-
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.
Move InfoCompiler class to its own file
- Loading branch information
1 parent
f8a40e6
commit c20b61d
Showing
2 changed files
with
154 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
from ufo2ft.outlineCompiler import BaseOutlineCompiler | ||
|
||
|
||
class InfoCompiler(BaseOutlineCompiler): | ||
info_tables = frozenset( | ||
[ | ||
"head", | ||
"hhea", | ||
"name", | ||
"OS/2", | ||
"post", | ||
"vhea", | ||
"gasp", | ||
] | ||
) | ||
|
||
def __init__(self, ufo, otf): | ||
self.orig_otf = otf | ||
tables = self.info_tables & set(otf.keys()) | ||
super().__init__(ufo, tables=tables, glyphSet={}, glyphOrder=[]) | ||
if "gasp" in tables: | ||
self.setupTable_gasp() | ||
|
||
@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): | ||
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