| [1] | 1 | """A couple of point pens which return the glyph as a list of basic values.""" |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | from robofab.pens.pointPen import AbstractPointPen |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | class DigestPointPen(AbstractPointPen): |
|---|
| 8 | |
|---|
| 9 | """Calculate a digest of all points |
|---|
| 10 | AND coordinates |
|---|
| 11 | AND components |
|---|
| 12 | in a glyph. |
|---|
| 13 | """ |
|---|
| 14 | |
|---|
| 15 | def __init__(self, ignoreSmoothAndName=False): |
|---|
| 16 | self._data = [] |
|---|
| 17 | self.ignoreSmoothAndName = ignoreSmoothAndName |
|---|
| 18 | |
|---|
| 19 | def beginPath(self): |
|---|
| 20 | self._data.append('beginPath') |
|---|
| 21 | |
|---|
| 22 | def endPath(self): |
|---|
| 23 | self._data.append('endPath') |
|---|
| 24 | |
|---|
| 25 | def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs): |
|---|
| 26 | if self.ignoreSmoothAndName: |
|---|
| 27 | self._data.append((pt, segmentType)) |
|---|
| 28 | else: |
|---|
| 29 | self._data.append((pt, segmentType, smooth, name)) |
|---|
| 30 | |
|---|
| 31 | def addComponent(self, baseGlyphName, transformation): |
|---|
| [26] | 32 | t = [] |
|---|
| 33 | for v in transformation: |
|---|
| 34 | if int(v) == v: |
|---|
| 35 | t.append(int(v)) |
|---|
| 36 | else: |
|---|
| 37 | t.append(v) |
|---|
| 38 | self._data.append((baseGlyphName, tuple(t))) |
|---|
| [1] | 39 | |
|---|
| 40 | def getDigest(self): |
|---|
| 41 | return tuple(self._data) |
|---|
| 42 | |
|---|
| 43 | def getDigestPointsOnly(self): |
|---|
| 44 | """Return a tuple with all coordinates of all points, |
|---|
| 45 | but without smooth info or drawing instructions. |
|---|
| 46 | For instance if you want to compare 2 glyphs in shape, |
|---|
| 47 | but not interpolatability. |
|---|
| 48 | """ |
|---|
| 49 | points = [] |
|---|
| 50 | for item in self._data: |
|---|
| 51 | points.append(item[0]) |
|---|
| 52 | points.sort() |
|---|
| 53 | return tuple(points) |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | class DigestPointStructurePen(DigestPointPen): |
|---|
| 57 | |
|---|
| 58 | """Calculate a digest of the structure of the glyph |
|---|
| 59 | NOT coordinates |
|---|
| 60 | NOT values. |
|---|
| 61 | """ |
|---|
| 62 | |
|---|
| 63 | def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs): |
|---|
| 64 | self._data.append(segmentType) |
|---|
| 65 | |
|---|
| 66 | def addComponent(self, baseGlyphName, transformation): |
|---|
| 67 | self._data.append(baseGlyphName) |
|---|
| 68 | |
|---|