Fixes an issue with rendering on Windows with ClearType by decomposing any components which use non-trivial transformations like rotation or shear. This increases font size a bit but not to any worrying degree. Closes #251

This commit is contained in:
Rasmus Andersson 2020-08-19 13:54:30 -07:00
parent 05e3a4c774
commit 7d70535c01
3 changed files with 31 additions and 15 deletions

View file

@ -185,7 +185,7 @@ build/ufo/features: src/features
# hinted TTF files via autohint
$(FONTDIR)/const-hinted/%.ttf: $(FONTDIR)/const/%.ttf
mkdir -p "$(dir $@)"
ttfautohint --fallback-stem-width=256 --no-info "$<" "$@"
ttfautohint --windows-compatibility --adjust-subglyphs --no-info "$<" "$@"
# python -m ttfautohint --fallback-stem-width=256 --no-info "$<" "$@"

View file

@ -26,6 +26,9 @@ from fontbuildlib.name import setFamilyName, renameStylesGoogleFonts
log = logging.getLogger(__name__)
# set to true to exclude anchors from .glyphs when generating UFOs
EXCLUDE_ANCHORS = False
def sighandler(signum, frame):
sys.stdout.write('\n')
@ -268,7 +271,8 @@ class Main(object):
if g.name in glyphOrder:
del(glyphOrder[g.name])
g.unicodes = []
# g.clearAnchors()
if EXCLUDE_ANCHORS:
g.clearAnchors()
if 'com.schriftgestaltung.Glyphs.lastChange' in g.lib:
del(g.lib['com.schriftgestaltung.Glyphs.lastChange'])
@ -380,7 +384,7 @@ class Main(object):
# generate designspace from glyphs project
designspace = glyphsLib.to_designspace(
font,
# propagate_anchors=False,
propagate_anchors=(not EXCLUDE_ANCHORS),
instance_dir=relpath(instance_dir, master_dir),
store_editor_state=False, # do not store glyphs editor UI state in UFOs
)
@ -527,9 +531,10 @@ class Main(object):
del(font.lib[italicAngleKey])
font.info.italicAngle = italicAngle
# # clear anchors
# for g in font:
# g.clearAnchors()
# clear anchors
if EXCLUDE_ANCHORS:
for g in font:
g.clearAnchors()
# update font info
weight = instance_weight[basename(font.path)]

View file

@ -27,6 +27,14 @@ class FontBuilder:
# update version to actual, real version. Must come after any call to setFontInfo.
updateFontVersion(ufo, dummy=False, isVF=False)
# decompose some glyphs
glyphNamesToDecompose = set()
for g in ufo:
directives = findGlyphDirectives(g.note)
if 'decompose' in directives or (g.components and not composedGlyphIsTrivial(g)):
glyphNamesToDecompose.add(g.name)
self._decompose([ufo], glyphNamesToDecompose)
compilerOptions = dict(
useProductionNames=True,
inplace=True, # avoid extra copy
@ -89,9 +97,16 @@ class FontBuilder:
font.save(outputFilename)
def _decompose(self, ufos, glyphNamesToDecompose):
if glyphNamesToDecompose:
if log.isEnabledFor(logging.DEBUG):
log.debug('Decomposing glyphs:\n %s', "\n ".join(glyphNamesToDecompose))
elif log.isEnabledFor(logging.INFO):
log.info('Decomposing %d glyphs', len(glyphNamesToDecompose))
decomposeGlyphs(ufos, glyphNamesToDecompose)
@staticmethod
def _loadDesignspace(designspace):
def _loadDesignspace(self, designspace):
log.info("loading designspace sources")
if isinstance(designspace, str):
designspace = DesignSpaceDocument.fromfile(designspace)
@ -120,6 +135,8 @@ class FontBuilder:
for ufo in masters:
for g in ufo:
directives = findGlyphDirectives(g.note)
if g.name == 'parenright':
print("parenright directives:", repr(directives))
if 'decompose' in directives or (g.components and not composedGlyphIsTrivial(g)):
glyphNamesToDecompose.add(g.name)
if 'removeoverlap' in directives:
@ -127,13 +144,7 @@ class FontBuilder:
glyphNamesToDecompose.add(g.name)
glyphsToRemoveOverlaps.add(g)
# decompose
if glyphNamesToDecompose:
if log.isEnabledFor(logging.DEBUG):
log.debug('Decomposing glyphs:\n %s', "\n ".join(glyphNamesToDecompose))
elif log.isEnabledFor(logging.INFO):
log.info('Decomposing %d glyphs', len(glyphNamesToDecompose))
decomposeGlyphs(masters, glyphNamesToDecompose)
self._decompose(masters, glyphNamesToDecompose)
# remove overlaps
if glyphsToRemoveOverlaps: