make drop_implied_oncurves work with multiple interpolatable glyphs
This commit is contained in:
parent
02a063685f
commit
a73abc6b87
@ -17,48 +17,57 @@ import math
|
|||||||
__all__ = ["TTGlyphPen", "TTGlyphPointPen"]
|
__all__ = ["TTGlyphPen", "TTGlyphPointPen"]
|
||||||
|
|
||||||
|
|
||||||
def drop_implied_oncurves(glyph):
|
def drop_implied_oncurves(*interpolatable_glyphs):
|
||||||
drop = set()
|
drop = None
|
||||||
start = 0
|
for glyph in interpolatable_glyphs:
|
||||||
flags = glyph.flags
|
may_drop = set()
|
||||||
coords = glyph.coordinates
|
start = 0
|
||||||
for last in glyph.endPtsOfContours:
|
flags = glyph.flags
|
||||||
for i in range(start, last + 1):
|
coords = glyph.coordinates
|
||||||
if not (flags[i] & flagOnCurve):
|
for last in glyph.endPtsOfContours:
|
||||||
continue
|
for i in range(start, last + 1):
|
||||||
prv = i - 1 if i > start else last
|
if not (flags[i] & flagOnCurve):
|
||||||
nxt = i + 1 if i < last else start
|
continue
|
||||||
if (flags[prv] & flagOnCurve) or flags[prv] != flags[nxt]:
|
prv = i - 1 if i > start else last
|
||||||
continue
|
nxt = i + 1 if i < last else start
|
||||||
p0 = coords[prv]
|
if (flags[prv] & flagOnCurve) or flags[prv] != flags[nxt]:
|
||||||
p1 = coords[i]
|
continue
|
||||||
p2 = coords[nxt]
|
p0 = coords[prv]
|
||||||
if not math.isclose(p1[0] - p0[0], p2[0] - p1[0]) or not math.isclose(
|
p1 = coords[i]
|
||||||
p1[1] - p0[1], p2[1] - p1[1]
|
p2 = coords[nxt]
|
||||||
):
|
if not math.isclose(p1[0] - p0[0], p2[0] - p1[0]) or not math.isclose(
|
||||||
continue
|
p1[1] - p0[1], p2[1] - p1[1]
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
may_drop.add(i)
|
||||||
|
# we only want to drop if ALL interpolatable glyphs have the same implied oncurves
|
||||||
|
if drop is None:
|
||||||
|
drop = may_drop
|
||||||
|
else:
|
||||||
|
drop.intersection_update(may_drop)
|
||||||
|
|
||||||
drop.add(i)
|
|
||||||
if drop:
|
if drop:
|
||||||
# Do the actual dropping
|
# Do the actual dropping
|
||||||
glyph.coordinates = GlyphCoordinates(
|
for glyph in interpolatable_glyphs:
|
||||||
coords[i] for i in range(len(coords)) if i not in drop
|
glyph.coordinates = GlyphCoordinates(
|
||||||
)
|
coords[i] for i in range(len(coords)) if i not in drop
|
||||||
glyph.flags = array("B", (flags[i] for i in range(len(flags)) if i not in drop))
|
)
|
||||||
|
glyph.flags = array("B", (flags[i] for i in range(len(flags)) if i not in drop))
|
||||||
|
|
||||||
endPts = glyph.endPtsOfContours
|
endPts = glyph.endPtsOfContours
|
||||||
newEndPts = []
|
newEndPts = []
|
||||||
i = 0
|
i = 0
|
||||||
delta = 0
|
delta = 0
|
||||||
for d in sorted(drop):
|
for d in sorted(drop):
|
||||||
while d > endPts[i]:
|
while d > endPts[i]:
|
||||||
|
newEndPts.append(endPts[i] - delta)
|
||||||
|
i += 1
|
||||||
|
delta += 1
|
||||||
|
while i < len(endPts):
|
||||||
newEndPts.append(endPts[i] - delta)
|
newEndPts.append(endPts[i] - delta)
|
||||||
i += 1
|
i += 1
|
||||||
delta += 1
|
glyph.endPtsOfContours = newEndPts
|
||||||
while i < len(endPts):
|
|
||||||
newEndPts.append(endPts[i] - delta)
|
|
||||||
i += 1
|
|
||||||
glyph.endPtsOfContours = newEndPts
|
|
||||||
|
|
||||||
|
|
||||||
class _TTGlyphBasePen:
|
class _TTGlyphBasePen:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user