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"]
|
||||
|
||||
|
||||
def drop_implied_oncurves(glyph):
|
||||
drop = set()
|
||||
start = 0
|
||||
flags = glyph.flags
|
||||
coords = glyph.coordinates
|
||||
for last in glyph.endPtsOfContours:
|
||||
for i in range(start, last + 1):
|
||||
if not (flags[i] & flagOnCurve):
|
||||
continue
|
||||
prv = i - 1 if i > start else last
|
||||
nxt = i + 1 if i < last else start
|
||||
if (flags[prv] & flagOnCurve) or flags[prv] != flags[nxt]:
|
||||
continue
|
||||
p0 = coords[prv]
|
||||
p1 = coords[i]
|
||||
p2 = coords[nxt]
|
||||
if not math.isclose(p1[0] - p0[0], p2[0] - p1[0]) or not math.isclose(
|
||||
p1[1] - p0[1], p2[1] - p1[1]
|
||||
):
|
||||
continue
|
||||
def drop_implied_oncurves(*interpolatable_glyphs):
|
||||
drop = None
|
||||
for glyph in interpolatable_glyphs:
|
||||
may_drop = set()
|
||||
start = 0
|
||||
flags = glyph.flags
|
||||
coords = glyph.coordinates
|
||||
for last in glyph.endPtsOfContours:
|
||||
for i in range(start, last + 1):
|
||||
if not (flags[i] & flagOnCurve):
|
||||
continue
|
||||
prv = i - 1 if i > start else last
|
||||
nxt = i + 1 if i < last else start
|
||||
if (flags[prv] & flagOnCurve) or flags[prv] != flags[nxt]:
|
||||
continue
|
||||
p0 = coords[prv]
|
||||
p1 = coords[i]
|
||||
p2 = coords[nxt]
|
||||
if not math.isclose(p1[0] - p0[0], p2[0] - p1[0]) or not math.isclose(
|
||||
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:
|
||||
# Do the actual dropping
|
||||
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))
|
||||
for glyph in interpolatable_glyphs:
|
||||
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))
|
||||
|
||||
endPts = glyph.endPtsOfContours
|
||||
newEndPts = []
|
||||
i = 0
|
||||
delta = 0
|
||||
for d in sorted(drop):
|
||||
while d > endPts[i]:
|
||||
endPts = glyph.endPtsOfContours
|
||||
newEndPts = []
|
||||
i = 0
|
||||
delta = 0
|
||||
for d in sorted(drop):
|
||||
while d > endPts[i]:
|
||||
newEndPts.append(endPts[i] - delta)
|
||||
i += 1
|
||||
delta += 1
|
||||
while i < len(endPts):
|
||||
newEndPts.append(endPts[i] - delta)
|
||||
i += 1
|
||||
delta += 1
|
||||
while i < len(endPts):
|
||||
newEndPts.append(endPts[i] - delta)
|
||||
i += 1
|
||||
glyph.endPtsOfContours = newEndPts
|
||||
glyph.endPtsOfContours = newEndPts
|
||||
|
||||
|
||||
class _TTGlyphBasePen:
|
||||
|
Loading…
x
Reference in New Issue
Block a user