Cnass commited on
Commit
409d2f5
·
verified ·
1 Parent(s): 4fdae51

Update app/synthetic_accents.py

Browse files
Files changed (1) hide show
  1. app/synthetic_accents.py +47 -13
app/synthetic_accents.py CHANGED
@@ -23,22 +23,56 @@ def _circle(cx: float, cy: float, rx: float, ry: float, n: int = 16) -> Contour:
23
  return pts
24
 
25
 
26
- def _cedilla_hook(width: float, height: float) -> Contour:
27
- # Basit bir virgül/kanca şekli; sol üstten başlar sağa iner, sola kıvrılır.
28
- steps = 14
29
- pts: list[Point] = []
30
- # gövde (kalın kısım) - küçük bir dörtgen üstte
31
- stem_w = width * 0.55
32
- pts += [(0, height * 0.55), (stem_w, height * 0.55), (stem_w, height * 0.85), (0, height * 0.85)]
33
- # kanca kuyruğu - üst sağdan aşağı sola bir yay
34
- cx, cy = width * 0.15, height * 0.15
35
- r = width * 0.42
36
- for i in range(steps + 1):
37
- a = math.radians(10 + i * (230 / steps))
38
- pts.append((cx + r * math.cos(a), cy + r * math.sin(a) * 0.7 - height * 0.1))
39
  return pts
40
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  def _breve_arc(width: float, height: float) -> Contour:
43
  # Kalın kenarlı bir "u" (ters gülümseme) şekli - iki içiçe yay.
44
  steps = 20
 
23
  return pts
24
 
25
 
26
+ def _chaikin(points: list[Point], iterations: int = 3) -> list[Point]:
27
+ """Köşeli bir çizgiyi (uç noktalar sabit kalacak şekilde) yumuşak bir
28
+ eğriye yaklaştırır - basit ve kendi kendini kesme riski olmayan bir
29
+ düzleştirme yöntemi."""
30
+ pts = points
31
+ for _ in range(iterations):
32
+ smoothed = [pts[0]]
33
+ for (x0, y0), (x1, y1) in zip(pts, pts[1:]):
34
+ smoothed.append((0.75 * x0 + 0.25 * x1, 0.75 * y0 + 0.25 * y1))
35
+ smoothed.append((0.25 * x0 + 0.75 * x1, 0.25 * y0 + 0.75 * y1))
36
+ smoothed.append(pts[-1])
37
+ pts = smoothed
 
38
  return pts
39
 
40
 
41
+ def _stroke_polygon(centerline: list[Point], width_start: float, width_end: float) -> Contour:
42
+ """Bir merkez çizgiyi, uca doğru inceltilmiş (tapered) tek bir kapalı
43
+ poligona (dış kenar + ters yönde iç kenar) dönüştürür."""
44
+ n = len(centerline)
45
+ outer: list[Point] = []
46
+ inner: list[Point] = []
47
+ for i, (x, y) in enumerate(centerline):
48
+ if i == 0:
49
+ dx, dy = centerline[1][0] - x, centerline[1][1] - y
50
+ elif i == n - 1:
51
+ dx, dy = x - centerline[i - 1][0], y - centerline[i - 1][1]
52
+ else:
53
+ dx = centerline[i + 1][0] - centerline[i - 1][0]
54
+ dy = centerline[i + 1][1] - centerline[i - 1][1]
55
+ length = math.hypot(dx, dy) or 1.0
56
+ nx, ny = -dy / length, dx / length
57
+ half = (width_start * (1 - i / (n - 1)) + width_end * (i / (n - 1))) / 2
58
+ outer.append((x + nx * half, y + ny * half))
59
+ inner.append((x - nx * half, y - ny * half))
60
+ return outer + list(reversed(inner))
61
+
62
+
63
+ def _cedilla_hook(width: float, height: float) -> Contour:
64
+ # Harfin altına tutunan, aşağı ve sola kıvrılan, ucu incelen tek parça bir kanca.
65
+ key_points = [
66
+ (width * 0.58, height * 1.00), # üstte harfe tutunma noktası
67
+ (width * 0.68, height * 0.70), # sağa doğru omuz
68
+ (width * 0.50, height * 0.38), # merkeze doğru iniş
69
+ (width * 0.24, height * 0.14), # sola kıvrılma
70
+ (width * 0.16, height * 0.00), # incelen uç
71
+ ]
72
+ centerline = _chaikin(key_points, iterations=3)
73
+ return _stroke_polygon(centerline, width_start=height * 0.30, width_end=height * 0.045)
74
+
75
+
76
  def _breve_arc(width: float, height: float) -> Contour:
77
  # Kalın kenarlı bir "u" (ters gülümseme) şekli - iki içiçe yay.
78
  steps = 20