-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #816 from googlefonts/vf-fontinfo
Apply DesignSpace variable-font's public.fontInfo lib key to variable fonts
- Loading branch information
Showing
25 changed files
with
670 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
""" | ||
InfoCompiler is used to apply fontinfo overrides to an already compiled font. | ||
This is used to apply fontinfo from a DesignSpace variable-font after merging | ||
font sources into final variable font. | ||
It builds a temporary font with the only the tables that can be modified with | ||
fontinfo, then merge relevant table attributes it into the original font. | ||
""" | ||
|
||
import copy | ||
|
||
from ufo2ft.outlineCompiler import BaseOutlineCompiler | ||
|
||
|
||
class InfoCompiler(BaseOutlineCompiler): | ||
info_tables = frozenset( | ||
[ | ||
"head", | ||
"hhea", | ||
"name", | ||
"OS/2", | ||
"post", | ||
"vhea", | ||
"gasp", | ||
] | ||
) | ||
|
||
def __init__(self, otf, ufo, info): | ||
self.orig_otf = otf | ||
tables = self.info_tables & set(otf.keys()) | ||
|
||
# Create a temporary UFO and sets its fontinfo to the union of the main | ||
# UFO's fontinfo and the DesignSpace variable-font’s info. | ||
temp_ufo = type(ufo)() | ||
if hasattr(ufo.info, "getDataForSerialization"): | ||
# defcon | ||
data = ufo.info.getDataForSerialization() | ||
data.update(info) | ||
temp_ufo.info.setDataFromSerialization(data) | ||
else: | ||
# ufoLib2 | ||
temp_ufo.info = copy.copy(ufo.info) | ||
for k, v in info.items(): | ||
setattr(temp_ufo.info, k, v) | ||
|
||
super().__init__(temp_ufo, tables=tables, glyphSet={}, glyphOrder=[]) | ||
|
||
def compile(self): | ||
super().compile() | ||
if "gasp" in self.tables: | ||
self.setupTable_gasp() | ||
return self.orig_otf | ||
|
||
@staticmethod | ||
def makeMissingRequiredGlyphs(*args, **kwargs): | ||
return | ||
|
||
def makeFontBoundingBox(self): | ||
from ufo2ft.outlineCompiler import EMPTY_BOUNDING_BOX | ||
|
||
return EMPTY_BOUNDING_BOX | ||
|
||
def _set_attrs(self, tag, attrs): | ||
temp = self.otf[tag] | ||
orig = self.orig_otf[tag] | ||
for attr in attrs: | ||
if (value := getattr(temp, attr, None)) is not None: | ||
setattr(orig, attr, value) | ||
|
||
def setupTable_head(self): | ||
super().setupTable_head() | ||
self._set_attrs( | ||
"head", | ||
{ | ||
"fontRevision", | ||
"unitsPerEm", | ||
"created", | ||
"macStyle", | ||
"flags", | ||
"lowestRecPPEM", | ||
}, | ||
) | ||
|
||
def setupTable_hhea(self): | ||
super().setupTable_hhea() | ||
self._set_attrs( | ||
"hhea", | ||
{ | ||
"ascent", | ||
"descent", | ||
"lineGap", | ||
"caretSlopeRise", | ||
"caretSlopeRun", | ||
"caretOffset", | ||
}, | ||
) | ||
|
||
def setupTable_vhea(self): | ||
super().setupTable_vhea() | ||
self._set_attrs( | ||
"vhea", | ||
{ | ||
"ascent", | ||
"descent", | ||
"lineGap", | ||
"caretSlopeRise", | ||
"caretSlopeRun", | ||
"caretOffset", | ||
}, | ||
) | ||
|
||
def setupTable_OS2(self): | ||
super().setupTable_OS2() | ||
self._set_attrs( | ||
"OS/2", | ||
{ | ||
"usWeightClass", | ||
"usWidthClass", | ||
"fsType", | ||
"ySubscriptXSize", | ||
"ySubscriptYSize", | ||
"ySubscriptYOffset", | ||
"ySubscriptXOffset", | ||
"ySuperscriptXSize", | ||
"ySuperscriptYSize", | ||
"ySuperscriptYOffset", | ||
"ySuperscriptXOffset", | ||
"yStrikeoutSize", | ||
"yStrikeoutPosition", | ||
"sFamilyClass", | ||
"panose", | ||
"ulUnicodeRange1", | ||
"ulUnicodeRange2", | ||
"ulUnicodeRange3", | ||
"ulUnicodeRange4", | ||
"achVendID", | ||
"fsSelection", | ||
"sTypoAscender", | ||
"sTypoDescender", | ||
"sTypoLineGap", | ||
"usWinAscent", | ||
"usWinDescent", | ||
"ulCodePageRange1", | ||
"ulCodePageRange2", | ||
"sxHeight", | ||
"sCapHeight", | ||
}, | ||
) | ||
|
||
def setupTable_post(self): | ||
super().setupTable_post() | ||
self._set_attrs( | ||
"post", | ||
{ | ||
"italicAngle", | ||
"underlinePosition", | ||
"underlineThickness", | ||
"isFixedPitch", | ||
}, | ||
) | ||
|
||
def setupTable_name(self): | ||
super().setupTable_name() | ||
temp = self.otf["name"] | ||
orig = self.orig_otf["name"] | ||
temp_names = { | ||
(n.nameID, n.platformID, n.platEncID, n.langID): n for n in temp.names | ||
} | ||
orig_names = { | ||
(n.nameID, n.platformID, n.platEncID, n.langID): n for n in orig.names | ||
} | ||
orig_names.update(temp_names) | ||
orig.names = list(orig_names.values()) | ||
|
||
def setupTable_gasp(self): | ||
from ufo2ft.instructionCompiler import InstructionCompiler | ||
|
||
instructionCompiler = InstructionCompiler(self.ufo, self.otf) | ||
instructionCompiler.setupTable_gasp() | ||
self._set_attrs("gasp", {"gaspRange"}) | ||
|
||
def setupTable_maxp(self): | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>ascender</key> | ||
<integer>600</integer> | ||
<key>capHeight</key> | ||
<integer>700</integer> | ||
<key>descender</key> | ||
<integer>-400</integer> | ||
<key>familyName</key> | ||
<string>TestVarFont</string> | ||
<key>italicAngle</key> | ||
<integer>0</integer> | ||
<key>openTypeHeadCreated</key> | ||
<string>2022/07/26 14:49:29</string> | ||
<key>openTypeOS2Type</key> | ||
<array> | ||
<integer>3</integer> | ||
</array> | ||
<key>postscriptUnderlinePosition</key> | ||
<integer>-100</integer> | ||
<key>postscriptUnderlineThickness</key> | ||
<integer>50</integer> | ||
<key>styleName</key> | ||
<string>Bold</string> | ||
<key>unitsPerEm</key> | ||
<integer>1000</integer> | ||
<key>versionMajor</key> | ||
<integer>1</integer> | ||
<key>versionMinor</key> | ||
<integer>0</integer> | ||
<key>xHeight</key> | ||
<integer>500</integer> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<glyph name="alef-ar.fina" format="2"> | ||
<advance width="410"/> | ||
<unicode hex="0627"/> | ||
<outline> | ||
<contour> | ||
<point x="280" y="601" type="line"/> | ||
<point x="280" y="160" type="line"/> | ||
<point x="470" y="160" type="line"/> | ||
<point x="470" y="0" type="line"/> | ||
<point x="120" y="0" type="line"/> | ||
<point x="120" y="569" type="line"/> | ||
</contour> | ||
</outline> | ||
</glyph> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>alef-ar.fina</key> | ||
<string>alef-ar.fina.glif</string> | ||
<key>space</key> | ||
<string>space.glif</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<glyph name="space" format="2"> | ||
<advance width="600"/> | ||
<unicode hex="0020"/> | ||
<outline> | ||
</outline> | ||
</glyph> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<array> | ||
<array> | ||
<string>public.default</string> | ||
<string>glyphs</string> | ||
</array> | ||
</array> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>public.glyphOrder</key> | ||
<array> | ||
<string>space</string> | ||
<string>alef-ar.fina</string> | ||
</array> | ||
<key>public.postscriptNames</key> | ||
<dict> | ||
<key>alef-ar.fina</key> | ||
<string>uniFE8E</string> | ||
</dict> | ||
</dict> | ||
</plist> |
Oops, something went wrong.