use a "smart rounding" algorithm to handle rounding when reducing upm.

This commit is contained in:
be5invis 2015-08-28 17:41:13 +08:00
parent 7c77c8182d
commit f3ae40b75d
8 changed files with 125 additions and 23 deletions

View file

@ -5,8 +5,9 @@ import sys
source = sys.argv[1]
font = fontforge.open(source)
font.mergeFeature(sys.argv[2])
# Replace accented characters into references
print "Reference finding: ", font.fontname
font.selection.select(("ranges", "unicode", None), 0x1FCD, 0x1FCF, 0x1FDD, 0x1FDF)
font.replaceWithReference(4)
font.selection.none()
@ -16,6 +17,9 @@ font.selection.none()
font.selection.select(("ranges", "unicode", None), 0x0000, 0xFFFF)
font.replaceWithReference(4)
font.selection.none()
# Remove overlapped area
print "Overlap Removal: ", font.fontname
font.selection.all()
font.removeOverlap()
font.round()
@ -26,18 +30,28 @@ for i in font:
glyph.unlinkRef()
glyph.removeOverlap()
# Outline simplify
print "Simplify, pass 1: ", font.fontname
font.simplify(1)
font.layers["Fore"].is_quadratic = False
font.selection.all()
font.simplify(font.em / 1000.0, ("smoothcurves"), 0.05)
font.transform(psMat.skew(-font.italicangle / 180 * math.pi))
# convert cubic outlines to quadratic under 1000upm
font.simplify(font.em / 1000.0 * 0.5, ("smoothcurves", "choosehv"), 0.1);
print "Simplify, pass 2: ", font.fontname
oldem = font.em
font.em = 1000
font.round()
font.simplify(0.25)
font.transform(psMat.skew(-font.italicangle / 180 * math.pi))
for i in font:
font[i].addExtrema(("all"))
font.simplify(1, ("smoothcurves"), 0.05)
font.layers["Fore"].is_quadratic = True
font.round()
font.simplify(1)
print "Finalize: ", font.fontname
font.em = oldem
font.mergeFeature(sys.argv[2])
font.canonicalContours()
font.canonicalStart()
font.generate(sys.argv[3], flags = ("short-post", "opentype"))