-
Notifications
You must be signed in to change notification settings - Fork 4
/
getFromNextFont.py
146 lines (104 loc) · 4.33 KB
/
getFromNextFont.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#MenuTitle: Get from next font
# -*- coding: utf-8 -*-
__doc__="""
(UI) Import anchors from antother font.
"""
from GlyphsApp import *
from vanilla import *
from Foundation import NSPoint
import copy
font = Glyphs.font
class AnchorTeleporter(object):
def __init__(self):
infoText = ""
self.w = FloatingWindow((300, 320), "Get from next font")
self.w.textBox = TextBox((10, 10, -10, 17), "Get from")
self.w.popUpFont = PopUpButton((10, 35, -10, 20),
self.createFontList(),
callback=self.popUpFontCallback)
self.w.textBox2 = TextBox((10, 65, -10, 17), "Layer:")
self.w.popUpLayers = PopUpButton((10, 85, -10, 20),[""])
self.w.checkBoxPaths = CheckBox((10, 120, -10, 20), "import paths", value=False)
self.w.checkBoxComponents = CheckBox((10, 145, -10, 20), "import components", value=False)
self.w.checkBoxSidebearings = CheckBox((10, 170, -10, 20), "import Sidebearings", value=False)
self.w.checkBoxAnchors = CheckBox((10, 195, -10, 20), "import Anchors", value=False)
self.w.importButton = Button((10, -70, -10, 20), "Import", callback=self.cloneCallback)
self.w.line2 = HorizontalLine((10, -40, -10, 1))
self.w.box = Box((10, -30, -10, 24))
self.w.box.infoBox = TextBox((0, 0, -10, -0), infoText, alignment='center', sizeStyle='small')
self.w.popUpLayers.enable( False )
self.w.importButton.enable( False )
self.w.open()
def popUpFontCallback(self, sender):
thisLayer = Glyphs.font.selectedLayers[0]
selectedFont = Glyphs.fonts[sender.get()]
glyphName = thisLayer.parent.name
layerList = []
for layer in selectedFont.glyphs[glyphName].layers:
layerList.append(layer.name)
self.w.popUpLayers.setItems( layerList )
self.w.popUpLayers.enable( True )
self.w.importButton.enable( True )
def createFontList(self):
fonts = Glyphs.fonts
fontList = []
for thisFont in fonts:
fontList.append(thisFont.filepath.split("/")[-1])
return fontList
def cloneCallback(self, sender):
selectedLayers = Glyphs.font.selectedLayers
varImportPaths = self.w.checkBoxPaths.get()
varImportComponents = self.w.checkBoxComponents.get()
varImportSidebearings = self.w.checkBoxSidebearings.get()
varImportAnchors = self.w.checkBoxAnchors.get()
self.w.box.infoBox.set("Anchors Copied!")
def importAnchors ( thisLayer, anchorName, x, y):
thisLayer.anchors[anchorName] = GSAnchor()
thisLayer.anchors[anchorName].position = NSPoint(x,y)
# thisLayer.anchors.append( newAnchor )
def importPaths ( thisLayer, nextPath):
thisLayer.paths.append( nextPath )
def importComponents ( thisLayer, nextComponent):
thisLayer.components.append( nextComponent )
def importSidebearings ( thisLayer, nextPath):
thisLayer.paths.append( nextPath )
for thisLayer in selectedLayers:
glyph = thisLayer.parent
layerIndex = self.w.popUpLayers.get()
popchoose = self.w.popUpLayers.getItems()
nextFontIndex = self.w.popUpFont.get()
try:
for i in Glyphs.fonts[nextFontIndex].glyphs[glyph.name].layers:
if i.name == list(popchoose) [layerIndex]:
nextFontLayer = i
if varImportAnchors == True:
nextFontAnchors = nextFontLayer.anchors
for nextAnchor in nextFontAnchors:
thisAnchor = nextAnchor.copy()
thisLayer.anchors[ str(thisAnchor.name) ] = thisAnchor
#anchorName = nextAnchor.name
# x = nextAnchor.position.x
# y = nextAnchor.position.y
# importAnchors (thisLayer, anchorName, x, y)
if varImportPaths == True:
nextFontPaths = nextFontLayer.paths
for nextPath in nextFontPaths:
importPaths (thisLayer, nextPath)
if varImportComponents == True:
nextFontComponents = nextFontLayer.components
for nextComponent in nextFontComponents:
importComponents (thisLayer, nextComponent)
if varImportSidebearings == True:
if nextFontLayer.leftMetricsKey != None:
thisLayer.leftMetricsKey = nextFontLayer.leftMetricsKey
else:
thisLayer.LSB = nextFontLayer.LSB
if nextFontLayer.rightMetricsKey != None:
thisLayer.rightMetricsKey = nextFontLayer.rightMetricsKey
else:
thisLayer.RSB = nextFontLayer.RSB
self.w.box.infoBox.set("Data imported!")
break
except Exception, e:
print e
AnchorTeleporter()