Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ from defcon import Font, Glyph, Point
|
|
| 14 |
from fontTools.pens.svgPathPen import SVGPathPen
|
| 15 |
from svgpathtools import parse_path, Path, Line, CubicBezier, QuadraticBezier, Arc
|
| 16 |
from svgpathtools.path import Path as SvgPath
|
|
|
|
| 17 |
|
| 18 |
# ------------------------
|
| 19 |
# MODELE
|
|
@@ -110,12 +111,16 @@ def build_ufo_from_glyphs(glyphs):
|
|
| 110 |
continue
|
| 111 |
normalized_path.append(segment)
|
| 112 |
if normalized_path:
|
|
|
|
| 113 |
bounds = None
|
| 114 |
for segment in normalized_path:
|
|
|
|
|
|
|
|
|
|
| 115 |
if bounds is None:
|
| 116 |
-
bounds =
|
| 117 |
else:
|
| 118 |
-
bounds |=
|
| 119 |
if bounds and (bounds.width > 0) and (bounds.height > 0):
|
| 120 |
glyph_width = 800
|
| 121 |
glyph_height = 1000
|
|
@@ -141,9 +146,17 @@ def build_ufo_from_glyphs(glyphs):
|
|
| 141 |
control2 = transform_point(segment.control2)
|
| 142 |
end_point = transform_point(segment.end)
|
| 143 |
pen.curveTo(control1, control2, end_point)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
if normalized_path and normalized_path[-1].end == normalized_path[0].start:
|
| 145 |
pen.closePath()
|
| 146 |
-
glyph.width = glyph_width
|
| 147 |
print(f"Glyph {letter} created with SVG path.")
|
| 148 |
except Exception as e:
|
| 149 |
print(f"Error injecting SVG for {letter}: {e}")
|
|
|
|
| 14 |
from fontTools.pens.svgPathPen import SVGPathPen
|
| 15 |
from svgpathtools import parse_path, Path, Line, CubicBezier, QuadraticBezier, Arc
|
| 16 |
from svgpathtools.path import Path as SvgPath
|
| 17 |
+
from svgpathtools.path import BoundingBox # Importation de BoundingBox pour gérer les limites
|
| 18 |
|
| 19 |
# ------------------------
|
| 20 |
# MODELE
|
|
|
|
| 111 |
continue
|
| 112 |
normalized_path.append(segment)
|
| 113 |
if normalized_path:
|
| 114 |
+
# Calculer les limites du chemin
|
| 115 |
bounds = None
|
| 116 |
for segment in normalized_path:
|
| 117 |
+
segment_bounds = BoundingBox([segment.start, segment.end])
|
| 118 |
+
if isinstance(segment, (CubicBezier, QuadraticBezier)):
|
| 119 |
+
segment_bounds |= BoundingBox([segment.control1, segment.control2])
|
| 120 |
if bounds is None:
|
| 121 |
+
bounds = segment_bounds
|
| 122 |
else:
|
| 123 |
+
bounds |= segment_bounds
|
| 124 |
if bounds and (bounds.width > 0) and (bounds.height > 0):
|
| 125 |
glyph_width = 800
|
| 126 |
glyph_height = 1000
|
|
|
|
| 146 |
control2 = transform_point(segment.control2)
|
| 147 |
end_point = transform_point(segment.end)
|
| 148 |
pen.curveTo(control1, control2, end_point)
|
| 149 |
+
elif isinstance(segment, QuadraticBezier):
|
| 150 |
+
control = transform_point(segment.control)
|
| 151 |
+
end_point = transform_point(segment.end)
|
| 152 |
+
# Approximer la courbe quadratique avec une courbe cubique
|
| 153 |
+
start_point = transform_point(segment.start)
|
| 154 |
+
control1 = start_point + (control - start_point) * 2/3
|
| 155 |
+
control2 = end_point + (control - end_point) * 2/3
|
| 156 |
+
pen.curveTo(control1, control2, end_point)
|
| 157 |
if normalized_path and normalized_path[-1].end == normalized_path[0].start:
|
| 158 |
pen.closePath()
|
| 159 |
+
glyph.width = glyph_width if 'glyph_width' in locals() else 1000
|
| 160 |
print(f"Glyph {letter} created with SVG path.")
|
| 161 |
except Exception as e:
|
| 162 |
print(f"Error injecting SVG for {letter}: {e}")
|