ChevalierJoseph commited on
Commit
7075e4c
·
verified ·
1 Parent(s): 45d360c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -6
app.py CHANGED
@@ -12,6 +12,7 @@ import glob
12
  from fontmake.font_project import FontProject
13
  from defcon import Font, Glyph
14
  from fontTools.pens.svgPathPen import SVGPathPen
 
15
 
16
  # ------------------------
17
  # MODELE
@@ -85,14 +86,35 @@ def build_ufo_from_glyphs(glyphs):
85
  glyph.unicode = ord(letter)
86
  pen = glyph.getPen()
87
  try:
88
- # Dessiner un rectangle pour chaque glyphe
89
- pen.moveTo((50, 0))
90
- pen.lineTo((500, 0))
91
- pen.lineTo((500, 500))
92
- pen.lineTo((50, 500))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  pen.closePath()
94
  glyph.width = 600
95
- print(f"Glyph {letter} created with rectangle contour.")
96
  except Exception as e:
97
  print(f"Error injecting SVG for {letter}: {e}")
98
  font.insertGlyph(glyph)
 
12
  from fontmake.font_project import FontProject
13
  from defcon import Font, Glyph
14
  from fontTools.pens.svgPathPen import SVGPathPen
15
+ from svgpathtools import parse_path, Path, Line, CubicBezier, QuadraticBezier, Arc
16
 
17
  # ------------------------
18
  # MODELE
 
86
  glyph.unicode = ord(letter)
87
  pen = glyph.getPen()
88
  try:
89
+ path = parse_path(path_data)
90
+ for segment in path:
91
+ if segment.length() == 0:
92
+ continue
93
+ # Commencer un nouveau contour
94
+ start_point = (segment.start.real, segment.start.imag)
95
+ pen.moveTo(start_point)
96
+ # Dessiner la courbe ou la ligne selon le type de segment
97
+ if isinstance(segment, Line):
98
+ end_point = (segment.end.real, segment.end.imag)
99
+ pen.lineTo(end_point)
100
+ elif isinstance(segment, CubicBezier):
101
+ control1 = (segment.control1.real, segment.control1.imag)
102
+ control2 = (segment.control2.real, segment.control2.imag)
103
+ end_point = (segment.end.real, segment.end.imag)
104
+ pen.curveTo(control1, control2, end_point)
105
+ elif isinstance(segment, QuadraticBezier):
106
+ # Convertir la courbe quadratique en courbe cubique
107
+ # Pour simplifier, nous allons approximer avec une ligne droite
108
+ end_point = (segment.end.real, segment.end.imag)
109
+ pen.lineTo(end_point)
110
+ elif isinstance(segment, Arc):
111
+ # Les arcs sont plus complexes à convertir
112
+ # Pour simplifier, nous allons approximer avec une ligne droite
113
+ end_point = (segment.end.real, segment.end.imag)
114
+ pen.lineTo(end_point)
115
  pen.closePath()
116
  glyph.width = 600
117
+ print(f"Glyph {letter} created with SVG path.")
118
  except Exception as e:
119
  print(f"Error injecting SVG for {letter}: {e}")
120
  font.insertGlyph(glyph)