-
Notifications
You must be signed in to change notification settings - Fork 4
/
smooth2sharp.py
67 lines (49 loc) · 2.76 KB
/
smooth2sharp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#MenuTitle: Smooth2Sharp
# -*- coding: utf-8 -*-
__doc__="""
The script searches smooth nodes with disaligned handles and changes them to sharp.
"""
import math
Font = Glyphs.font
selectedLayers = Font.selectedLayers
for layer in selectedLayers:
paths = layer.paths
for thisPath in paths:
numOfNodes = len(thisPath.nodes)
for thisNodeIndex in range(numOfNodes):
thisNode = thisPath.nodes[ thisNodeIndex ]
prevNode = thisPath.nodes[ (thisNodeIndex - 1) % numOfNodes ]
nextNode = thisPath.nodes[ (thisNodeIndex + 1) % numOfNodes ]
posx = thisNode.position.x
posy = thisNode.position.y
prevposx = prevNode.position.x
prevposy = prevNode.position.y
nextposx = nextNode.position.x
nextposy = nextNode.position.y
#1er. Filtro. Fuera OFFCURVES Y SHARPS
if thisNode.type == GSCURVE and thisNode.connection == GSSMOOTH:
#2do. Filtro. Fuera ortogonales
if not (( posx - prevposx ) + ( posx - nextposx ) == 0.0 or ( posy - prevposy ) + ( posy - nextposy ) == 0.0):
#triangulo 1
ladoX1 = prevposx - posx
ladoY1 = prevposy - posy
#triangulo 2
ladoX2 = nextposx - posx
ladoY2 = nextposy - posy
#3er. Filtro. Fuera nodos con 1 tirador sobre Y o X
if ladoY1 == 0.0 or ladoY2 == 0.0 or ladoX1 == 0.0 or ladoX2 == 0.0:
thisNode.connection = GSSHARP
else:
#Tangente Angulo Triangulo1
angle1 = ladoY1 / ladoX1
#Tangente Angulo Triangulo2
angle2 = ladoY2 / ladoX2
#Redondeo Angulo1
ceil1=(math.ceil(angle1*100)/100)
#Redondeo Angulo2
ceil2=(math.ceil(angle2*100)/100)
#Resta de los redondeos
resta = ceil1 - ceil2
#Limite permitido
if resta > 0.1 or resta < -0.1:
thisNode.connection = GSSHARP