[varLib.mutator] set OVERLAP_SIMPLE and OVERLAP_COMPOUND by default in instantiateVariableFont (#1518)

This commit is contained in:
Chris Simpkins 2019-02-28 12:34:43 -05:00 committed by Cosimo Lupo
parent c10cca83b0
commit 16bb3fd605
4 changed files with 26 additions and 13 deletions

View File

@ -9,7 +9,7 @@ from fontTools.misc.fixedTools import floatToFixedToFloat, otRound, floatToFixed
from fontTools.pens.boundsPen import BoundsPen
from fontTools.ttLib import TTFont, newTable
from fontTools.ttLib.tables import ttProgram
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates, flagOverlapSimple, OVERLAP_COMPOUND
from fontTools.varLib import _GetCoordinates, _SetCoordinates
from fontTools.varLib.models import (
supportScalar,
@ -145,7 +145,7 @@ def interpolate_cff2_metrics(varfont, topDict, glyphOrder, loc):
hmtx[gname] = tuple(entry)
def instantiateVariableFont(varfont, location, inplace=False):
def instantiateVariableFont(varfont, location, inplace=False, overlap=True):
""" Generate a static instance from a variable TTFont and a dictionary
defining the desired location along the variable font's axes.
The location values must be specified as user-space coordinates, e.g.:
@ -154,6 +154,10 @@ def instantiateVariableFont(varfont, location, inplace=False):
By default, a new TTFont object is returned. If ``inplace`` is True, the
input varfont is modified and reduced to a static font.
When the overlap parameter is defined as True,
OVERLAP_SIMPLE and OVERLAP_COMPOUND bits are set to 1. See
https://docs.microsoft.com/en-us/typography/opentype/spec/glyf
"""
if not inplace:
# make a copy to leave input varfont unmodified
@ -308,6 +312,15 @@ def instantiateVariableFont(varfont, location, inplace=False):
addidef = any(op.startswith("GETVARIATION") for op in instructions)
if addidef:
break
if overlap:
for glyph_name in glyf.keys():
glyph = glyf[glyph_name]
# Set OVERLAP_COMPOUND bit for compound glyphs
if glyph.isComposite():
glyph.components[0].flags |= OVERLAP_COMPOUND
# Set OVERLAP_SIMPLE bit for simple glyphs
elif glyph.numberOfContours > 0:
glyph.flags[0] |= flagOverlapSimple
if addidef:
log.info("Adding IDEF to fpgm table for GETVARIATION opcode")
asm = []

View File

@ -154,7 +154,7 @@
<TTGlyph name=".notdef" xMin="80" yMin="0" xMax="560" yMax="666">
<contour>
<pt x="83" y="0" on="1"/>
<pt x="83" y="0" on="1" overlap="1"/>
<pt x="503" y="666" on="1"/>
<pt x="557" y="666" on="1"/>
<pt x="137" y="0" on="1"/>
@ -190,7 +190,7 @@
<TTGlyph name="uni0024" xMin="51" yMin="-115" xMax="474" yMax="746">
<contour>
<pt x="251" y="31" on="1"/>
<pt x="251" y="31" on="1" overlap="1"/>
<pt x="309" y="31" on="0"/>
<pt x="379" y="92" on="0"/>
<pt x="379" y="144" on="1"/>
@ -262,7 +262,7 @@
<TTGlyph name="uni0024.nostroke" xMin="51" yMin="-115" xMax="474" yMax="746">
<contour>
<pt x="251" y="31" on="1"/>
<pt x="251" y="31" on="1" overlap="1"/>
<pt x="308" y="31" on="0"/>
<pt x="377" y="90" on="0"/>
<pt x="377" y="142" on="1"/>
@ -334,7 +334,7 @@
<TTGlyph name="uni0041" xMin="7" yMin="0" xMax="656" yMax="670">
<contour>
<pt x="7" y="0" on="1"/>
<pt x="7" y="0" on="1" overlap="1"/>
<pt x="7" y="38" on="1"/>
<pt x="104" y="53" on="1"/>
<pt x="124" y="53" on="1"/>
@ -370,7 +370,7 @@
<TTGlyph name="uni0061" xMin="42" yMin="-14" xMax="511" yMax="490">
<contour>
<pt x="42" y="110" on="1"/>
<pt x="42" y="110" on="1" overlap="1"/>
<pt x="42" y="157" on="0"/>
<pt x="110" y="229" on="0"/>
<pt x="214" y="265" on="1"/>

View File

@ -168,7 +168,7 @@
<TTGlyph name="a" xMin="38" yMin="-12" xMax="388" yMax="468">
<contour>
<pt x="312" y="0" on="1"/>
<pt x="312" y="0" on="1" overlap="1"/>
<pt x="312" y="64" on="1"/>
<pt x="244" y="-12" on="1"/>
<pt x="180" y="-12" on="1"/>
@ -200,7 +200,7 @@
<TTGlyph name="b" xMin="76" yMin="-12" xMax="426" yMax="628">
<contour>
<pt x="218" y="468" on="1"/>
<pt x="218" y="468" on="1" overlap="1"/>
<pt x="284" y="468" on="1"/>
<pt x="426" y="316" on="1"/>
<pt x="426" y="140" on="1"/>
@ -229,7 +229,7 @@
<TTGlyph name="nonmarkingreturn"/><!-- contains no outline data -->
<TTGlyph name="q" xMin="38" yMin="-172" xMax="388" yMax="468">
<component glyphName="b" x="464" y="456" scale="-0.99994" flags="0x4"/>
<component glyphName="b" x="464" y="456" scale="-0.99994" flags="0x404"/>
</TTGlyph>
<TTGlyph name="space"/><!-- contains no outline data -->

View File

@ -157,7 +157,7 @@
<TTGlyph name="a" xMin="38" yMin="-12" xMax="388" yMax="468">
<contour>
<pt x="312" y="0" on="1"/>
<pt x="312" y="0" on="1" overlap="1"/>
<pt x="312" y="64" on="1"/>
<pt x="244" y="-12" on="1"/>
<pt x="180" y="-12" on="1"/>
@ -185,7 +185,7 @@
<TTGlyph name="b" xMin="76" yMin="-12" xMax="426" yMax="628">
<contour>
<pt x="218" y="468" on="1"/>
<pt x="218" y="468" on="1" overlap="1"/>
<pt x="284" y="468" on="1"/>
<pt x="426" y="316" on="1"/>
<pt x="426" y="140" on="1"/>
@ -214,7 +214,7 @@
<TTGlyph name="nonmarkingreturn"/><!-- contains no outline data -->
<TTGlyph name="q" xMin="38" yMin="-172" xMax="388" yMax="468">
<component glyphName="b" x="464" y="456" scale="-0.99994" flags="0x4"/>
<component glyphName="b" x="464" y="456" scale="-0.99994" flags="0x404"/>
</TTGlyph>
<TTGlyph name="space"/><!-- contains no outline data -->