From 7d70535c01803b9c734147acb3049a74875f6356 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Wed, 19 Aug 2020 13:54:30 -0700 Subject: 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 --- Makefile | 2 +- misc/fontbuild | 15 ++++++++++----- misc/fontbuildlib/builder.py | 29 ++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index bcfb1bdc3..9408bdf1c 100644 --- a/Makefile +++ b/Makefile @@ -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 "$<" "$@" diff --git a/misc/fontbuild b/misc/fontbuild index 2913c5495..170057d1a 100755 --- a/misc/fontbuild +++ b/misc/fontbuild @@ -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)] diff --git a/misc/fontbuildlib/builder.py b/misc/fontbuildlib/builder.py index da769769c..bef295d13 100644 --- a/misc/fontbuildlib/builder.py +++ b/misc/fontbuildlib/builder.py @@ -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: -- cgit v1.2.3