-
Notifications
You must be signed in to change notification settings - Fork 4
/
slantAnchors.py
61 lines (44 loc) · 2.01 KB
/
slantAnchors.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
#MenuTitle: Slant Anchors
# -*- coding: utf-8 -*-
__doc__="""
(UI) Moves anchors according to master italic angle. Useful when importing anchors from roman versions, or after changing the font angle.
"""
import GlyphsApp
from Foundation import NSPoint
from vanilla import *
import math
font = Glyphs.font
selectedLayers = font.selectedLayers
class slantAnchor(object):
def __init__(self):
self.w = Window((160, 100), "Slant anchors")
self.w.textBox = EditText((10, 10, 60, 20), "")
self.w.EditText = TextBox((80, 10, 90, 20), u"\u00B0")
self.w.checkBox = CheckBox((10, 40, -10, 20), "Use italic angle",
callback=self.checkBoxCallback, value=False)
self.w.button = Button((10, 70, -10, 20), "Move",
callback=self.buttonCallback)
self.w.open()
def checkBoxCallback(self, sender):
print "check box state change!", sender.get()
def buttonCallback(self, sender):
def angle(angle, height, yPos):
offset = math.tan(math.radians(angle)) * height / 2
shift = math.tan(math.radians(angle)) * yPos - offset
return shift
for thisLayer in selectedLayers:
#Set variables
masterID = thisLayer.associatedMasterId
print masterID
thisMasterXheight = font.masters[masterID].xHeight
thisMasterAngle = thisLayer.glyphMetrics()[5]
for thisAnchor in thisLayer.anchors:
posY = thisAnchor.position.y
if self.w.checkBox.get() == True:
newPosition = thisAnchor.position.x + angle(thisMasterAngle, thisMasterXheight, posY)
thisAnchor.position = NSPoint(newPosition, posY)
else:
customAngle = self.w.textBox.get()
newPosition = thisAnchor.position.x + angle(float(customAngle), thisMasterXheight, posY)
thisAnchor.position = NSPoint(newPosition, posY)
slantAnchor()