-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19 Extremum Point Check.py
56 lines (38 loc) · 1.34 KB
/
19 Extremum Point Check.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
# MenuTitle: 19 Extremum Point Check
from mojo.roboFont import CurrentFont, CurrentGlyph
from fontTools.pens.basePen import BasePen
# helper functions from fontTools.misc.arrayTools
def normRect(rect):
"""Normalize the rectangle so that the following holds:
xMin <= xMax and yMin <= yMax
"""
(xMin, yMin, xMax, yMax) = rect
return min(xMin, xMax), min(yMin, yMax), max(xMin, xMax), max(yMin, yMax)
def pointInRect(p, rect):
"""Return True when point (x, y) is inside rect."""
(x, y) = p
xMin, yMin, xMax, yMax = rect
return (xMin <= x <= xMax) and (yMin <= y <= yMax)
class MyPen(BasePen):
def _moveTo(self, pt):
pass
def _lineTo(self, pt):
pass
def _curveToOne(self, bcp1, bcp2, pt):
curr = self._getCurrentPoint()
rect = normRect((curr[0], curr[1], pt[0], pt[1]))
if not pointInRect(bcp1, rect):
print("Control point is out of bounding box:", bcp1)
print(" ", rect)
if not pointInRect(bcp2, rect):
print("Control point is out of bounding box:", bcp2)
print(" ", rect)
def _closePath(self):
pass
def _endPath(self):
pass
def addComponent(self, baseGlyphName, transformation):
pass
if __name__ == "__main__":
p = MyPen(CurrentFont())
CurrentGlyph().draw(p)