Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
justanotherfoundry committed Feb 10, 2014
1 parent 04727b4 commit 4fe8060
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Delete All Hints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#MenuTitle: Delete All Hints
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

'''
Removes all hints front he selected glyphs.
'''

from GlyphsApp import *

doc = Glyphs.currentDocument
font = doc.font
layers = doc.selectedLayers()

for layer in layers:
layer.hints = []
57 changes: 57 additions & 0 deletions Expand Kerning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#MenuTitle: Expand Kerning
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

'''
Expand Kerning like we know it from FontLab.
'''
from GlyphsApp import *

doc = Glyphs.currentDocument
font = doc.font
master_id = font.selectedFontMaster.id

right_groups = set( [ '@MMK_R_' + glyph.leftKerningGroup for glyph in font.glyphs if glyph.leftKerningGroup ] )
left_groups = set( [ '@MMK_L_' + glyph.rightKerningGroup for glyph in font.glyphs if glyph.rightKerningGroup ] )
glyph_names = set( [ glyph.name for glyph in font.glyphs ] )
right_sides = right_groups.union( glyph_names )

# expand
for left_glyph in font.glyphs:
print left_glyph
if left_glyph.rightKerningGroup:
left_name = '@MMK_L_' + left_glyph.rightKerningGroup
else:
left_name = left_glyph.name
for right_glyph in font.glyphs:
if right_glyph.leftKerningGroup:
right_name = '@MMK_R_' + right_glyph.leftKerningGroup
else:
right_name = right_glyph.name
value = font.kerningForPair( master_id, left_name, right_name )
if value < 77000:
existing_value = font.kerningForPair( master_id, left_glyph.name, right_glyph.name )
if existing_value < 77000:
continue
exception_value = font.kerningForPair( master_id, left_glyph.name, right_name )
if exception_value < 77000:
value = exception_value
exception_value = font.kerningForPair( master_id, left_name, right_glyph.name )
if exception_value < 77000:
value = exception_value
font.setKerningForPair( master_id, left_glyph.name, right_glyph.name, value )

# remove group kerning
for left_side in left_groups:
for right_side in right_sides:
font.removeKerningForPair( master_id, left_side, right_side )
for left_side in glyph_names:
for right_side in right_groups:
font.removeKerningForPair( master_id, left_side, right_side )

# remove kerning groups
# (TODO)
88 changes: 88 additions & 0 deletions Insert Glyph to Background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#MenuTitle: Insert Glyph to Background
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

"""
1. Enter a glyph name.
2. Press the left align or right align button.
3. This script will clear the mask, then insert the specified glyph into the mask.
- With right align selected, the contours will be pasted as if the advance widths were aligned.
- The keyboard shortcuts for left and right aligned are Enter and Esc.
- It is sufficient to enter the beginning of the glyph name, e.g. "deg" for "degree".
"""

from GlyphsApp import *
from vanilla import *

LEFT = '<'
RIGHT = '>'

glyphs = Glyphs.font.glyphs

class GlyphnameDialog( object):

def __init__( self, selected_glyphs ):
self.selected_glyphs = selected_glyphs
x = 10
y = 10
height = 20
button_width = 30
glyphname_width = 180
gap = 6
self.w = Window( ( x + button_width + gap + glyphname_width + gap + button_width + x, y + height + y ), "insert glyph" )
self.w.center()
self.w.glyphname = EditText( ( x, y, glyphname_width, height ), '')
x += glyphname_width + gap
self.w.alignleft = Button( ( x, y, button_width, height ), LEFT, callback = self.buttonCallback )
x += button_width + gap
self.w.alignright = Button( ( x, y, button_width, height ), RIGHT, callback = self.buttonCallback )
self.w.setDefaultButton( self.w.alignleft )
self.w.alignright.bind( "\x1b", [] )
self.w.open()

def buttonCallback( self, sender ):
title = sender.getTitle()
glyphname = self.w.glyphname.get()
if not glyphname:
self.w.close()
return
if len( glyphname ) == 1:
pass
# todo: get Unicode value and choose glyph accordingly
other_glyph = glyphs[ glyphname ]
if not other_glyph:
for glyph in glyphs:
if glyph.name.startswith( glyphname ):
other_glyph = glyph
print 'Using', glyph.name
break
else:
print 'No matching glyph found.'
self.w.close()
return
for glyph in self.selected_glyphs:
glyph.beginUndo()
for layer in glyph.layers:
# clear mask
for i in range( len ( layer.background.paths ) ):
del layer.background.paths[0]
# inert paths
for other_layer in other_glyph.layers:
if other_layer.associatedMasterId == layer.associatedMasterId:
for path in other_layer.copyDecomposedLayer().paths:
if title == RIGHT:
shift = layer.width - other_layer.width # might not be used
for node in path.nodes:
node.x = node.x + shift
layer.background.paths.append( path )
break
glyph.endUndo()
self.w.close()

selected_glyphs = set( [ layer.parent for layer in Glyphs.font.selectedLayers ] )
GlyphnameDialog( selected_glyphs )
32 changes: 32 additions & 0 deletions Mask to Master.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#MenuTitle: mask to master
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

'''
Simulates the good ol' Mask to Master function we know from FontLab
(i.e. replaces the current outline with the background).
You can give it the familiar Cmd+J shortcut via App Shortcuts
in the Mac OS System Preferences.
'''

from GlyphsApp import *

font = Glyphs.font
layers = font.selectedLayers
glyph = layers[0].parent

glyph.beginUndo()

for layer in layers:
# remove outline
for i in range( len ( layer.paths ) ):
del layer.paths[0]
# paste in background
for path in layer.copyDecomposedLayer().background.paths:
layer.paths.append( path )

glyph.endUndo()
39 changes: 39 additions & 0 deletions Paste Background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#MenuTitle: Paste Background
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

'''
Pastes the background contours into the current layer.
Former FontLab users can give it the familiar Cmd+L shortcut via App Shortcuts
in the Mac OS System Preferences.
'''

from GlyphsApp import *

doc = Glyphs.currentDocument
font = doc.font
layers = doc.selectedLayers()
glyph = layers[0].parent

glyph.beginUndo()

for layer in layers:
# deselect all
for path in layer.paths:
for node in path.nodes:
layer.removeObjectFromSelection_( node )
# layer.removeObjectsFromSelection_( path.pyobjc_instanceMethods.nodes() )

# paste in background
for path in layer.copyDecomposedLayer().background.paths:
# copy across path
layer.paths.append( path )
# select path
for node in layer.paths[-1].nodes:
layer.addSelection_( node )

glyph.endUndo()
21 changes: 21 additions & 0 deletions Remove Backup Layers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#MenuTitle: Remove Backup Layers
# encoding: utf-8

# by Tim Ahrens
# http://justanotherfoundry.com
# https://github.com/justanotherfoundry/glyphsapp-scripts

'''
Removes all backup layers (i.e. those created using the "Copy" button) from the font.
'''

from GlyphsApp import *

font = Glyphs.currentDocument.font

for glyph in font.glyphs:
associated_layers = [ layer.layerId for layer in glyph.layers if layer.layerId != layer.associatedMasterId and not '[' in layer.name and not ']' in layer.name ]
for layerId in associated_layers:
print 'deleting extra layer from', glyph.name
del glyph.layers[layerId]
Loading

0 comments on commit 4fe8060

Please sign in to comment.