fonttools 4.56.0__cp312-cp312-musllinux_1_2_aarch64.whl → 4.57.0__cp312-cp312-musllinux_1_2_aarch64.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 (40) hide show
  1. fontTools/__init__.py +1 -1
  2. fontTools/config/__init__.py +15 -0
  3. fontTools/cu2qu/cu2qu.c +6 -6
  4. fontTools/cu2qu/cu2qu.cpython-312-aarch64-linux-musl.so +0 -0
  5. fontTools/feaLib/ast.py +8 -3
  6. fontTools/feaLib/builder.py +32 -9
  7. fontTools/feaLib/lexer.c +5 -5
  8. fontTools/feaLib/lexer.cpython-312-aarch64-linux-musl.so +0 -0
  9. fontTools/feaLib/parser.py +58 -0
  10. fontTools/misc/bezierTools.c +6 -6
  11. fontTools/misc/bezierTools.cpython-312-aarch64-linux-musl.so +0 -0
  12. fontTools/misc/testTools.py +2 -1
  13. fontTools/otlLib/optimize/gpos.py +7 -1
  14. fontTools/pens/momentsPen.c +5 -5
  15. fontTools/pens/momentsPen.cpython-312-aarch64-linux-musl.so +0 -0
  16. fontTools/qu2cu/qu2cu.c +6 -6
  17. fontTools/qu2cu/qu2cu.cpython-312-aarch64-linux-musl.so +0 -0
  18. fontTools/ttLib/__init__.py +4 -0
  19. fontTools/ttLib/__main__.py +47 -8
  20. fontTools/ttLib/tables/D__e_b_g.py +20 -2
  21. fontTools/ttLib/tables/_c_m_a_p.py +19 -6
  22. fontTools/ttLib/tables/_g_l_y_f.py +9 -4
  23. fontTools/ttLib/tables/_g_v_a_r.py +4 -2
  24. fontTools/ttLib/tables/otConverters.py +5 -2
  25. fontTools/ttLib/tables/otTables.py +5 -1
  26. fontTools/ttLib/ttFont.py +3 -5
  27. fontTools/ttLib/ttGlyphSet.py +0 -10
  28. fontTools/ttx.py +13 -1
  29. fontTools/varLib/__init__.py +92 -89
  30. fontTools/varLib/hvar.py +113 -0
  31. fontTools/varLib/iup.c +6 -6
  32. fontTools/varLib/iup.cpython-312-aarch64-linux-musl.so +0 -0
  33. fontTools/varLib/varStore.py +1 -1
  34. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/METADATA +16 -2
  35. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/RECORD +270 -269
  36. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/WHEEL +1 -1
  37. {fonttools-4.56.0.data → fonttools-4.57.0.data}/data/share/man/man1/ttx.1 +0 -0
  38. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/entry_points.txt +0 -0
  39. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info/licenses}/LICENSE +0 -0
  40. {fonttools-4.56.0.dist-info → fonttools-4.57.0.dist-info}/top_level.txt +0 -0
@@ -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 "
fontTools/ttx.py CHANGED
@@ -101,9 +101,15 @@ Compile options
101
101
  --with-zopfli
102
102
  Use Zopfli instead of Zlib to compress WOFF. The Python
103
103
  extension is available at https://pypi.python.org/pypi/zopfli
104
+ --optimize-font-speed
105
+ Enable optimizations that prioritize speed over file size.
106
+ This mainly affects how glyf t able and gvar / VARC tables are
107
+ compiled. The produced fonts will be larger, but rendering
108
+ performance will be improved with HarfBuzz and other text
109
+ layout engines.
104
110
  """
105
111
 
106
- from fontTools.ttLib import TTFont, TTLibError
112
+ from fontTools.ttLib import OPTIMIZE_FONT_SPEED, TTFont, TTLibError
107
113
  from fontTools.misc.macCreatorType import getMacCreatorAndType
108
114
  from fontTools.unicode import setUnicodeData
109
115
  from fontTools.misc.textTools import Tag, tostr
@@ -141,6 +147,7 @@ class Options(object):
141
147
  recalcTimestamp = None
142
148
  flavor = None
143
149
  useZopfli = False
150
+ optimizeFontSpeed = False
144
151
 
145
152
  def __init__(self, rawOptions, numFiles):
146
153
  self.onlyTables = []
@@ -229,6 +236,8 @@ class Options(object):
229
236
  self.flavor = value
230
237
  elif option == "--with-zopfli":
231
238
  self.useZopfli = True
239
+ elif option == "--optimize-font-speed":
240
+ self.optimizeFontSpeed = True
232
241
  if self.verbose and self.quiet:
233
242
  raise getopt.GetoptError("-q and -v options are mutually exclusive")
234
243
  if self.verbose:
@@ -324,6 +333,8 @@ def ttCompile(input, output, options):
324
333
  recalcBBoxes=options.recalcBBoxes,
325
334
  recalcTimestamp=options.recalcTimestamp,
326
335
  )
336
+ if options.optimizeFontSpeed:
337
+ ttf.cfg[OPTIMIZE_FONT_SPEED] = options.optimizeFontSpeed
327
338
  ttf.importXML(input)
328
339
 
329
340
  if options.recalcTimestamp is None and "head" in ttf and input is not sys.stdin:
@@ -386,6 +397,7 @@ def parseOptions(args):
386
397
  "version",
387
398
  "with-zopfli",
388
399
  "newline=",
400
+ "optimize-font-speed",
389
401
  ],
390
402
  )
391
403
 
@@ -12,13 +12,13 @@ a Glyphs source, eg., using noto-source as an example:
12
12
 
13
13
  .. code-block:: sh
14
14
 
15
- $ fontmake -o ttf-interpolatable -g NotoSansArabic-MM.glyphs
15
+ $ fontmake -o ttf-interpolatable -g NotoSansArabic-MM.glyphs
16
16
 
17
17
  Then you can make a variable-font this way:
18
18
 
19
19
  .. code-block:: sh
20
20
 
21
- $ fonttools varLib master_ufo/NotoSansArabic.designspace
21
+ $ fonttools varLib master_ufo/NotoSansArabic.designspace
22
22
 
23
23
  API *will* change in near future.
24
24
  """
@@ -479,7 +479,15 @@ def _merge_TTHinting(font, masterModel, master_ttfs):
479
479
 
480
480
  _MetricsFields = namedtuple(
481
481
  "_MetricsFields",
482
- ["tableTag", "metricsTag", "sb1", "sb2", "advMapping", "vOrigMapping"],
482
+ [
483
+ "tableTag",
484
+ "metricsTag",
485
+ "sb1",
486
+ "sb2",
487
+ "advMapping",
488
+ "vOrigMapping",
489
+ "phantomIndex",
490
+ ],
483
491
  )
484
492
 
485
493
  HVAR_FIELDS = _MetricsFields(
@@ -489,6 +497,7 @@ HVAR_FIELDS = _MetricsFields(
489
497
  sb2="RsbMap",
490
498
  advMapping="AdvWidthMap",
491
499
  vOrigMapping=None,
500
+ phantomIndex=0,
492
501
  )
493
502
 
494
503
  VVAR_FIELDS = _MetricsFields(
@@ -498,109 +507,43 @@ VVAR_FIELDS = _MetricsFields(
498
507
  sb2="BsbMap",
499
508
  advMapping="AdvHeightMap",
500
509
  vOrigMapping="VOrgMap",
510
+ phantomIndex=1,
501
511
  )
502
512
 
503
513
 
504
514
  def _add_HVAR(font, masterModel, master_ttfs, axisTags):
505
- _add_VHVAR(font, masterModel, master_ttfs, axisTags, HVAR_FIELDS)
515
+ getAdvanceMetrics = partial(
516
+ _get_advance_metrics, font, masterModel, master_ttfs, axisTags, HVAR_FIELDS
517
+ )
518
+ _add_VHVAR(font, axisTags, HVAR_FIELDS, getAdvanceMetrics)
506
519
 
507
520
 
508
521
  def _add_VVAR(font, masterModel, master_ttfs, axisTags):
509
- _add_VHVAR(font, masterModel, master_ttfs, axisTags, VVAR_FIELDS)
522
+ getAdvanceMetrics = partial(
523
+ _get_advance_metrics, font, masterModel, master_ttfs, axisTags, VVAR_FIELDS
524
+ )
525
+ _add_VHVAR(font, axisTags, VVAR_FIELDS, getAdvanceMetrics)
510
526
 
511
527
 
512
- def _add_VHVAR(font, masterModel, master_ttfs, axisTags, tableFields):
528
+ def _add_VHVAR(font, axisTags, tableFields, getAdvanceMetrics):
513
529
  tableTag = tableFields.tableTag
514
530
  assert tableTag not in font
531
+ glyphOrder = font.getGlyphOrder()
515
532
  log.info("Generating " + tableTag)
516
533
  VHVAR = newTable(tableTag)
517
534
  tableClass = getattr(ot, tableTag)
518
535
  vhvar = VHVAR.table = tableClass()
519
536
  vhvar.Version = 0x00010000
520
537
 
521
- glyphOrder = font.getGlyphOrder()
522
-
523
- # Build list of source font advance widths for each glyph
524
- metricsTag = tableFields.metricsTag
525
- advMetricses = [m[metricsTag].metrics for m in master_ttfs]
526
-
527
- # Build list of source font vertical origin coords for each glyph
528
- if tableTag == "VVAR" and "VORG" in master_ttfs[0]:
529
- vOrigMetricses = [m["VORG"].VOriginRecords for m in master_ttfs]
530
- defaultYOrigs = [m["VORG"].defaultVertOriginY for m in master_ttfs]
531
- vOrigMetricses = list(zip(vOrigMetricses, defaultYOrigs))
532
- else:
533
- vOrigMetricses = None
534
-
535
- metricsStore, advanceMapping, vOrigMapping = _get_advance_metrics(
536
- font,
537
- masterModel,
538
- master_ttfs,
539
- axisTags,
540
- glyphOrder,
541
- advMetricses,
542
- vOrigMetricses,
543
- )
538
+ vhAdvanceDeltasAndSupports, vOrigDeltasAndSupports = getAdvanceMetrics()
544
539
 
545
- vhvar.VarStore = metricsStore
546
- if advanceMapping is None:
547
- setattr(vhvar, tableFields.advMapping, None)
540
+ if vOrigDeltasAndSupports:
541
+ singleModel = False
548
542
  else:
549
- setattr(vhvar, tableFields.advMapping, advanceMapping)
550
- if vOrigMapping is not None:
551
- setattr(vhvar, tableFields.vOrigMapping, vOrigMapping)
552
- setattr(vhvar, tableFields.sb1, None)
553
- setattr(vhvar, tableFields.sb2, None)
554
-
555
- font[tableTag] = VHVAR
556
- return
557
-
558
-
559
- def _get_advance_metrics(
560
- font,
561
- masterModel,
562
- master_ttfs,
563
- axisTags,
564
- glyphOrder,
565
- advMetricses,
566
- vOrigMetricses=None,
567
- ):
568
- vhAdvanceDeltasAndSupports = {}
569
- vOrigDeltasAndSupports = {}
570
- # HACK: we treat width 65535 as a sentinel value to signal that a glyph
571
- # from a non-default master should not participate in computing {H,V}VAR,
572
- # as if it were missing. Allows to variate other glyph-related data independently
573
- # from glyph metrics
574
- sparse_advance = 0xFFFF
575
- for glyph in glyphOrder:
576
- vhAdvances = [
577
- (
578
- metrics[glyph][0]
579
- if glyph in metrics and metrics[glyph][0] != sparse_advance
580
- else None
581
- )
582
- for metrics in advMetricses
583
- ]
584
- vhAdvanceDeltasAndSupports[glyph] = masterModel.getDeltasAndSupports(
585
- vhAdvances, round=round
543
+ singleModel = models.allEqual(
544
+ id(v[1]) for v in vhAdvanceDeltasAndSupports.values()
586
545
  )
587
546
 
588
- singleModel = models.allEqual(id(v[1]) for v in vhAdvanceDeltasAndSupports.values())
589
-
590
- if vOrigMetricses:
591
- singleModel = False
592
- for glyph in glyphOrder:
593
- # We need to supply a vOrigs tuple with non-None default values
594
- # for each glyph. vOrigMetricses contains values only for those
595
- # glyphs which have a non-default vOrig.
596
- vOrigs = [
597
- metrics[glyph] if glyph in metrics else defaultVOrig
598
- for metrics, defaultVOrig in vOrigMetricses
599
- ]
600
- vOrigDeltasAndSupports[glyph] = masterModel.getDeltasAndSupports(
601
- vOrigs, round=round
602
- )
603
-
604
547
  directStore = None
605
548
  if singleModel:
606
549
  # Build direct mapping
@@ -621,7 +564,7 @@ def _get_advance_metrics(
621
564
  storeBuilder.setSupports(supports)
622
565
  advMapping[glyphName] = storeBuilder.storeDeltas(deltas, round=noRound)
623
566
 
624
- if vOrigMetricses:
567
+ if vOrigDeltasAndSupports:
625
568
  vOrigMap = {}
626
569
  for glyphName in glyphOrder:
627
570
  deltas, supports = vOrigDeltasAndSupports[glyphName]
@@ -633,7 +576,7 @@ def _get_advance_metrics(
633
576
  advMapping = [mapping2[advMapping[g]] for g in glyphOrder]
634
577
  advanceMapping = builder.buildVarIdxMap(advMapping, glyphOrder)
635
578
 
636
- if vOrigMetricses:
579
+ if vOrigDeltasAndSupports:
637
580
  vOrigMap = [mapping2[vOrigMap[g]] for g in glyphOrder]
638
581
 
639
582
  useDirect = False
@@ -657,10 +600,70 @@ def _get_advance_metrics(
657
600
  advanceMapping = None
658
601
  else:
659
602
  metricsStore = indirectStore
660
- if vOrigMetricses:
603
+ if vOrigDeltasAndSupports:
661
604
  vOrigMapping = builder.buildVarIdxMap(vOrigMap, glyphOrder)
662
605
 
663
- return metricsStore, advanceMapping, vOrigMapping
606
+ vhvar.VarStore = metricsStore
607
+ setattr(vhvar, tableFields.advMapping, advanceMapping)
608
+ if vOrigMapping is not None:
609
+ setattr(vhvar, tableFields.vOrigMapping, vOrigMapping)
610
+ setattr(vhvar, tableFields.sb1, None)
611
+ setattr(vhvar, tableFields.sb2, None)
612
+
613
+ font[tableTag] = VHVAR
614
+ return
615
+
616
+
617
+ def _get_advance_metrics(font, masterModel, master_ttfs, axisTags, tableFields):
618
+ tableTag = tableFields.tableTag
619
+ glyphOrder = font.getGlyphOrder()
620
+
621
+ # Build list of source font advance widths for each glyph
622
+ metricsTag = tableFields.metricsTag
623
+ advMetricses = [m[metricsTag].metrics for m in master_ttfs]
624
+
625
+ # Build list of source font vertical origin coords for each glyph
626
+ if tableTag == "VVAR" and "VORG" in master_ttfs[0]:
627
+ vOrigMetricses = [m["VORG"].VOriginRecords for m in master_ttfs]
628
+ defaultYOrigs = [m["VORG"].defaultVertOriginY for m in master_ttfs]
629
+ vOrigMetricses = list(zip(vOrigMetricses, defaultYOrigs))
630
+ else:
631
+ vOrigMetricses = None
632
+
633
+ vhAdvanceDeltasAndSupports = {}
634
+ vOrigDeltasAndSupports = {}
635
+ # HACK: we treat width 65535 as a sentinel value to signal that a glyph
636
+ # from a non-default master should not participate in computing {H,V}VAR,
637
+ # as if it were missing. Allows to variate other glyph-related data independently
638
+ # from glyph metrics
639
+ sparse_advance = 0xFFFF
640
+ for glyph in glyphOrder:
641
+ vhAdvances = [
642
+ (
643
+ metrics[glyph][0]
644
+ if glyph in metrics and metrics[glyph][0] != sparse_advance
645
+ else None
646
+ )
647
+ for metrics in advMetricses
648
+ ]
649
+ vhAdvanceDeltasAndSupports[glyph] = masterModel.getDeltasAndSupports(
650
+ vhAdvances, round=round
651
+ )
652
+
653
+ if vOrigMetricses:
654
+ for glyph in glyphOrder:
655
+ # We need to supply a vOrigs tuple with non-None default values
656
+ # for each glyph. vOrigMetricses contains values only for those
657
+ # glyphs which have a non-default vOrig.
658
+ vOrigs = [
659
+ metrics[glyph] if glyph in metrics else defaultVOrig
660
+ for metrics, defaultVOrig in vOrigMetricses
661
+ ]
662
+ vOrigDeltasAndSupports[glyph] = masterModel.getDeltasAndSupports(
663
+ vOrigs, round=round
664
+ )
665
+
666
+ return vhAdvanceDeltasAndSupports, vOrigDeltasAndSupports
664
667
 
665
668
 
666
669
  def _add_MVAR(font, masterModel, master_ttfs, axisTags):
@@ -0,0 +1,113 @@
1
+ from fontTools.misc.roundTools import noRound
2
+ from fontTools.ttLib import TTFont, newTable
3
+ from fontTools.ttLib.tables import otTables as ot
4
+ from fontTools.ttLib.tables.otBase import OTTableWriter
5
+ from fontTools.varLib import HVAR_FIELDS, VVAR_FIELDS, _add_VHVAR
6
+ from fontTools.varLib import builder, models, varStore
7
+ from fontTools.misc.fixedTools import fixedToFloat as fi2fl
8
+ from fontTools.misc.cliTools import makeOutputFileName
9
+ from functools import partial
10
+ import logging
11
+
12
+ log = logging.getLogger("fontTools.varLib.avar")
13
+
14
+
15
+ def _get_advance_metrics(font, axisTags, tableFields):
16
+ # There's two ways we can go from here:
17
+ # 1. For each glyph, at each master peak, compute the value of the
18
+ # advance width at that peak. Then pass these all to a VariationModel
19
+ # builder to compute back the deltas.
20
+ # 2. For each master peak, pull out the deltas of the advance width directly,
21
+ # and feed these to the VarStoreBuilder, forgoing the remoding step.
22
+ # We'll go with the second option, as it's simpler, faster, and more direct.
23
+ gvar = font["gvar"]
24
+ vhAdvanceDeltasAndSupports = {}
25
+ glyphOrder = font.getGlyphOrder()
26
+ phantomIndex = tableFields.phantomIndex
27
+ for glyphName in glyphOrder:
28
+ supports = []
29
+ deltas = []
30
+ variations = gvar.variations.get(glyphName, [])
31
+
32
+ for tv in variations:
33
+ supports.append(tv.axes)
34
+ phantoms = tv.coordinates[-4:]
35
+ phantoms = phantoms[phantomIndex * 2 : phantomIndex * 2 + 2]
36
+ assert len(phantoms) == 2
37
+ phantoms[0] = phantoms[0][phantomIndex] if phantoms[0] is not None else 0
38
+ phantoms[1] = phantoms[1][phantomIndex] if phantoms[1] is not None else 0
39
+ deltas.append(phantoms[1] - phantoms[0])
40
+
41
+ vhAdvanceDeltasAndSupports[glyphName] = (deltas, supports)
42
+
43
+ vOrigDeltasAndSupports = None # TODO
44
+
45
+ return vhAdvanceDeltasAndSupports, vOrigDeltasAndSupports
46
+
47
+
48
+ def add_HVAR(font):
49
+ if "HVAR" in font:
50
+ del font["HVAR"]
51
+ axisTags = [axis.axisTag for axis in font["fvar"].axes]
52
+ getAdvanceMetrics = partial(_get_advance_metrics, font, axisTags, HVAR_FIELDS)
53
+ _add_VHVAR(font, axisTags, HVAR_FIELDS, getAdvanceMetrics)
54
+
55
+
56
+ def add_VVAR(font):
57
+ if "VVAR" in font:
58
+ del font["VVAR"]
59
+ getAdvanceMetrics = partial(_get_advance_metrics, font, axisTags, HVAR_FIELDS)
60
+ axisTags = [axis.axisTag for axis in font["fvar"].axes]
61
+ _add_VHVAR(font, axisTags, VVAR_FIELDS, getAdvanceMetrics)
62
+
63
+
64
+ def main(args=None):
65
+ """Add `HVAR` table to variable font."""
66
+
67
+ if args is None:
68
+ import sys
69
+
70
+ args = sys.argv[1:]
71
+
72
+ from fontTools import configLogger
73
+ from fontTools.designspaceLib import DesignSpaceDocument
74
+ import argparse
75
+
76
+ parser = argparse.ArgumentParser(
77
+ "fonttools varLib.hvar",
78
+ description="Add `HVAR` table from to variable font.",
79
+ )
80
+ parser.add_argument("font", metavar="varfont.ttf", help="Variable-font file.")
81
+ parser.add_argument(
82
+ "-o",
83
+ "--output-file",
84
+ type=str,
85
+ help="Output font file name.",
86
+ )
87
+
88
+ options = parser.parse_args(args)
89
+
90
+ configLogger(level="WARNING")
91
+
92
+ font = TTFont(options.font)
93
+ if not "fvar" in font:
94
+ log.error("Not a variable font.")
95
+ return 1
96
+
97
+ add_HVAR(font)
98
+ if "vmtx" in font:
99
+ add_VVAR(font)
100
+
101
+ if options.output_file is None:
102
+ outfile = makeOutputFileName(options.font, overWrite=True, suffix=".hvar")
103
+ else:
104
+ outfile = options.output_file
105
+ if outfile:
106
+ log.info("Saving %s", outfile)
107
+ font.save(outfile)
108
+
109
+
110
+ if __name__ == "__main__":
111
+ import sys
112
+
113
+ sys.exit(main())
fontTools/varLib/iup.c CHANGED
@@ -1,4 +1,4 @@
1
- /* Generated by Cython 3.0.11 */
1
+ /* Generated by Cython 3.0.12 */
2
2
 
3
3
  /* BEGIN: Cython Metadata
4
4
  {
@@ -36,10 +36,10 @@ END: Cython Metadata */
36
36
  #else
37
37
  #define __PYX_EXTRA_ABI_MODULE_NAME ""
38
38
  #endif
39
- #define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME
39
+ #define CYTHON_ABI "3_0_12" __PYX_EXTRA_ABI_MODULE_NAME
40
40
  #define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
41
41
  #define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
42
- #define CYTHON_HEX_VERSION 0x03000BF0
42
+ #define CYTHON_HEX_VERSION 0x03000CF0
43
43
  #define CYTHON_FUTURE_DIVISION 1
44
44
  #include <stddef.h>
45
45
  #ifndef offsetof
@@ -1972,7 +1972,7 @@ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args,
1972
1972
  #if !CYTHON_VECTORCALL
1973
1973
  #if PY_VERSION_HEX >= 0x03080000
1974
1974
  #include "frameobject.h"
1975
- #if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API
1975
+ #if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API && !defined(PYPY_VERSION)
1976
1976
  #ifndef Py_BUILD_CORE
1977
1977
  #define Py_BUILD_CORE 1
1978
1978
  #endif
@@ -16524,7 +16524,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
16524
16524
  #include "compile.h"
16525
16525
  #include "frameobject.h"
16526
16526
  #include "traceback.h"
16527
- #if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API
16527
+ #if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API && !defined(PYPY_VERSION)
16528
16528
  #ifndef Py_BUILD_CORE
16529
16529
  #define Py_BUILD_CORE 1
16530
16530
  #endif
@@ -17714,7 +17714,7 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name
17714
17714
 
17715
17715
  /* CoroutineBase */
17716
17716
  #include <frameobject.h>
17717
- #if PY_VERSION_HEX >= 0x030b00a6
17717
+ #if PY_VERSION_HEX >= 0x030b00a6 && !defined(PYPY_VERSION)
17718
17718
  #ifndef Py_BUILD_CORE
17719
17719
  #define Py_BUILD_CORE 1
17720
17720
  #endif