fonttools 4.56.0__cp38-cp38-win_amd64.whl → 4.57.0__cp38-cp38-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fonttools might be problematic. Click here for more details.

Files changed (34) hide show
  1. fontTools/__init__.py +1 -1
  2. fontTools/config/__init__.py +15 -0
  3. fontTools/cu2qu/cu2qu.cp38-win_amd64.pyd +0 -0
  4. fontTools/feaLib/ast.py +8 -3
  5. fontTools/feaLib/builder.py +32 -9
  6. fontTools/feaLib/lexer.cp38-win_amd64.pyd +0 -0
  7. fontTools/feaLib/parser.py +58 -0
  8. fontTools/misc/bezierTools.cp38-win_amd64.pyd +0 -0
  9. fontTools/misc/testTools.py +2 -1
  10. fontTools/otlLib/optimize/gpos.py +7 -1
  11. fontTools/pens/momentsPen.cp38-win_amd64.pyd +0 -0
  12. fontTools/qu2cu/qu2cu.cp38-win_amd64.pyd +0 -0
  13. fontTools/ttLib/__init__.py +4 -0
  14. fontTools/ttLib/__main__.py +47 -8
  15. fontTools/ttLib/tables/D__e_b_g.py +20 -2
  16. fontTools/ttLib/tables/_c_m_a_p.py +19 -6
  17. fontTools/ttLib/tables/_g_l_y_f.py +9 -4
  18. fontTools/ttLib/tables/_g_v_a_r.py +4 -2
  19. fontTools/ttLib/tables/otConverters.py +5 -2
  20. fontTools/ttLib/tables/otTables.py +5 -1
  21. fontTools/ttLib/ttFont.py +3 -5
  22. fontTools/ttLib/ttGlyphSet.py +0 -10
  23. fontTools/ttx.py +13 -1
  24. fontTools/varLib/__init__.py +92 -89
  25. fontTools/varLib/hvar.py +113 -0
  26. fontTools/varLib/iup.cp38-win_amd64.pyd +0 -0
  27. fontTools/varLib/varStore.py +1 -1
  28. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/METADATA +14 -1
  29. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/RECORD +34 -33
  30. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/WHEEL +1 -1
  31. {fonttools-4.56.0.data → fonttools-4.57.0.data}/data/share/man/man1/ttx.1 +0 -0
  32. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/LICENSE +0 -0
  33. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/entry_points.txt +0 -0
  34. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/top_level.txt +0 -0
fontTools/__init__.py CHANGED
@@ -3,6 +3,6 @@ from fontTools.misc.loggingTools import configLogger
3
3
 
4
4
  log = logging.getLogger(__name__)
5
5
 
6
- version = __version__ = "4.56.0"
6
+ version = __version__ = "4.57.0"
7
7
 
8
8
  __all__ = ["version", "log", "configLogger"]
@@ -73,3 +73,18 @@ Config.register_option(
73
73
  parse=Option.parse_optional_bool,
74
74
  validate=Option.validate_optional_bool,
75
75
  )
76
+
77
+ Config.register_option(
78
+ name="fontTools.ttLib:OPTIMIZE_FONT_SPEED",
79
+ help=dedent(
80
+ """\
81
+ Enable optimizations that prioritize speed over file size. This
82
+ mainly affects how glyf table and gvar / VARC tables are compiled.
83
+ The produced fonts will be larger, but rendering performance will
84
+ be improved with HarfBuzz and other text layout engines.
85
+ """
86
+ ),
87
+ default=False,
88
+ parse=Option.parse_optional_bool,
89
+ validate=Option.validate_optional_bool,
90
+ )
Binary file
fontTools/feaLib/ast.py CHANGED
@@ -1828,15 +1828,16 @@ class BaseAxis(Statement):
1828
1828
  """An axis definition, being either a ``VertAxis.BaseTagList/BaseScriptList``
1829
1829
  pair or a ``HorizAxis.BaseTagList/BaseScriptList`` pair."""
1830
1830
 
1831
- def __init__(self, bases, scripts, vertical, location=None):
1831
+ def __init__(self, bases, scripts, vertical, minmax=None, location=None):
1832
1832
  Statement.__init__(self, location)
1833
1833
  self.bases = bases #: A list of baseline tag names as strings
1834
1834
  self.scripts = scripts #: A list of script record tuplets (script tag, default baseline tag, base coordinate)
1835
1835
  self.vertical = vertical #: Boolean; VertAxis if True, HorizAxis if False
1836
+ self.minmax = [] #: A set of minmax record
1836
1837
 
1837
1838
  def build(self, builder):
1838
1839
  """Calls the builder object's ``set_base_axis`` callback."""
1839
- builder.set_base_axis(self.bases, self.scripts, self.vertical)
1840
+ builder.set_base_axis(self.bases, self.scripts, self.vertical, self.minmax)
1840
1841
 
1841
1842
  def asFea(self, indent=""):
1842
1843
  direction = "Vert" if self.vertical else "Horiz"
@@ -1844,9 +1845,13 @@ class BaseAxis(Statement):
1844
1845
  "{} {} {}".format(a[0], a[1], " ".join(map(str, a[2])))
1845
1846
  for a in self.scripts
1846
1847
  ]
1848
+ minmaxes = [
1849
+ "\n{}Axis.MinMax {} {} {}, {};".format(direction, a[0], a[1], a[2], a[3])
1850
+ for a in self.minmax
1851
+ ]
1847
1852
  return "{}Axis.BaseTagList {};\n{}{}Axis.BaseScriptList {};".format(
1848
1853
  direction, " ".join(self.bases), indent, direction, ", ".join(scripts)
1849
- )
1854
+ ) + "\n".join(minmaxes)
1850
1855
 
1851
1856
 
1852
1857
  class OS2Field(Statement):
@@ -341,6 +341,7 @@ class Builder(object):
341
341
  table = self.font["head"] = newTable("head")
342
342
  table.decompile(b"\0" * 54, self.font)
343
343
  table.tableVersion = 1.0
344
+ table.magicNumber = 0x5F0F3CF5
344
345
  table.created = table.modified = 3406620153 # 2011-12-13 11:22:33
345
346
  table.fontRevision = self.fontRevision_
346
347
 
@@ -727,10 +728,16 @@ class Builder(object):
727
728
  result.table = base
728
729
  return result
729
730
 
731
+ def buildBASECoord(self, c):
732
+ coord = otTables.BaseCoord()
733
+ coord.Format = 1
734
+ coord.Coordinate = c
735
+ return coord
736
+
730
737
  def buildBASEAxis(self, axis):
731
738
  if not axis:
732
739
  return
733
- bases, scripts = axis
740
+ bases, scripts, minmax = axis
734
741
  axis = otTables.Axis()
735
742
  axis.BaseTagList = otTables.BaseTagList()
736
743
  axis.BaseTagList.BaselineTag = bases
@@ -739,19 +746,35 @@ class Builder(object):
739
746
  axis.BaseScriptList.BaseScriptRecord = []
740
747
  axis.BaseScriptList.BaseScriptCount = len(scripts)
741
748
  for script in sorted(scripts):
749
+ minmax_for_script = [
750
+ record[1:] for record in minmax if record[0] == script[0]
751
+ ]
742
752
  record = otTables.BaseScriptRecord()
743
753
  record.BaseScriptTag = script[0]
744
754
  record.BaseScript = otTables.BaseScript()
745
- record.BaseScript.BaseLangSysCount = 0
746
755
  record.BaseScript.BaseValues = otTables.BaseValues()
747
756
  record.BaseScript.BaseValues.DefaultIndex = bases.index(script[1])
748
757
  record.BaseScript.BaseValues.BaseCoord = []
749
758
  record.BaseScript.BaseValues.BaseCoordCount = len(script[2])
759
+ record.BaseScript.BaseLangSysRecord = []
760
+
750
761
  for c in script[2]:
751
- coord = otTables.BaseCoord()
752
- coord.Format = 1
753
- coord.Coordinate = c
754
- record.BaseScript.BaseValues.BaseCoord.append(coord)
762
+ record.BaseScript.BaseValues.BaseCoord.append(self.buildBASECoord(c))
763
+ for language, min_coord, max_coord in minmax_for_script:
764
+ minmax_record = otTables.MinMax()
765
+ minmax_record.MinCoord = self.buildBASECoord(min_coord)
766
+ minmax_record.MaxCoord = self.buildBASECoord(max_coord)
767
+ minmax_record.FeatMinMaxCount = 0
768
+ if language == "dflt":
769
+ record.BaseScript.DefaultMinMax = minmax_record
770
+ else:
771
+ lang_record = otTables.BaseLangSysRecord()
772
+ lang_record.BaseLangSysTag = language
773
+ lang_record.MinMax = minmax_record
774
+ record.BaseScript.BaseLangSysRecord.append(lang_record)
775
+ record.BaseScript.BaseLangSysCount = len(
776
+ record.BaseScript.BaseLangSysRecord
777
+ )
755
778
  axis.BaseScriptList.BaseScriptRecord.append(record)
756
779
  return axis
757
780
 
@@ -1235,11 +1258,11 @@ class Builder(object):
1235
1258
  def add_cv_character(self, character, tag):
1236
1259
  self.cv_characters_[tag].append(character)
1237
1260
 
1238
- def set_base_axis(self, bases, scripts, vertical):
1261
+ def set_base_axis(self, bases, scripts, vertical, minmax=[]):
1239
1262
  if vertical:
1240
- self.base_vert_axis_ = (bases, scripts)
1263
+ self.base_vert_axis_ = (bases, scripts, minmax)
1241
1264
  else:
1242
- self.base_horiz_axis_ = (bases, scripts)
1265
+ self.base_horiz_axis_ = (bases, scripts, minmax)
1243
1266
 
1244
1267
  def set_size_parameters(
1245
1268
  self, location, DesignSize, SubfamilyID, RangeStart, RangeEnd
Binary file
@@ -1286,6 +1286,19 @@ class Parser(object):
1286
1286
  n = match.group(0)[1:]
1287
1287
  return bytechr(int(n, 16)).decode(encoding)
1288
1288
 
1289
+ def find_previous(self, statements, class_):
1290
+ for previous in reversed(statements):
1291
+ if isinstance(previous, self.ast.Comment):
1292
+ continue
1293
+ elif isinstance(previous, class_):
1294
+ return previous
1295
+ else:
1296
+ # If we find something that doesn't match what we're looking
1297
+ # for, and isn't a comment, fail
1298
+ return None
1299
+ # Out of statements to look at
1300
+ return None
1301
+
1289
1302
  def parse_table_BASE_(self, table):
1290
1303
  statements = table.statements
1291
1304
  while self.next_token_ != "}" or self.cur_comments_:
@@ -1306,6 +1319,19 @@ class Parser(object):
1306
1319
  location=self.cur_token_location_,
1307
1320
  )
1308
1321
  )
1322
+ elif self.is_cur_keyword_("HorizAxis.MinMax"):
1323
+ base_script_list = self.find_previous(statements, ast.BaseAxis)
1324
+ if base_script_list is None:
1325
+ raise FeatureLibError(
1326
+ "MinMax must be preceded by BaseScriptList",
1327
+ self.cur_token_location_,
1328
+ )
1329
+ if base_script_list.vertical:
1330
+ raise FeatureLibError(
1331
+ "HorizAxis.MinMax must be preceded by HorizAxis statements",
1332
+ self.cur_token_location_,
1333
+ )
1334
+ base_script_list.minmax.append(self.parse_base_minmax_())
1309
1335
  elif self.is_cur_keyword_("VertAxis.BaseTagList"):
1310
1336
  vert_bases = self.parse_base_tag_list_()
1311
1337
  elif self.is_cur_keyword_("VertAxis.BaseScriptList"):
@@ -1318,6 +1344,19 @@ class Parser(object):
1318
1344
  location=self.cur_token_location_,
1319
1345
  )
1320
1346
  )
1347
+ elif self.is_cur_keyword_("VertAxis.MinMax"):
1348
+ base_script_list = self.find_previous(statements, ast.BaseAxis)
1349
+ if base_script_list is None:
1350
+ raise FeatureLibError(
1351
+ "MinMax must be preceded by BaseScriptList",
1352
+ self.cur_token_location_,
1353
+ )
1354
+ if not base_script_list.vertical:
1355
+ raise FeatureLibError(
1356
+ "VertAxis.MinMax must be preceded by VertAxis statements",
1357
+ self.cur_token_location_,
1358
+ )
1359
+ base_script_list.minmax.append(self.parse_base_minmax_())
1321
1360
  elif self.cur_token_ == ";":
1322
1361
  continue
1323
1362
 
@@ -1587,6 +1626,25 @@ class Parser(object):
1587
1626
  coords = [self.expect_number_() for i in range(count)]
1588
1627
  return script_tag, base_tag, coords
1589
1628
 
1629
+ def parse_base_minmax_(self):
1630
+ script_tag = self.expect_script_tag_()
1631
+ language = self.expect_language_tag_()
1632
+ min_coord = self.expect_number_()
1633
+ self.advance_lexer_()
1634
+ if not (self.cur_token_type_ is Lexer.SYMBOL and self.cur_token_ == ","):
1635
+ raise FeatureLibError(
1636
+ "Expected a comma between min and max coordinates",
1637
+ self.cur_token_location_,
1638
+ )
1639
+ max_coord = self.expect_number_()
1640
+ if self.next_token_ == ",": # feature tag...
1641
+ raise FeatureLibError(
1642
+ "Feature tags are not yet supported in BASE table",
1643
+ self.cur_token_location_,
1644
+ )
1645
+
1646
+ return script_tag, language, min_coord, max_coord
1647
+
1590
1648
  def parse_device_(self):
1591
1649
  result = None
1592
1650
  self.expect_symbol_("<")
@@ -46,7 +46,8 @@ def parseXmlInto(font, parseInto, xmlSnippet):
46
46
  parsed_xml = [e for e in parseXML(xmlSnippet.strip()) if not isinstance(e, str)]
47
47
  for name, attrs, content in parsed_xml:
48
48
  parseInto.fromXML(name, attrs, content, font)
49
- parseInto.populateDefaults()
49
+ if hasattr(parseInto, "populateDefaults"):
50
+ parseInto.populateDefaults()
50
51
  return parseInto
51
52
 
52
53
 
@@ -53,12 +53,18 @@ def compact(font: TTFont, level: int) -> TTFont:
53
53
  # are not grouped together first; instead each subtable is treated
54
54
  # independently, so currently this step is:
55
55
  # Split existing subtables into more smaller subtables
56
- gpos = font["GPOS"]
56
+ gpos = font.get("GPOS")
57
+
58
+ # If the font does not contain a GPOS table, there is nothing to do.
59
+ if gpos is None:
60
+ return font
61
+
57
62
  for lookup in gpos.table.LookupList.Lookup:
58
63
  if lookup.LookupType == 2:
59
64
  compact_lookup(font, level, lookup)
60
65
  elif lookup.LookupType == 9 and lookup.SubTable[0].ExtensionLookupType == 2:
61
66
  compact_ext_lookup(font, level, lookup)
67
+
62
68
  return font
63
69
 
64
70
 
Binary file
@@ -1,5 +1,6 @@
1
1
  """fontTools.ttLib -- a package for dealing with TrueType fonts."""
2
2
 
3
+ from fontTools.config import OPTIONS
3
4
  from fontTools.misc.loggingTools import deprecateFunction
4
5
  import logging
5
6
 
@@ -7,6 +8,9 @@ import logging
7
8
  log = logging.getLogger(__name__)
8
9
 
9
10
 
11
+ OPTIMIZE_FONT_SPEED = OPTIONS["fontTools.ttLib:OPTIMIZE_FONT_SPEED"]
12
+
13
+
10
14
  class TTLibError(Exception):
11
15
  pass
12
16
 
@@ -1,5 +1,5 @@
1
1
  import sys
2
- from fontTools.ttLib import TTLibError, TTLibFileIsCollectionError
2
+ from fontTools.ttLib import OPTIMIZE_FONT_SPEED, TTLibError, TTLibFileIsCollectionError
3
3
  from fontTools.ttLib.ttFont import *
4
4
  from fontTools.ttLib.ttCollection import TTCollection
5
5
 
@@ -51,7 +51,7 @@ def main(args=None):
51
51
  )
52
52
  parser.add_argument("font", metavar="font", nargs="*", help="Font file.")
53
53
  parser.add_argument(
54
- "-t", "--table", metavar="table", nargs="*", help="Tables to decompile."
54
+ "-t", "--table", metavar="table", action="append", help="Tables to decompile."
55
55
  )
56
56
  parser.add_argument(
57
57
  "-o", "--output", metavar="FILE", default=None, help="Output file."
@@ -71,27 +71,66 @@ def main(args=None):
71
71
  default=None,
72
72
  help="Flavor of output font. 'woff' or 'woff2'.",
73
73
  )
74
+ parser.add_argument(
75
+ "--no-recalc-timestamp",
76
+ dest="recalcTimestamp",
77
+ action="store_false",
78
+ help="Keep the original font 'modified' timestamp.",
79
+ )
80
+ parser.add_argument(
81
+ "-b",
82
+ dest="recalcBBoxes",
83
+ action="store_false",
84
+ help="Don't recalc glyph bounding boxes: use the values in the original font.",
85
+ )
86
+ parser.add_argument(
87
+ "--optimize-font-speed",
88
+ action="store_true",
89
+ help=(
90
+ "Enable optimizations that prioritize speed over file size. This "
91
+ "mainly affects how glyf table and gvar / VARC tables are compiled."
92
+ ),
93
+ )
74
94
  options = parser.parse_args(args)
75
95
 
76
96
  fontNumber = int(options.y) if options.y is not None else None
77
97
  outFile = options.output
78
98
  lazy = options.lazy
79
99
  flavor = options.flavor
80
- tables = options.table if options.table is not None else ["*"]
100
+ tables = options.table
101
+ recalcBBoxes = options.recalcBBoxes
102
+ recalcTimestamp = options.recalcTimestamp
103
+ optimizeFontSpeed = options.optimize_font_speed
81
104
 
82
105
  fonts = []
83
106
  for f in options.font:
84
107
  try:
85
- font = TTFont(f, fontNumber=fontNumber, lazy=lazy)
108
+ font = TTFont(
109
+ f,
110
+ recalcBBoxes=recalcBBoxes,
111
+ recalcTimestamp=recalcTimestamp,
112
+ fontNumber=fontNumber,
113
+ lazy=lazy,
114
+ )
115
+ if optimizeFontSpeed:
116
+ font.cfg[OPTIMIZE_FONT_SPEED] = optimizeFontSpeed
86
117
  fonts.append(font)
87
118
  except TTLibFileIsCollectionError:
88
119
  collection = TTCollection(f, lazy=lazy)
89
120
  fonts.extend(collection.fonts)
90
121
 
91
- if lazy is False:
92
- for font in fonts:
93
- for table in tables if "*" not in tables else font.keys():
94
- font[table] # Decompiles
122
+ if tables is None:
123
+ if lazy is False:
124
+ tables = ["*"]
125
+ elif optimizeFontSpeed:
126
+ tables = {"glyf", "gvar", "VARC"}.intersection(font.keys())
127
+ else:
128
+ tables = []
129
+ for font in fonts:
130
+ if "GlyphOrder" in tables:
131
+ font.getGlyphOrder()
132
+ for table in tables if "*" not in tables else font.keys():
133
+ font[table] # Decompiles
95
134
 
96
135
  if outFile is not None:
97
136
  if len(fonts) == 1:
@@ -1,9 +1,15 @@
1
1
  import json
2
+ from textwrap import indent
2
3
 
3
4
  from . import DefaultTable
5
+ from fontTools.misc.textTools import tostr
4
6
 
5
7
 
6
8
  class table_D__e_b_g(DefaultTable.DefaultTable):
9
+ def __init__(self, tag=None):
10
+ DefaultTable.DefaultTable.__init__(self, tag)
11
+ self.data = {}
12
+
7
13
  def decompile(self, data, ttFont):
8
14
  self.data = json.loads(data)
9
15
 
@@ -11,7 +17,19 @@ class table_D__e_b_g(DefaultTable.DefaultTable):
11
17
  return json.dumps(self.data).encode("utf-8")
12
18
 
13
19
  def toXML(self, writer, ttFont):
14
- writer.writecdata(json.dumps(self.data, indent=2))
20
+ # make sure json indentation inside CDATA block matches XMLWriter's
21
+ data = json.dumps(self.data, indent=len(writer.indentwhite))
22
+ prefix = tostr(writer.indentwhite) * (writer.indentlevel + 1)
23
+ # but don't indent the first json line so it's adjacent to `<![CDATA[{`
24
+ cdata = indent(data, prefix, lambda ln: ln != "{\n")
25
+
26
+ writer.begintag("json")
27
+ writer.newline()
28
+ writer.writecdata(cdata)
29
+ writer.newline()
30
+ writer.endtag("json")
31
+ writer.newline()
15
32
 
16
33
  def fromXML(self, name, attrs, content, ttFont):
17
- self.data = json.loads(content)
34
+ if name == "json":
35
+ self.data = json.loads("".join(content))
@@ -141,6 +141,17 @@ class table__c_m_a_p(DefaultTable.DefaultTable):
141
141
  result.setdefault(name, set()).add(codepoint)
142
142
  return result
143
143
 
144
+ def buildReversedMin(self):
145
+ result = {}
146
+ for subtable in self.tables:
147
+ if subtable.isUnicode():
148
+ for codepoint, name in subtable.cmap.items():
149
+ if name in result:
150
+ result[name] = min(result[name], codepoint)
151
+ else:
152
+ result[name] = codepoint
153
+ return result
154
+
144
155
  def decompile(self, data, ttFont):
145
156
  tableVersion, numSubTables = struct.unpack(">HH", data[:4])
146
157
  self.tableVersion = int(tableVersion)
@@ -1162,13 +1173,15 @@ class cmap_format_12_or_13(CmapSubtable):
1162
1173
  charCodes = []
1163
1174
  gids = []
1164
1175
  pos = 0
1176
+ groups = array.array("I", data[: self.nGroups * 12])
1177
+ if sys.byteorder != "big":
1178
+ groups.byteswap()
1165
1179
  for i in range(self.nGroups):
1166
- startCharCode, endCharCode, glyphID = struct.unpack(
1167
- ">LLL", data[pos : pos + 12]
1168
- )
1169
- pos += 12
1180
+ startCharCode = groups[i * 3]
1181
+ endCharCode = groups[i * 3 + 1]
1182
+ glyphID = groups[i * 3 + 2]
1170
1183
  lenGroup = 1 + endCharCode - startCharCode
1171
- charCodes.extend(list(range(startCharCode, endCharCode + 1)))
1184
+ charCodes.extend(range(startCharCode, endCharCode + 1))
1172
1185
  gids.extend(self._computeGIDs(glyphID, lenGroup))
1173
1186
  self.data = data = None
1174
1187
  self.cmap = _make_map(self.ttFont, charCodes, gids)
@@ -1299,7 +1312,7 @@ class cmap_format_12(cmap_format_12_or_13):
1299
1312
  cmap_format_12_or_13.__init__(self, format)
1300
1313
 
1301
1314
  def _computeGIDs(self, startingGlyph, numberOfGlyphs):
1302
- return list(range(startingGlyph, startingGlyph + numberOfGlyphs))
1315
+ return range(startingGlyph, startingGlyph + numberOfGlyphs)
1303
1316
 
1304
1317
  def _IsInSameRun(self, glyphID, lastGlyphID, charCode, lastCharCode):
1305
1318
  return (glyphID == 1 + lastGlyphID) and (charCode == 1 + lastCharCode)
@@ -134,6 +134,8 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
134
134
  glyph.expand(self)
135
135
 
136
136
  def compile(self, ttFont):
137
+ optimizeSpeed = ttFont.cfg[ttLib.OPTIMIZE_FONT_SPEED]
138
+
137
139
  self.axisTags = (
138
140
  [axis.axisTag for axis in ttFont["fvar"].axes] if "fvar" in ttFont else []
139
141
  )
@@ -148,7 +150,12 @@ class table__g_l_y_f(DefaultTable.DefaultTable):
148
150
  boundsDone = set()
149
151
  for glyphName in self.glyphOrder:
150
152
  glyph = self.glyphs[glyphName]
151
- glyphData = glyph.compile(self, recalcBBoxes, boundsDone=boundsDone)
153
+ glyphData = glyph.compile(
154
+ self,
155
+ recalcBBoxes,
156
+ boundsDone=boundsDone,
157
+ optimizeSize=not optimizeSpeed,
158
+ )
152
159
  if padding > 1:
153
160
  glyphData = pad(glyphData, size=padding)
154
161
  locations.append(currentLocation)
@@ -714,7 +721,7 @@ class Glyph(object):
714
721
  self.decompileCoordinates(data)
715
722
 
716
723
  def compile(
717
- self, glyfTable, recalcBBoxes=True, *, boundsDone=None, optimizeSize=None
724
+ self, glyfTable, recalcBBoxes=True, *, boundsDone=None, optimizeSize=True
718
725
  ):
719
726
  if hasattr(self, "data"):
720
727
  if recalcBBoxes:
@@ -732,8 +739,6 @@ class Glyph(object):
732
739
  if self.isComposite():
733
740
  data = data + self.compileComponents(glyfTable)
734
741
  else:
735
- if optimizeSize is None:
736
- optimizeSize = getattr(glyfTable, "optimizeSize", True)
737
742
  data = data + self.compileCoordinates(optimizeSize=optimizeSize)
738
743
  return data
739
744
 
@@ -3,6 +3,7 @@ from functools import partial
3
3
  from fontTools.misc import sstruct
4
4
  from fontTools.misc.textTools import safeEval
5
5
  from fontTools.misc.lazyTools import LazyDict
6
+ from fontTools.ttLib import OPTIMIZE_FONT_SPEED
6
7
  from fontTools.ttLib.tables.TupleVariation import TupleVariation
7
8
  from . import DefaultTable
8
9
  import array
@@ -57,6 +58,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
57
58
  self.variations = {}
58
59
 
59
60
  def compile(self, ttFont):
61
+
60
62
  axisTags = [axis.axisTag for axis in ttFont["fvar"].axes]
61
63
  sharedTuples = tv.compileSharedTuples(
62
64
  axisTags, itertools.chain(*self.variations.values())
@@ -91,9 +93,9 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
91
93
  return b"".join(result)
92
94
 
93
95
  def compileGlyphs_(self, ttFont, axisTags, sharedCoordIndices):
96
+ optimizeSpeed = ttFont.cfg[OPTIMIZE_FONT_SPEED]
94
97
  result = []
95
98
  glyf = ttFont["glyf"]
96
- optimizeSize = getattr(self, "optimizeSize", True)
97
99
  for glyphName in ttFont.getGlyphOrder():
98
100
  variations = self.variations.get(glyphName, [])
99
101
  if not variations:
@@ -106,7 +108,7 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
106
108
  pointCountUnused,
107
109
  axisTags,
108
110
  sharedCoordIndices,
109
- optimizeSize=optimizeSize,
111
+ optimizeSize=not optimizeSpeed,
110
112
  )
111
113
  )
112
114
  return result
@@ -10,7 +10,7 @@ from fontTools.ttLib.tables.TupleVariation import TupleVariation
10
10
  from fontTools.misc.roundTools import nearestMultipleShortestRepr, otRound
11
11
  from fontTools.misc.textTools import bytesjoin, tobytes, tostr, pad, safeEval
12
12
  from fontTools.misc.lazyTools import LazyList
13
- from fontTools.ttLib import getSearchRange
13
+ from fontTools.ttLib import OPTIMIZE_FONT_SPEED, getSearchRange
14
14
  from .otBase import (
15
15
  CountReference,
16
16
  FormatSwitchingBaseTable,
@@ -1810,7 +1810,10 @@ class TupleValues:
1810
1810
  return TupleVariation.decompileDeltas_(None, data)[0]
1811
1811
 
1812
1812
  def write(self, writer, font, tableDict, values, repeatIndex=None):
1813
- return bytes(TupleVariation.compileDeltaValues_(values))
1813
+ optimizeSpeed = font.cfg[OPTIMIZE_FONT_SPEED]
1814
+ return bytes(
1815
+ TupleVariation.compileDeltaValues_(values, optimizeSize=not optimizeSpeed)
1816
+ )
1814
1817
 
1815
1818
  def xmlRead(self, attrs, content, font):
1816
1819
  return safeEval(attrs["value"])
@@ -11,6 +11,7 @@ from functools import reduce
11
11
  from math import radians
12
12
  import itertools
13
13
  from collections import defaultdict, namedtuple
14
+ from fontTools.ttLib import OPTIMIZE_FONT_SPEED
14
15
  from fontTools.ttLib.tables.TupleVariation import TupleVariation
15
16
  from fontTools.ttLib.tables.otTraverse import dfs_base_table
16
17
  from fontTools.misc.arrayTools import quantizeRect
@@ -236,6 +237,8 @@ class VarComponent:
236
237
  return data[i:]
237
238
 
238
239
  def compile(self, font):
240
+ optimizeSpeed = font.cfg[OPTIMIZE_FONT_SPEED]
241
+
239
242
  data = []
240
243
 
241
244
  flags = self.flags
@@ -259,7 +262,8 @@ class VarComponent:
259
262
  data.append(_write_uint32var(self.axisIndicesIndex))
260
263
  data.append(
261
264
  TupleVariation.compileDeltaValues_(
262
- [fl2fi(v, 14) for v in self.axisValues]
265
+ [fl2fi(v, 14) for v in self.axisValues],
266
+ optimizeSize=not optimizeSpeed,
263
267
  )
264
268
  )
265
269
  else:
fontTools/ttLib/ttFont.py CHANGED
@@ -593,10 +593,8 @@ class TTFont(object):
593
593
  # temporary cmap and by the real cmap in case we don't find a unicode
594
594
  # cmap.
595
595
  numGlyphs = int(self["maxp"].numGlyphs)
596
- glyphOrder = [None] * numGlyphs
596
+ glyphOrder = ["glyph%.5d" % i for i in range(numGlyphs)]
597
597
  glyphOrder[0] = ".notdef"
598
- for i in range(1, numGlyphs):
599
- glyphOrder[i] = "glyph%.5d" % i
600
598
  # Set the glyph order, so the cmap parser has something
601
599
  # to work with (so we don't get called recursively).
602
600
  self.glyphOrder = glyphOrder
@@ -606,7 +604,7 @@ class TTFont(object):
606
604
  # this naming table will usually not cover all glyphs in the font.
607
605
  # If the font has no Unicode cmap table, reversecmap will be empty.
608
606
  if "cmap" in self:
609
- reversecmap = self["cmap"].buildReversed()
607
+ reversecmap = self["cmap"].buildReversedMin()
610
608
  else:
611
609
  reversecmap = {}
612
610
  useCount = {}
@@ -616,7 +614,7 @@ class TTFont(object):
616
614
  # If a font maps both U+0041 LATIN CAPITAL LETTER A and
617
615
  # U+0391 GREEK CAPITAL LETTER ALPHA to the same glyph,
618
616
  # we prefer naming the glyph as "A".
619
- glyphName = self._makeGlyphName(min(reversecmap[tempName]))
617
+ glyphName = self._makeGlyphName(reversecmap[tempName])
620
618
  numUses = useCount[glyphName] = useCount.get(glyphName, 0) + 1
621
619
  if numUses > 1:
622
620
  glyphName = "%s.alt%d" % (glyphName, numUses - 1)
@@ -104,16 +104,6 @@ class _TTGlyphSetGlyf(_TTGlyphSet):
104
104
  return _TTGlyphGlyf(self, glyphName, recalcBounds=self.recalcBounds)
105
105
 
106
106
 
107
- class _TTGlyphSetGlyf(_TTGlyphSet):
108
- def __init__(self, font, location, recalcBounds=True):
109
- self.glyfTable = font["glyf"]
110
- super().__init__(font, location, self.glyfTable, recalcBounds=recalcBounds)
111
- self.gvarTable = font.get("gvar")
112
-
113
- def __getitem__(self, glyphName):
114
- return _TTGlyphGlyf(self, glyphName, recalcBounds=self.recalcBounds)
115
-
116
-
117
107
  class _TTGlyphSetCFF(_TTGlyphSet):
118
108
  def __init__(self, font, location):
119
109
  tableTag = "CFF2" if "CFF2" in font else "CFF "