Last active
February 1, 2023 23:51
-
-
Save okay-type/79814b7c31883eb32257986ff9498932 to your computer and use it in GitHub Desktop.
copy anchors from glyph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vanilla import * | |
from mojo.subscriber import Subscriber, registerRoboFontSubscriber | |
''' | |
to do: | |
when only copying x values, skew to italic angle | |
''' | |
class copyanchors(Subscriber): | |
def build(self): | |
self.w = Window((300,60), title='Copy Anchors From') | |
self.w.text = EditText((8,4,-8,25), '') | |
self.w.button_XY = Button((8,30,94,25), 'Copy X & Y', callback=self.copyanchors_XY) | |
self.w.button_X = Button((106,30,94,25), 'Copy X', callback=self.copyanchors_X) | |
self.w.button_Y = Button((206,30,94,25), 'Copy Y', callback=self.copyanchors_Y) | |
self.w.open() | |
if CurrentGlyph() is not None: | |
self.w.text.set(self.striplastdot(CurrentGlyph().name)) | |
def glyphEditorDidSetGlyph(self, info): | |
## shouldn't have to do this in next beta | |
glyph = info['glyph'] | |
if glyph is None: | |
return | |
self.w.text.set(self.striplastdot(glyph.name)) | |
def striplastdot(self, name): | |
# some lazy replacements to get base glyph names | |
# you should probably adjust this for your workflow | |
if 'ogonek' in name: | |
name = name.replace('ogonek','') | |
elif 'horn' in name: | |
name = name.replace('horn','') | |
elif 'dotless' in name: | |
name = name.replace('dotless','') | |
elif 'slash' in name: | |
name = name.replace('slash','') | |
elif 'Eth' in name: | |
name = name.replace('Eth','D') | |
else: | |
name = name.rsplit('.', 1)[0] | |
return name | |
def copyanchors_XY(self, sender): | |
self.copyanchors(sender, True, True) | |
def copyanchors_X(self, sender): | |
self.copyanchors(sender, True, False) | |
def copyanchors_Y(self, sender): | |
self.copyanchors(sender, False, True) | |
def copyanchors(self, sender, x, y): | |
self.f = CurrentFont() | |
g = self.w.text.get() | |
if g in self.f.glyphOrder: | |
glyph = self.f[g] | |
cg = CurrentGlyph() | |
with cg.undo('Copy Anchor Positions from '+g): | |
if cg is not None and cg is not glyph: | |
print('copying anchor positions from', g) | |
for g_anchor in glyph.anchors: | |
for c_anchor in cg.anchors: | |
if g_anchor.name == c_anchor.name: | |
new_x = c_anchor.x | |
new_y = c_anchor.y | |
if x == True: | |
new_x = g_anchor.x | |
if y == True: | |
new_y = g_anchor.y | |
c_anchor.x = new_x | |
c_anchor.y = new_y | |
print('\t', c_anchor.name, new_x, new_y) | |
if __name__ == '__main__': | |
registerRoboFontSubscriber(copyanchors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment