-
Notifications
You must be signed in to change notification settings - Fork 7
/
Interpolated Nudge.py
90 lines (74 loc) · 2.98 KB
/
Interpolated Nudge.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#MenuTitle: Interpolated nudge
# -*- coding: utf-8 -*-
__doc__="""
Nudge points while keeping tension
"""
import vanilla
windowHeight = 100
windowWidth = 120
class InterpolatedNudgeWindow( object ):
def __init__( self ):
try:
self.w = vanilla.FloatingWindow( (windowWidth, windowHeight), "Interpolated Nudge")
self.w.text_anchor = vanilla.TextBox( (15, 12, 130, 17), "Amount", sizeStyle='small')
self.w.amount = vanilla.EditText( (65, 9, 50, 20), "10", sizeStyle = 'small')
self.w.up = vanilla.Button(((windowWidth-20)/2, 20, 30, 40), "^", sizeStyle='small', callback=self.up)
self.w.down = vanilla.Button(((windowWidth-20)/2, (windowHeight-40), 30, 40), "v", sizeStyle='small', callback=self.down)
self.w.left = vanilla.Button((10, (windowHeight-20)/2, 30, 40), "<", sizeStyle='small', callback=self.left)
self.w.right = vanilla.Button((-30, (windowHeight-20)/2, 30, 40), ">", sizeStyle='small', callback=self.right)
self.w.open()
self.w.amount.selectAll()
except Exception, e:
print(e)
def nextOnCurve(self, n):
n = n.nextNode
while n.type == OFFCURVE: n = n.nextNode
return n
def prevOnCurve(self, n):
n = n.prevNode
while n.type == OFFCURVE: n = n.prevNode
return n
def adjust(self, handle, node, diffX, diffY, dx, dy):
adjX, adjY = 0, 0
if diffX != 0:
adjX = ((node.position.x-handle.position.x)/diffX) * dx
if diffY != 0:
adjY = ((node.position.y-handle.position.y)/diffY) * dy
if handle.type == OFFCURVE:
handle.position = (handle.position.x + adjX, handle.position.y + adjY)
def nudge(self, n, deltax, deltay):
nn = self.nextOnCurve(n)
pn = self.prevOnCurve(n)
diffX, diffY = nn.position.x - n.position.x, nn.position.y - n.position.y
if nn != n.nextNode:
self.adjust(nn.prevNode, nn, diffX, diffY, deltax, deltay)
self.adjust(nn.nextNode, nn, diffX, diffY, deltax, deltay)
diffX, diffY = pn.position.x - n.position.x, pn.position.y - n.position.y
if pn != n.prevNode:
self.adjust(pn.prevNode, pn, diffX, diffY, deltax, deltay)
self.adjust(pn.nextNode, pn, diffX, diffY, deltax, deltay)
n.position = (n.position.x + deltax, n.position.y + deltay)
if n.prevNode.type == OFFCURVE:
n.prevNode.position = (n.prevNode.position.x + deltax, n.prevNode.position.y + deltay)
if n.nextNode.type == OFFCURVE:
n.nextNode.position = (n.nextNode.position.x + deltax, n.nextNode.position.y + deltay)
def up(self,sender):
try:
val = float(self.w.amount.get())
self.doIt(0,val)
except Exception, e:
print(e)
def down(self,sender):
val = float(self.w.amount.get())
self.doIt(0,-val)
def left(self,sender):
val = float(self.w.amount.get())
self.doIt(-val,0)
def right(self,sender):
val = float(self.w.amount.get())
self.doIt(val,0)
def doIt(self, dx, dy):
for n in Glyphs.font.selectedLayers[0].selection:
self.nudge(n,dx,dy)
Glyphs.redraw()
InterpolatedNudgeWindow()