fonttools 4.59.0__cp313-cp313-musllinux_1_2_aarch64.whl → 4.59.2__cp313-cp313-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.
- fontTools/__init__.py +1 -1
- fontTools/cffLib/CFF2ToCFF.py +40 -10
- fontTools/cffLib/transforms.py +11 -6
- fontTools/cu2qu/cu2qu.c +751 -643
- fontTools/cu2qu/cu2qu.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/cu2qu/cu2qu.py +17 -2
- fontTools/feaLib/builder.py +15 -4
- fontTools/feaLib/lexer.c +21 -6
- fontTools/feaLib/lexer.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/feaLib/parser.py +11 -1
- fontTools/feaLib/variableScalar.py +6 -1
- fontTools/misc/bezierTools.c +24 -9
- fontTools/misc/bezierTools.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/misc/psCharStrings.py +17 -2
- fontTools/misc/textTools.py +4 -2
- fontTools/pens/momentsPen.c +11 -4
- fontTools/pens/momentsPen.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/qu2cu/qu2cu.c +23 -8
- fontTools/qu2cu/qu2cu.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/subset/__init__.py +1 -0
- fontTools/ttLib/tables/_a_v_a_r.py +4 -2
- fontTools/ttLib/tables/_g_v_a_r.py +6 -3
- fontTools/ttLib/tables/_h_m_t_x.py +7 -3
- fontTools/ttLib/tables/_n_a_m_e.py +11 -6
- fontTools/varLib/__init__.py +80 -1
- fontTools/varLib/featureVars.py +8 -0
- fontTools/varLib/instancer/__init__.py +120 -22
- fontTools/varLib/iup.c +23 -8
- fontTools/varLib/iup.cpython-313-aarch64-linux-musl.so +0 -0
- fontTools/varLib/mutator.py +11 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/METADATA +38 -10
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/RECORD +38 -38
- {fonttools-4.59.0.data → fonttools-4.59.2.data}/data/share/man/man1/ttx.1 +0 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/WHEEL +0 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/entry_points.txt +0 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/licenses/LICENSE +0 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/licenses/LICENSE.external +0 -0
- {fonttools-4.59.0.dist-info → fonttools-4.59.2.dist-info}/top_level.txt +0 -0
|
@@ -64,7 +64,6 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|
|
64
64
|
self.variations = {}
|
|
65
65
|
|
|
66
66
|
def compile(self, ttFont):
|
|
67
|
-
|
|
68
67
|
axisTags = [axis.axisTag for axis in ttFont["fvar"].axes]
|
|
69
68
|
sharedTuples = tv.compileSharedTuples(
|
|
70
69
|
axisTags, itertools.chain(*self.variations.values())
|
|
@@ -141,8 +140,12 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
|
|
141
140
|
self,
|
|
142
141
|
)
|
|
143
142
|
|
|
144
|
-
assert len(glyphs) == self.glyphCount
|
|
145
|
-
assert len(axisTags) == self.axisCount
|
|
143
|
+
assert len(glyphs) == self.glyphCount, (len(glyphs), self.glyphCount)
|
|
144
|
+
assert len(axisTags) == self.axisCount, (
|
|
145
|
+
len(axisTags),
|
|
146
|
+
self.axisCount,
|
|
147
|
+
axisTags,
|
|
148
|
+
)
|
|
146
149
|
sharedCoords = tv.decompileSharedTuples(
|
|
147
150
|
axisTags, self.sharedTupleCount, data, self.offsetToSharedTuples
|
|
148
151
|
)
|
|
@@ -40,15 +40,19 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
|
|
40
40
|
% (self.headerTag, self.numberOfMetricsName)
|
|
41
41
|
)
|
|
42
42
|
numberOfMetrics = numGlyphs
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
numberOfSideBearings = numGlyphs - numberOfMetrics
|
|
44
|
+
tableSize = 4 * numberOfMetrics + 2 * numberOfSideBearings
|
|
45
|
+
if len(data) < tableSize:
|
|
46
|
+
raise ttLib.TTLibError(
|
|
47
|
+
f"not enough '{self.tableTag}' table data: "
|
|
48
|
+
f"expected {tableSize} bytes, got {len(data)}"
|
|
49
|
+
)
|
|
45
50
|
# Note: advanceWidth is unsigned, but some font editors might
|
|
46
51
|
# read/write as signed. We can't be sure whether it was a mistake
|
|
47
52
|
# or not, so we read as unsigned but also issue a warning...
|
|
48
53
|
metricsFmt = ">" + self.longMetricFormat * numberOfMetrics
|
|
49
54
|
metrics = struct.unpack(metricsFmt, data[: 4 * numberOfMetrics])
|
|
50
55
|
data = data[4 * numberOfMetrics :]
|
|
51
|
-
numberOfSideBearings = numGlyphs - numberOfMetrics
|
|
52
56
|
sideBearings = array.array("h", data[: 2 * numberOfSideBearings])
|
|
53
57
|
data = data[2 * numberOfSideBearings :]
|
|
54
58
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
2
4
|
from fontTools.misc import sstruct
|
|
3
5
|
from fontTools.misc.textTools import (
|
|
4
6
|
bytechr,
|
|
@@ -63,7 +65,7 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
|
|
|
63
65
|
)
|
|
64
66
|
stringData = data[stringOffset:]
|
|
65
67
|
data = data[6:]
|
|
66
|
-
self.names = []
|
|
68
|
+
self.names: list[NameRecord] = []
|
|
67
69
|
for i in range(n):
|
|
68
70
|
if len(data) < 12:
|
|
69
71
|
log.error("skipping malformed name record #%d", i)
|
|
@@ -112,7 +114,9 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
|
|
|
112
114
|
self.names.append(name)
|
|
113
115
|
name.fromXML(name, attrs, content, ttFont)
|
|
114
116
|
|
|
115
|
-
def getName(
|
|
117
|
+
def getName(
|
|
118
|
+
self, nameID: int, platformID: int, platEncID: int, langID: int | None = None
|
|
119
|
+
) -> "NameRecord | None":
|
|
116
120
|
for namerecord in self.names:
|
|
117
121
|
if (
|
|
118
122
|
namerecord.nameID == nameID
|
|
@@ -123,8 +127,9 @@ class table__n_a_m_e(DefaultTable.DefaultTable):
|
|
|
123
127
|
return namerecord
|
|
124
128
|
return None # not found
|
|
125
129
|
|
|
126
|
-
def getDebugName(self, nameID):
|
|
127
|
-
englishName
|
|
130
|
+
def getDebugName(self, nameID: int) -> str | None:
|
|
131
|
+
englishName: str | None = None
|
|
132
|
+
someName: str | None = None
|
|
128
133
|
for name in self.names:
|
|
129
134
|
if name.nameID != nameID:
|
|
130
135
|
continue
|
|
@@ -513,7 +518,7 @@ class NameRecord(object):
|
|
|
513
518
|
self.platformID == 3 and self.platEncID in [0, 1, 10]
|
|
514
519
|
)
|
|
515
520
|
|
|
516
|
-
def toUnicode(self, errors="strict"):
|
|
521
|
+
def toUnicode(self, errors: str = "strict") -> str:
|
|
517
522
|
"""
|
|
518
523
|
If self.string is a Unicode string, return it; otherwise try decoding the
|
|
519
524
|
bytes in self.string to a Unicode string using the encoding of this
|
|
@@ -533,7 +538,7 @@ class NameRecord(object):
|
|
|
533
538
|
and saving it back will not change them.
|
|
534
539
|
"""
|
|
535
540
|
|
|
536
|
-
def isascii(b):
|
|
541
|
+
def isascii(b: int) -> bool:
|
|
537
542
|
return (b >= 0x20 and b <= 0x7E) or b in [0x09, 0x0A, 0x0D]
|
|
538
543
|
|
|
539
544
|
encoding = self.getEncoding()
|
fontTools/varLib/__init__.py
CHANGED
|
@@ -30,7 +30,11 @@ from fontTools.misc.fixedTools import floatToFixed as fl2fi
|
|
|
30
30
|
from fontTools.misc.textTools import Tag, tostr
|
|
31
31
|
from fontTools.ttLib import TTFont, newTable
|
|
32
32
|
from fontTools.ttLib.tables._f_v_a_r import Axis, NamedInstance
|
|
33
|
-
from fontTools.ttLib.tables._g_l_y_f import
|
|
33
|
+
from fontTools.ttLib.tables._g_l_y_f import (
|
|
34
|
+
GlyphCoordinates,
|
|
35
|
+
dropImpliedOnCurvePoints,
|
|
36
|
+
USE_MY_METRICS,
|
|
37
|
+
)
|
|
34
38
|
from fontTools.ttLib.tables.ttProgram import Program
|
|
35
39
|
from fontTools.ttLib.tables.TupleVariation import TupleVariation
|
|
36
40
|
from fontTools.ttLib.tables import otTables as ot
|
|
@@ -489,6 +493,77 @@ def _merge_TTHinting(font, masterModel, master_ttfs):
|
|
|
489
493
|
cvar.variations = variations
|
|
490
494
|
|
|
491
495
|
|
|
496
|
+
def _has_inconsistent_use_my_metrics_flag(
|
|
497
|
+
master_glyf, glyph_name, flagged_components, expected_num_components
|
|
498
|
+
) -> bool:
|
|
499
|
+
master_glyph = master_glyf.get(glyph_name)
|
|
500
|
+
# 'sparse' glyph master doesn't contribute. Besides when components don't match
|
|
501
|
+
# the VF build is going to fail anyway, so be lenient here.
|
|
502
|
+
if (
|
|
503
|
+
master_glyph is not None
|
|
504
|
+
and master_glyph.isComposite()
|
|
505
|
+
and len(master_glyph.components) == expected_num_components
|
|
506
|
+
):
|
|
507
|
+
for i, base_glyph in flagged_components:
|
|
508
|
+
comp = master_glyph.components[i]
|
|
509
|
+
if comp.glyphName != base_glyph:
|
|
510
|
+
break
|
|
511
|
+
if not (comp.flags & USE_MY_METRICS):
|
|
512
|
+
return True
|
|
513
|
+
return False
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
def _unset_inconsistent_use_my_metrics_flags(vf, master_fonts):
|
|
517
|
+
"""Clear USE_MY_METRICS on composite components if inconsistent across masters.
|
|
518
|
+
|
|
519
|
+
If a composite glyph's component has USE_MY_METRICS set differently among
|
|
520
|
+
the masters, the flag is removed from the variable font's glyf table so that
|
|
521
|
+
advance widths are not determined by that single component's phantom points.
|
|
522
|
+
"""
|
|
523
|
+
glyf = vf["glyf"]
|
|
524
|
+
master_glyfs = [m["glyf"] for m in master_fonts if "glyf" in m]
|
|
525
|
+
if not master_glyfs:
|
|
526
|
+
# Should not happen: at least the base master (as copied into vf) has glyf
|
|
527
|
+
return
|
|
528
|
+
|
|
529
|
+
for glyph_name in glyf.keys():
|
|
530
|
+
glyph = glyf[glyph_name]
|
|
531
|
+
if not glyph.isComposite():
|
|
532
|
+
continue
|
|
533
|
+
|
|
534
|
+
# collect indices of component(s) that carry the USE_MY_METRICS flag.
|
|
535
|
+
# This is supposed to be 1 component per composite, but you never know.
|
|
536
|
+
flagged_components = [
|
|
537
|
+
(i, comp.glyphName)
|
|
538
|
+
for i, comp in enumerate(glyph.components)
|
|
539
|
+
if (comp.flags & USE_MY_METRICS)
|
|
540
|
+
]
|
|
541
|
+
if not flagged_components:
|
|
542
|
+
# Nothing to fix
|
|
543
|
+
continue
|
|
544
|
+
|
|
545
|
+
# Verify that for all master glyf tables that contribute this glyph, the
|
|
546
|
+
# corresponding component (same glyphName and index) also carries USE_MY_METRICS
|
|
547
|
+
# and unset the flag if not.
|
|
548
|
+
expected_num_components = len(glyph.components)
|
|
549
|
+
if any(
|
|
550
|
+
_has_inconsistent_use_my_metrics_flag(
|
|
551
|
+
master_glyf, glyph_name, flagged_components, expected_num_components
|
|
552
|
+
)
|
|
553
|
+
for master_glyf in master_glyfs
|
|
554
|
+
):
|
|
555
|
+
comp_names = [name for _, name in flagged_components]
|
|
556
|
+
log.info(
|
|
557
|
+
"Composite glyph '%s' has inconsistent USE_MY_METRICS flags across "
|
|
558
|
+
"masters; clearing the flag on component%s %s",
|
|
559
|
+
glyph_name,
|
|
560
|
+
"s" if len(comp_names) > 1 else "",
|
|
561
|
+
comp_names if len(comp_names) > 1 else comp_names[0],
|
|
562
|
+
)
|
|
563
|
+
for i, _ in flagged_components:
|
|
564
|
+
glyph.components[i].flags &= ~USE_MY_METRICS
|
|
565
|
+
|
|
566
|
+
|
|
492
567
|
_MetricsFields = namedtuple(
|
|
493
568
|
"_MetricsFields",
|
|
494
569
|
[
|
|
@@ -1205,6 +1280,10 @@ def build(
|
|
|
1205
1280
|
if "DSIG" in vf:
|
|
1206
1281
|
del vf["DSIG"]
|
|
1207
1282
|
|
|
1283
|
+
# Clear USE_MY_METRICS composite flags if set inconsistently across masters.
|
|
1284
|
+
if "glyf" in vf:
|
|
1285
|
+
_unset_inconsistent_use_my_metrics_flags(vf, master_fonts)
|
|
1286
|
+
|
|
1208
1287
|
# TODO append masters as named-instances as well; needs .designspace change.
|
|
1209
1288
|
fvar = _add_fvar(vf, ds.axes, ds.instances)
|
|
1210
1289
|
if "STAT" not in exclude:
|
fontTools/varLib/featureVars.py
CHANGED
|
@@ -95,6 +95,14 @@ def addFeatureVariations(font, conditionalSubstitutions, featureTag="rvrn"):
|
|
|
95
95
|
|
|
96
96
|
addFeatureVariationsRaw(font, font["GSUB"].table, conditionsAndLookups, featureTags)
|
|
97
97
|
|
|
98
|
+
# Update OS/2.usMaxContext in case the font didn't have features before, but
|
|
99
|
+
# does now, if the OS/2 table exists. The table may be required, but
|
|
100
|
+
# fontTools needs to be able to deal with non-standard fonts. Since feature
|
|
101
|
+
# variations are always 1:1 mappings, we can set the value to at least 1
|
|
102
|
+
# instead of recomputing it with `otlLib.maxContextCalc.maxCtxFont()`.
|
|
103
|
+
if (os2 := font.get("OS/2")) is not None:
|
|
104
|
+
os2.usMaxContext = max(1, os2.usMaxContext)
|
|
105
|
+
|
|
98
106
|
|
|
99
107
|
def _existingVariableFeatures(table):
|
|
100
108
|
existingFeatureVarsTags = set()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Partially instantiate a variable font.
|
|
2
2
|
|
|
3
3
|
The module exports an `instantiateVariableFont` function and CLI that allow to
|
|
4
4
|
create full instances (i.e. static fonts) from variable fonts, as well as "partial"
|
|
@@ -36,7 +36,7 @@ If the input location specifies all the axes, the resulting instance is no longe
|
|
|
36
36
|
'variable' (same as using fontools varLib.mutator):
|
|
37
37
|
.. code-block:: pycon
|
|
38
38
|
|
|
39
|
-
>>>
|
|
39
|
+
>>>
|
|
40
40
|
>> instance = instancer.instantiateVariableFont(
|
|
41
41
|
... varfont, {"wght": 700, "wdth": 67.5}
|
|
42
42
|
... )
|
|
@@ -56,8 +56,10 @@ From the console script, this is equivalent to passing `wght=drop` as input.
|
|
|
56
56
|
|
|
57
57
|
This module is similar to fontTools.varLib.mutator, which it's intended to supersede.
|
|
58
58
|
Note that, unlike varLib.mutator, when an axis is not mentioned in the input
|
|
59
|
-
location, the varLib.instancer will keep the axis and the corresponding
|
|
60
|
-
whereas mutator implicitly drops the axis at its default coordinate.
|
|
59
|
+
location, by default the varLib.instancer will keep the axis and the corresponding
|
|
60
|
+
deltas, whereas mutator implicitly drops the axis at its default coordinate.
|
|
61
|
+
To obtain the same behavior as mutator, pass the `static=True` parameter or
|
|
62
|
+
the `--static` CLI option.
|
|
61
63
|
|
|
62
64
|
The module supports all the following "levels" of instancing, which can of
|
|
63
65
|
course be combined:
|
|
@@ -72,7 +74,7 @@ L1
|
|
|
72
74
|
L2
|
|
73
75
|
dropping one or more axes while pinning them at non-default locations;
|
|
74
76
|
.. code-block:: pycon
|
|
75
|
-
|
|
77
|
+
|
|
76
78
|
>>>
|
|
77
79
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": 700})
|
|
78
80
|
|
|
@@ -81,22 +83,18 @@ L3
|
|
|
81
83
|
a new minimum or maximum, potentially -- though not necessarily -- dropping
|
|
82
84
|
entire regions of variations that fall completely outside this new range.
|
|
83
85
|
.. code-block:: pycon
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
>>>
|
|
86
88
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300)})
|
|
87
89
|
|
|
88
90
|
L4
|
|
89
91
|
moving the default location of an axis, by specifying (min,defalt,max) values:
|
|
90
92
|
.. code-block:: pycon
|
|
91
|
-
|
|
93
|
+
|
|
92
94
|
>>>
|
|
93
95
|
>> font = instancer.instantiateVariableFont(varfont, {"wght": (100, 300, 700)})
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
are supported, but support for CFF2 variable fonts will be added soon.
|
|
97
|
-
|
|
98
|
-
The discussion and implementation of these features are tracked at
|
|
99
|
-
https://github.com/fonttools/fonttools/issues/1537
|
|
97
|
+
Both TrueType-flavored (glyf+gvar) variable and CFF2 variable fonts are supported.
|
|
100
98
|
"""
|
|
101
99
|
|
|
102
100
|
from fontTools.misc.fixedTools import (
|
|
@@ -120,6 +118,7 @@ from fontTools.cffLib.specializer import (
|
|
|
120
118
|
specializeCommands,
|
|
121
119
|
generalizeCommands,
|
|
122
120
|
)
|
|
121
|
+
from fontTools.cffLib.CFF2ToCFF import convertCFF2ToCFF
|
|
123
122
|
from fontTools.varLib import builder
|
|
124
123
|
from fontTools.varLib.mvar import MVAR_ENTRIES
|
|
125
124
|
from fontTools.varLib.merger import MutatorMerger
|
|
@@ -136,6 +135,7 @@ from enum import IntEnum
|
|
|
136
135
|
import logging
|
|
137
136
|
import os
|
|
138
137
|
import re
|
|
138
|
+
import io
|
|
139
139
|
from typing import Dict, Iterable, Mapping, Optional, Sequence, Tuple, Union
|
|
140
140
|
import warnings
|
|
141
141
|
|
|
@@ -433,7 +433,27 @@ class AxisLimits(_BaseAxisLimits):
|
|
|
433
433
|
|
|
434
434
|
avarSegments = {}
|
|
435
435
|
if usingAvar and "avar" in varfont:
|
|
436
|
-
|
|
436
|
+
avar = varfont["avar"]
|
|
437
|
+
avarSegments = avar.segments
|
|
438
|
+
|
|
439
|
+
if getattr(avar, "majorVersion", 1) >= 2 and avar.table.VarStore:
|
|
440
|
+
pinnedAxes = set(self.pinnedLocation())
|
|
441
|
+
if not pinnedAxes.issuperset(avarSegments):
|
|
442
|
+
raise NotImplementedError(
|
|
443
|
+
"Partial-instancing avar2 table is not supported"
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
# TODO: Merge this with the main codepath.
|
|
447
|
+
|
|
448
|
+
# Full instancing of avar2 font. Use avar table to normalize location and return.
|
|
449
|
+
location = self.pinnedLocation()
|
|
450
|
+
location = {
|
|
451
|
+
tag: normalize(value, axes[tag], avarSegments.get(tag, None))
|
|
452
|
+
for tag, value in location.items()
|
|
453
|
+
}
|
|
454
|
+
return NormalizedAxisLimits(
|
|
455
|
+
**avar.renormalizeLocation(location, varfont, dropZeroes=False)
|
|
456
|
+
)
|
|
437
457
|
|
|
438
458
|
normalizedLimits = {}
|
|
439
459
|
|
|
@@ -643,7 +663,11 @@ def instantiateCFF2(
|
|
|
643
663
|
# the Private dicts.
|
|
644
664
|
#
|
|
645
665
|
# Then prune unused things and possibly drop the VarStore if it's empty.
|
|
646
|
-
#
|
|
666
|
+
#
|
|
667
|
+
# If the downgrade parameter is True, no actual downgrading is done, but
|
|
668
|
+
# the function returns True if the VarStore was empty after instantiation,
|
|
669
|
+
# and hence a downgrade to CFF is possible. In all other cases it returns
|
|
670
|
+
# False.
|
|
647
671
|
|
|
648
672
|
log.info("Instantiating CFF2 table")
|
|
649
673
|
|
|
@@ -882,9 +906,9 @@ def instantiateCFF2(
|
|
|
882
906
|
del private.vstore
|
|
883
907
|
|
|
884
908
|
if downgrade:
|
|
885
|
-
|
|
909
|
+
return True
|
|
886
910
|
|
|
887
|
-
|
|
911
|
+
return False
|
|
888
912
|
|
|
889
913
|
|
|
890
914
|
def _instantiateGvarGlyph(
|
|
@@ -1116,7 +1140,8 @@ def _instantiateVHVAR(varfont, axisLimits, tableFields, *, round=round):
|
|
|
1116
1140
|
varIdx = advMapping.mapping[glyphName]
|
|
1117
1141
|
else:
|
|
1118
1142
|
varIdx = varfont.getGlyphID(glyphName)
|
|
1119
|
-
|
|
1143
|
+
delta = round(defaultDeltas[varIdx])
|
|
1144
|
+
metrics[glyphName] = (max(0, advanceWidth + delta), sb)
|
|
1120
1145
|
|
|
1121
1146
|
if (
|
|
1122
1147
|
tableTag == "VVAR"
|
|
@@ -1377,12 +1402,55 @@ def _isValidAvarSegmentMap(axisTag, segmentMap):
|
|
|
1377
1402
|
return True
|
|
1378
1403
|
|
|
1379
1404
|
|
|
1405
|
+
def downgradeCFF2ToCFF(varfont):
|
|
1406
|
+
# Save these properties
|
|
1407
|
+
recalcTimestamp = varfont.recalcTimestamp
|
|
1408
|
+
recalcBBoxes = varfont.recalcBBoxes
|
|
1409
|
+
|
|
1410
|
+
# Disable them
|
|
1411
|
+
varfont.recalcTimestamp = False
|
|
1412
|
+
varfont.recalcBBoxes = False
|
|
1413
|
+
|
|
1414
|
+
# Save to memory, reload, downgrade and save again, reload.
|
|
1415
|
+
# We do this dance because the convertCFF2ToCFF changes glyph
|
|
1416
|
+
# names, so following save would fail if any other table was
|
|
1417
|
+
# loaded and referencing glyph names.
|
|
1418
|
+
#
|
|
1419
|
+
# The second save+load is unfortunate but also necessary.
|
|
1420
|
+
|
|
1421
|
+
stream = io.BytesIO()
|
|
1422
|
+
log.info("Saving CFF2 font to memory for downgrade")
|
|
1423
|
+
varfont.save(stream)
|
|
1424
|
+
stream.seek(0)
|
|
1425
|
+
varfont = TTFont(stream, recalcTimestamp=False, recalcBBoxes=False)
|
|
1426
|
+
|
|
1427
|
+
convertCFF2ToCFF(varfont)
|
|
1428
|
+
|
|
1429
|
+
stream = io.BytesIO()
|
|
1430
|
+
log.info("Saving downgraded CFF font to memory")
|
|
1431
|
+
varfont.save(stream)
|
|
1432
|
+
stream.seek(0)
|
|
1433
|
+
varfont = TTFont(stream, recalcTimestamp=False, recalcBBoxes=False)
|
|
1434
|
+
|
|
1435
|
+
# Uncomment, to see test all tables can be loaded. This fails without
|
|
1436
|
+
# the extra save+load above.
|
|
1437
|
+
"""
|
|
1438
|
+
for tag in varfont.keys():
|
|
1439
|
+
print("Loading", tag)
|
|
1440
|
+
varfont[tag]
|
|
1441
|
+
"""
|
|
1442
|
+
|
|
1443
|
+
# Restore them
|
|
1444
|
+
varfont.recalcTimestamp = recalcTimestamp
|
|
1445
|
+
varfont.recalcBBoxes = recalcBBoxes
|
|
1446
|
+
|
|
1447
|
+
return varfont
|
|
1448
|
+
|
|
1449
|
+
|
|
1380
1450
|
def instantiateAvar(varfont, axisLimits):
|
|
1381
1451
|
# 'axisLimits' dict must contain user-space (non-normalized) coordinates.
|
|
1382
1452
|
|
|
1383
1453
|
avar = varfont["avar"]
|
|
1384
|
-
if getattr(avar, "majorVersion", 1) >= 2 and avar.table.VarStore:
|
|
1385
|
-
raise NotImplementedError("avar table with VarStore is not supported")
|
|
1386
1454
|
|
|
1387
1455
|
segments = avar.segments
|
|
1388
1456
|
|
|
@@ -1393,6 +1461,9 @@ def instantiateAvar(varfont, axisLimits):
|
|
|
1393
1461
|
del varfont["avar"]
|
|
1394
1462
|
return
|
|
1395
1463
|
|
|
1464
|
+
if getattr(avar, "majorVersion", 1) >= 2 and avar.table.VarStore:
|
|
1465
|
+
raise NotImplementedError("avar table with VarStore is not supported")
|
|
1466
|
+
|
|
1396
1467
|
log.info("Instantiating avar table")
|
|
1397
1468
|
for axis in pinnedAxes:
|
|
1398
1469
|
if axis in segments:
|
|
@@ -1594,6 +1665,7 @@ def instantiateVariableFont(
|
|
|
1594
1665
|
updateFontNames=False,
|
|
1595
1666
|
*,
|
|
1596
1667
|
downgradeCFF2=False,
|
|
1668
|
+
static=False,
|
|
1597
1669
|
):
|
|
1598
1670
|
"""Instantiate variable font, either fully or partially.
|
|
1599
1671
|
|
|
@@ -1637,12 +1709,23 @@ def instantiateVariableFont(
|
|
|
1637
1709
|
software that does not support CFF2. Defaults to False. Note that this
|
|
1638
1710
|
operation also removes overlaps within glyph shapes, as CFF does not support
|
|
1639
1711
|
overlaps but CFF2 does.
|
|
1712
|
+
static (bool): if True, generate a full instance (static font) instead of a partial
|
|
1713
|
+
instance (variable font).
|
|
1640
1714
|
"""
|
|
1641
1715
|
# 'overlap' used to be bool and is now enum; for backward compat keep accepting bool
|
|
1642
1716
|
overlap = OverlapMode(int(overlap))
|
|
1643
1717
|
|
|
1644
1718
|
sanityCheckVariableTables(varfont)
|
|
1645
1719
|
|
|
1720
|
+
if static:
|
|
1721
|
+
unspecified = []
|
|
1722
|
+
for axis in varfont["fvar"].axes:
|
|
1723
|
+
if axis.axisTag not in axisLimits:
|
|
1724
|
+
axisLimits[axis.axisTag] = None
|
|
1725
|
+
unspecified.append(axis.axisTag)
|
|
1726
|
+
if unspecified:
|
|
1727
|
+
log.info("Pinning unspecified axes to default: %s", unspecified)
|
|
1728
|
+
|
|
1646
1729
|
axisLimits = AxisLimits(axisLimits).limitAxesAndPopulateDefaults(varfont)
|
|
1647
1730
|
|
|
1648
1731
|
log.info("Restricted limits: %s", axisLimits)
|
|
@@ -1665,7 +1748,9 @@ def instantiateVariableFont(
|
|
|
1665
1748
|
instantiateVARC(varfont, normalizedLimits)
|
|
1666
1749
|
|
|
1667
1750
|
if "CFF2" in varfont:
|
|
1668
|
-
instantiateCFF2(
|
|
1751
|
+
downgradeCFF2 = instantiateCFF2(
|
|
1752
|
+
varfont, normalizedLimits, downgrade=downgradeCFF2
|
|
1753
|
+
)
|
|
1669
1754
|
|
|
1670
1755
|
if "gvar" in varfont:
|
|
1671
1756
|
instantiateGvar(varfont, normalizedLimits, optimize=optimize)
|
|
@@ -1720,6 +1805,12 @@ def instantiateVariableFont(
|
|
|
1720
1805
|
# name table has been updated.
|
|
1721
1806
|
setRibbiBits(varfont)
|
|
1722
1807
|
|
|
1808
|
+
if downgradeCFF2:
|
|
1809
|
+
origVarfont = varfont
|
|
1810
|
+
varfont = downgradeCFF2ToCFF(varfont)
|
|
1811
|
+
if inplace:
|
|
1812
|
+
origVarfont.__dict__ = varfont.__dict__.copy()
|
|
1813
|
+
|
|
1723
1814
|
return varfont
|
|
1724
1815
|
|
|
1725
1816
|
|
|
@@ -1826,6 +1917,12 @@ def parseArgs(args):
|
|
|
1826
1917
|
default=None,
|
|
1827
1918
|
help="Output instance TTF file (default: INPUT-instance.ttf).",
|
|
1828
1919
|
)
|
|
1920
|
+
parser.add_argument(
|
|
1921
|
+
"--static",
|
|
1922
|
+
dest="static",
|
|
1923
|
+
action="store_true",
|
|
1924
|
+
help="Make a static font: pin unspecified axes to their default location.",
|
|
1925
|
+
)
|
|
1829
1926
|
parser.add_argument(
|
|
1830
1927
|
"--no-optimize",
|
|
1831
1928
|
dest="optimize",
|
|
@@ -1923,13 +2020,13 @@ def main(args=None):
|
|
|
1923
2020
|
recalcBBoxes=options.recalc_bounds,
|
|
1924
2021
|
)
|
|
1925
2022
|
|
|
1926
|
-
isFullInstance = {
|
|
2023
|
+
isFullInstance = options.static or {
|
|
1927
2024
|
axisTag
|
|
1928
2025
|
for axisTag, limit in axisLimits.items()
|
|
1929
2026
|
if limit is None or limit[0] == limit[2]
|
|
1930
2027
|
}.issuperset(axis.axisTag for axis in varfont["fvar"].axes)
|
|
1931
2028
|
|
|
1932
|
-
instantiateVariableFont(
|
|
2029
|
+
varfont = instantiateVariableFont(
|
|
1933
2030
|
varfont,
|
|
1934
2031
|
axisLimits,
|
|
1935
2032
|
inplace=True,
|
|
@@ -1937,6 +2034,7 @@ def main(args=None):
|
|
|
1937
2034
|
overlap=options.overlap,
|
|
1938
2035
|
updateFontNames=options.update_name_table,
|
|
1939
2036
|
downgradeCFF2=options.downgrade_cff2,
|
|
2037
|
+
static=options.static,
|
|
1940
2038
|
)
|
|
1941
2039
|
|
|
1942
2040
|
suffix = "-instance" if isFullInstance else "-partial"
|
fontTools/varLib/iup.c
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Generated by Cython 3.1.
|
|
1
|
+
/* Generated by Cython 3.1.3 */
|
|
2
2
|
|
|
3
3
|
/* BEGIN: Cython Metadata
|
|
4
4
|
{
|
|
@@ -26,8 +26,8 @@ END: Cython Metadata */
|
|
|
26
26
|
#elif PY_VERSION_HEX < 0x03080000
|
|
27
27
|
#error Cython requires Python 3.8+.
|
|
28
28
|
#else
|
|
29
|
-
#define __PYX_ABI_VERSION "
|
|
30
|
-
#define CYTHON_HEX_VERSION
|
|
29
|
+
#define __PYX_ABI_VERSION "3_1_3"
|
|
30
|
+
#define CYTHON_HEX_VERSION 0x030103F0
|
|
31
31
|
#define CYTHON_FUTURE_DIVISION 1
|
|
32
32
|
/* CModulePreamble */
|
|
33
33
|
#include <stddef.h>
|
|
@@ -390,6 +390,9 @@ END: Cython Metadata */
|
|
|
390
390
|
enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
|
|
391
391
|
#endif
|
|
392
392
|
#endif
|
|
393
|
+
#ifndef CYTHON_LOCK_AND_GIL_DEADLOCK_AVOIDANCE_TIME
|
|
394
|
+
#define CYTHON_LOCK_AND_GIL_DEADLOCK_AVOIDANCE_TIME 100
|
|
395
|
+
#endif
|
|
393
396
|
#ifndef __has_attribute
|
|
394
397
|
#define __has_attribute(x) 0
|
|
395
398
|
#endif
|
|
@@ -2141,7 +2144,7 @@ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);
|
|
|
2141
2144
|
static PyObject *__Pyx_PyLong_AbsNeg(PyObject *num);
|
|
2142
2145
|
#define __Pyx_PyNumber_Absolute(x)\
|
|
2143
2146
|
((likely(PyLong_CheckExact(x))) ?\
|
|
2144
|
-
(likely(__Pyx_PyLong_IsNonNeg(x)) ? (
|
|
2147
|
+
(likely(__Pyx_PyLong_IsNonNeg(x)) ? __Pyx_NewRef(x) : __Pyx_PyLong_AbsNeg(x)) :\
|
|
2145
2148
|
PyNumber_Absolute(x))
|
|
2146
2149
|
#else
|
|
2147
2150
|
#define __Pyx_PyNumber_Absolute(x) PyNumber_Absolute(x)
|
|
@@ -14329,7 +14332,7 @@ static PyObject *__Pyx_PyLong_AbsNeg(PyObject *n) {
|
|
|
14329
14332
|
PyObject *copy = _PyLong_Copy((PyLongObject*)n);
|
|
14330
14333
|
if (likely(copy)) {
|
|
14331
14334
|
#if PY_VERSION_HEX >= 0x030C00A7
|
|
14332
|
-
((PyLongObject*)copy)->long_value.lv_tag
|
|
14335
|
+
((PyLongObject*)copy)->long_value.lv_tag ^= ((PyLongObject*)copy)->long_value.lv_tag & _PyLong_SIGN_MASK;
|
|
14333
14336
|
#else
|
|
14334
14337
|
__Pyx_SET_SIZE(copy, -Py_SIZE(copy));
|
|
14335
14338
|
#endif
|
|
@@ -14942,6 +14945,7 @@ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject
|
|
|
14942
14945
|
changed = 1;
|
|
14943
14946
|
}
|
|
14944
14947
|
#endif // CYTHON_METH_FASTCALL
|
|
14948
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
14945
14949
|
else if (strcmp(memb->name, "__module__") == 0) {
|
|
14946
14950
|
PyObject *descr;
|
|
14947
14951
|
assert(memb->type == T_OBJECT);
|
|
@@ -14956,11 +14960,13 @@ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject
|
|
|
14956
14960
|
}
|
|
14957
14961
|
changed = 1;
|
|
14958
14962
|
}
|
|
14963
|
+
#endif // !CYTHON_COMPILING_IN_PYPY
|
|
14959
14964
|
}
|
|
14960
14965
|
memb++;
|
|
14961
14966
|
}
|
|
14962
14967
|
}
|
|
14963
14968
|
#endif // !CYTHON_COMPILING_IN_LIMITED_API
|
|
14969
|
+
#if !CYTHON_COMPILING_IN_PYPY
|
|
14964
14970
|
slot = spec->slots;
|
|
14965
14971
|
while (slot && slot->slot && slot->slot != Py_tp_getset)
|
|
14966
14972
|
slot++;
|
|
@@ -14992,6 +14998,7 @@ static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject
|
|
|
14992
14998
|
++getset;
|
|
14993
14999
|
}
|
|
14994
15000
|
}
|
|
15001
|
+
#endif // !CYTHON_COMPILING_IN_PYPY
|
|
14995
15002
|
if (changed)
|
|
14996
15003
|
PyType_Modified(type);
|
|
14997
15004
|
#endif // PY_VERSION_HEX > 0x030900B1
|
|
@@ -15090,6 +15097,13 @@ try_unpack:
|
|
|
15090
15097
|
|
|
15091
15098
|
/* PyObjectCallMethod0 */
|
|
15092
15099
|
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
|
|
15100
|
+
#if CYTHON_VECTORCALL && (__PYX_LIMITED_VERSION_HEX >= 0x030C0000 || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x03090000))
|
|
15101
|
+
PyObject *args[1] = {obj};
|
|
15102
|
+
(void) __Pyx_PyObject_GetMethod;
|
|
15103
|
+
(void) __Pyx_PyObject_CallOneArg;
|
|
15104
|
+
(void) __Pyx_PyObject_CallNoArg;
|
|
15105
|
+
return PyObject_VectorcallMethod(method_name, args, 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
|
|
15106
|
+
#else
|
|
15093
15107
|
PyObject *method = NULL, *result = NULL;
|
|
15094
15108
|
int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
|
|
15095
15109
|
if (likely(is_method)) {
|
|
@@ -15102,6 +15116,7 @@ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name
|
|
|
15102
15116
|
Py_DECREF(method);
|
|
15103
15117
|
bad:
|
|
15104
15118
|
return result;
|
|
15119
|
+
#endif
|
|
15105
15120
|
}
|
|
15106
15121
|
|
|
15107
15122
|
/* ValidateBasesTuple */
|
|
@@ -15489,7 +15504,7 @@ bad:
|
|
|
15489
15504
|
}
|
|
15490
15505
|
|
|
15491
15506
|
/* CommonTypesMetaclass */
|
|
15492
|
-
PyObject* __pyx_CommonTypesMetaclass_get_module(CYTHON_UNUSED PyObject *self, CYTHON_UNUSED void* context) {
|
|
15507
|
+
static PyObject* __pyx_CommonTypesMetaclass_get_module(CYTHON_UNUSED PyObject *self, CYTHON_UNUSED void* context) {
|
|
15493
15508
|
return PyUnicode_FromString(__PYX_ABI_MODULE_NAME);
|
|
15494
15509
|
}
|
|
15495
15510
|
static PyGetSetDef __pyx_CommonTypesMetaclass_getset[] = {
|
|
@@ -17939,7 +17954,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyOb
|
|
|
17939
17954
|
}
|
|
17940
17955
|
|
|
17941
17956
|
/* PyObjectCallMethod1 */
|
|
17942
|
-
#if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000)
|
|
17957
|
+
#if !(CYTHON_VECTORCALL && (__PYX_LIMITED_VERSION_HEX >= 0x030C0000 || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x03090000)))
|
|
17943
17958
|
static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
|
|
17944
17959
|
PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
|
|
17945
17960
|
Py_DECREF(method);
|
|
@@ -17947,7 +17962,7 @@ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
|
|
|
17947
17962
|
}
|
|
17948
17963
|
#endif
|
|
17949
17964
|
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
|
|
17950
|
-
#if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C0000
|
|
17965
|
+
#if CYTHON_VECTORCALL && (__PYX_LIMITED_VERSION_HEX >= 0x030C0000 || (!CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x03090000))
|
|
17951
17966
|
PyObject *args[2] = {obj, arg};
|
|
17952
17967
|
(void) __Pyx_PyObject_GetMethod;
|
|
17953
17968
|
(void) __Pyx_PyObject_CallOneArg;
|
|
Binary file
|
fontTools/varLib/mutator.py
CHANGED
|
@@ -4,9 +4,16 @@ Instantiate a variation font. Run, eg:
|
|
|
4
4
|
.. code-block:: sh
|
|
5
5
|
|
|
6
6
|
$ fonttools varLib.mutator ./NotoSansArabic-VF.ttf wght=140 wdth=85
|
|
7
|
+
|
|
8
|
+
.. warning::
|
|
9
|
+
``fontTools.varLib.mutator`` is deprecated in favor of :mod:`fontTools.varLib.instancer`
|
|
10
|
+
which provides equivalent full instancing and also supports partial instancing.
|
|
11
|
+
Please migrate CLI usage to ``fonttools varLib.instancer`` and API usage to
|
|
12
|
+
:func:`fontTools.varLib.instancer.instantiateVariableFont`.
|
|
7
13
|
"""
|
|
8
14
|
|
|
9
15
|
from fontTools.misc.fixedTools import floatToFixedToFloat, floatToFixed
|
|
16
|
+
from fontTools.misc.loggingTools import deprecateFunction
|
|
10
17
|
from fontTools.misc.roundTools import otRound
|
|
11
18
|
from fontTools.pens.boundsPen import BoundsPen
|
|
12
19
|
from fontTools.ttLib import TTFont, newTable
|
|
@@ -159,6 +166,10 @@ def interpolate_cff2_metrics(varfont, topDict, glyphOrder, loc):
|
|
|
159
166
|
hmtx[gname] = tuple(entry)
|
|
160
167
|
|
|
161
168
|
|
|
169
|
+
@deprecateFunction(
|
|
170
|
+
"use fontTools.varLib.instancer.instantiateVariableFont instead "
|
|
171
|
+
"for either full or partial instancing",
|
|
172
|
+
)
|
|
162
173
|
def instantiateVariableFont(varfont, location, inplace=False, overlap=True):
|
|
163
174
|
"""Generate a static instance from a variable TTFont and a dictionary
|
|
164
175
|
defining the desired location along the variable font's axes.
|