-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaintainGlyphZoom.py
62 lines (52 loc) · 2.14 KB
/
MaintainGlyphZoom.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
from mojo.events import addObserver
from AppKit import NSRect
# RF Version Check
from mojo.roboFont import version
RF3 = version[0] > "1"
class MaintainZoom(object):
"""
Startup Script:
Maintain the same zoom settings when switching between layers and glyphs
-- Andy Clymer, github.com/andyclymer
"""
def __init__(self):
# Save zoom posSize and offset for each open font
# font object as key, dict of "rectPos", "rectSize", "offset" and "glyph" as value
self.prevZoom = {}
addObserver(self, "getZoom", "viewWillChangeGlyph")
addObserver(self, "setZoom", "viewDidChangeGlyph")
def getZoom(self, info):
view = info["view"]
glyph = info["glyph"]
if not None in [view, glyph]:
font = glyph.getParent()
# Get the zoom rect and offset for the view
rect = view.visibleRect()
offset = view._offset
posSizeOffset = dict(
rectPos = (rect.origin.x, rect.origin.y),
rectSize = (rect.size.width, rect.size.height),
offset = (offset.x, offset.y),
glyph = glyph)
# Save the zoom info
self.prevZoom[font] = posSizeOffset
def setZoom(self, info):
view = info["view"]
glyph = info["glyph"]
if not None in [view, glyph]:
font = glyph.getParent()
# Set the zoom info, if this is a new glyph or layer
if font in self.prevZoom:
posSizeOffset = self.prevZoom[font]
if not posSizeOffset["glyph"]== glyph:
offset = view._offset
newRect = NSRect()
newRect.origin.x, newRect.origin.y = posSizeOffset["rectPos"]
newRect.size.width, newRect.size.height = posSizeOffset["rectSize"]
view.zoomViewToRect_(newRect)
view._offset.x, view._offset.y = posSizeOffset["offset"]
else:
# Zoom to 100% if nothing has been saved for this font
view.zoomViewToAbsoluteScale_(1)
if RF3:
MaintainZoom()