aboutsummaryrefslogtreecommitdiffstats
path: root/equalize_sidebearings.py
blob: 28ee956012edd0968a9bed20e3d6abd48759cf94 (plain)
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
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 CustomSpaceCenterMenuForGlyph(SpaceCenterMenuForGlyph):

    def __init__(self, glyph):
        self._glyph = glyph
        super(SpaceCenterMenuForGlyph, self).__init__()


class EqualizeSidebearings(object):
    def __init__(self):
        addObserver(self, 'center', 'spaceCenterKeyUp')

    def center(self, info):
        if info['event'].characters() == 'a':
            # g = info['glyph']
            # self.equalize_sidebearings(info['glyph'])
            # space_center_menu = SpaceCenterMenuForGlyph(info['event'], self, g, None)
            # space_center_menu.equalSideBearings_(self)
            space_center_menu = CustomSpaceCenterMenuForGlyph(
                info['glyph'].naked())
            space_center_menu.equalSideBearings_(self)

            # import vanilla
            # self.w = vanilla.Window((400, 400, 1000, 900))
            # self.w.text = vanilla.ObjectBrowser((0, 0, -0, -0), space_center_menu)
            # self.w.open()
            #
            # g.prepareUndo('Equalize Sidebearings')
            #
            # g.center()
            #
            # 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()