diff options
| author | Teddy Wing | 2015-11-20 05:32:52 -0500 |
|---|---|---|
| committer | Teddy Wing | 2015-11-20 05:32:52 -0500 |
| commit | 385ba95ce64661a773af2a7f28191a768149c572 (patch) | |
| tree | 573cd653ba7f4ded8779f69bb91152e0afa90dd6 | |
| parent | 084d0770bb210e76946e885e6485e4045b5617a7 (diff) | |
| download | RoboFont-Equalize-Sidebearings-Key-385ba95ce64661a773af2a7f28191a768149c572.tar.bz2 | |
equalize_sidebearings.py: Copy RoboFont implementation
Copy `equalize_sidebearings` method and `getDefault` function from
RoboFont after uncompiling the `lib/UI/spaceCenter/*.pyc`,
`lib/doodleMenus.pyc`, and `lib/tools/defaults.pyc` files.
This gives us the exact same functionality that happens when choosing
"Equalize sidebearings" from the contextual menu in the Space Center.
Including the code directly instead of referencing it because the
`SpaceCenterMenuForGlyph` class opens a contextual menu on init, which
we really don't want, and the `equalizeSideBearings_` method that it
defined is an instance method, so I would need an instance of the class
but don't want to trigger the contextual menu. So I figured I'd just
copy the code directly to speed things up.
Unfortunately undo functionality doesn't work with the method I copied,
and I can't seem to figure out how to get it sorted out.
| -rw-r--r-- | equalize_sidebearings.py | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/equalize_sidebearings.py b/equalize_sidebearings.py index 92f518b..7f7f5cc 100644 --- a/equalize_sidebearings.py +++ b/equalize_sidebearings.py @@ -1,4 +1,15 @@ +from AppKit import NSUserDefaults + from mojo.events import addObserver +# from lib.doodleMenus import SpaceCenterMenuForGlyph +# from tools.defaults import getDefault + +def getDefault(key, defaultValue = None, defaultClass = None): + defaultsFromFile = NSUserDefaults.standardUserDefaults() + value = defaultsFromFile.get(key, defaultValue) + if defaultClass is not None: + return defaultClass(value) + return value class EqualizeSidebearings(object): def __init__(self): @@ -6,12 +17,30 @@ class EqualizeSidebearings(object): def center(self, info): if info['event'].characters() == 'a': - g = info['glyph'] - - g.prepareUndo('Equalize Sidebearings') - - g.center() + # g = info['glyph'] + self.equalize_sidebearings(info['glyph']) + # SpaceCenterMenuForGlyph(info['event'], self, g) + # + # g.prepareUndo('Equalize Sidebearings') + # + # g.center() + # + # g.performUndo() - g.performUndo() + def equalize_sidebearings(self, glyph): + useItalicAngleForDisplay = getDefault('glyphViewShouldUseItalicAngleForDisplay') + leftMarginAttribute = 'leftMargin' + rightMarginAttribute = 'rightMargin' + if useItalicAngleForDisplay: + leftMarginAttribute = 'angledLeftMargin' + rightMarginAttribute = 'angledRightMargin' + left = getattr(glyph, leftMarginAttribute) + right = getattr(glyph, rightMarginAttribute) + margin = int(round((left + right) / 2.0)) + glyph.prepareUndo('Equalize sidebearings') + setattr(glyph, leftMarginAttribute, margin) + setattr(glyph, rightMarginAttribute, margin) + glyph.selection.resetSelectionPath() + glyph.performUndo() EqualizeSidebearings()
\ No newline at end of file |
