8000 [varLib.mutator] Add support for macOS overlap rendering flag in instantiateVariableFont by chrissimpkins · Pull Request #1518 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[varLib.mutator] Add support for macOS overlap rendering flag in instantiateVariableFont #1518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Lib/fontTools/varLib/mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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,
Expand Down Expand Up @@ -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.:
Expand All @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
10 changes: 5 additions & 5 deletions Tests/varLib/data/test_results/Mutator.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down
6 changes: 3 additions & 3 deletions Tests/varLib/data/test_results/Mutator_Getvar-instance.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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 -->
Expand Down
6 changes: 3 additions & 3 deletions Tests/varLib/data/test_results/Mutator_IUP-instance.ttx
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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"/>
Expand Down Expand Up @@ -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 -->
Expand Down
0