Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- evalkit_tf437/lib/python3.10/site-packages/fontTools/cffLib/__pycache__/width.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/cffLib/width.py +210 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__init__.py +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__pycache__/errors.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__pycache__/table_builder.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/errors.py +2 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/table_builder.py +223 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/unbuilder.py +81 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/config/__init__.py +75 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/cu2qu/__pycache__/__main__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/cu2qu/cli.py +198 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/designspaceLib/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/designspaceLib/__pycache__/statNames.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/StandardEncoding.py +258 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__init__.py +1 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__pycache__/StandardEncoding.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/codecs.py +135 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/feaLib/__pycache__/builder.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/__init__.py +248 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/__pycache__/cmap.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/base.py +81 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/tables.py +341 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/unicode.py +78 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/cairoPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/pointInsidePen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/recordingPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/roundingPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/statisticsPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/svgPathPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/wxPen.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/boundsPen.py +98 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/cu2quPen.py +325 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/pointInsidePen.py +192 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/qtPen.py +29 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/recordingPen.py +335 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/reportLabPen.py +79 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/teePen.py +55 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/transformPen.py +115 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/ttGlyphPen.py +335 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/wxPen.py +29 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/t1Lib/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/S__i_l_f.py +1037 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_B_D_T_.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_B_L_C_.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/DefaultTable.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-310.pyc +0 -0
- evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/G_M_A_P_.cpython-310.pyc +0 -0
evalkit_tf437/lib/python3.10/site-packages/fontTools/cffLib/__pycache__/width.cpython-310.pyc
ADDED
|
Binary file (6.41 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/cffLib/width.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
+
"""T2CharString glyph width optimizer.
|
| 4 |
+
|
| 5 |
+
CFF glyphs whose width equals the CFF Private dictionary's ``defaultWidthX``
|
| 6 |
+
value do not need to specify their width in their charstring, saving bytes.
|
| 7 |
+
This module determines the optimum ``defaultWidthX`` and ``nominalWidthX``
|
| 8 |
+
values for a font, when provided with a list of glyph widths."""
|
| 9 |
+
|
| 10 |
+
from fontTools.ttLib import TTFont
|
| 11 |
+
from collections import defaultdict
|
| 12 |
+
from operator import add
|
| 13 |
+
from functools import reduce
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
__all__ = ["optimizeWidths", "main"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class missingdict(dict):
|
| 20 |
+
def __init__(self, missing_func):
|
| 21 |
+
self.missing_func = missing_func
|
| 22 |
+
|
| 23 |
+
def __missing__(self, v):
|
| 24 |
+
return self.missing_func(v)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def cumSum(f, op=add, start=0, decreasing=False):
|
| 28 |
+
keys = sorted(f.keys())
|
| 29 |
+
minx, maxx = keys[0], keys[-1]
|
| 30 |
+
|
| 31 |
+
total = reduce(op, f.values(), start)
|
| 32 |
+
|
| 33 |
+
if decreasing:
|
| 34 |
+
missing = lambda x: start if x > maxx else total
|
| 35 |
+
domain = range(maxx, minx - 1, -1)
|
| 36 |
+
else:
|
| 37 |
+
missing = lambda x: start if x < minx else total
|
| 38 |
+
domain = range(minx, maxx + 1)
|
| 39 |
+
|
| 40 |
+
out = missingdict(missing)
|
| 41 |
+
|
| 42 |
+
v = start
|
| 43 |
+
for x in domain:
|
| 44 |
+
v = op(v, f[x])
|
| 45 |
+
out[x] = v
|
| 46 |
+
|
| 47 |
+
return out
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def byteCost(widths, default, nominal):
|
| 51 |
+
if not hasattr(widths, "items"):
|
| 52 |
+
d = defaultdict(int)
|
| 53 |
+
for w in widths:
|
| 54 |
+
d[w] += 1
|
| 55 |
+
widths = d
|
| 56 |
+
|
| 57 |
+
cost = 0
|
| 58 |
+
for w, freq in widths.items():
|
| 59 |
+
if w == default:
|
| 60 |
+
continue
|
| 61 |
+
diff = abs(w - nominal)
|
| 62 |
+
if diff <= 107:
|
| 63 |
+
cost += freq
|
| 64 |
+
elif diff <= 1131:
|
| 65 |
+
cost += freq * 2
|
| 66 |
+
else:
|
| 67 |
+
cost += freq * 5
|
| 68 |
+
return cost
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def optimizeWidthsBruteforce(widths):
|
| 72 |
+
"""Bruteforce version. Veeeeeeeeeeeeeeeeery slow. Only works for smallests of fonts."""
|
| 73 |
+
|
| 74 |
+
d = defaultdict(int)
|
| 75 |
+
for w in widths:
|
| 76 |
+
d[w] += 1
|
| 77 |
+
|
| 78 |
+
# Maximum number of bytes using default can possibly save
|
| 79 |
+
maxDefaultAdvantage = 5 * max(d.values())
|
| 80 |
+
|
| 81 |
+
minw, maxw = min(widths), max(widths)
|
| 82 |
+
domain = list(range(minw, maxw + 1))
|
| 83 |
+
|
| 84 |
+
bestCostWithoutDefault = min(byteCost(widths, None, nominal) for nominal in domain)
|
| 85 |
+
|
| 86 |
+
bestCost = len(widths) * 5 + 1
|
| 87 |
+
for nominal in domain:
|
| 88 |
+
if byteCost(widths, None, nominal) > bestCost + maxDefaultAdvantage:
|
| 89 |
+
continue
|
| 90 |
+
for default in domain:
|
| 91 |
+
cost = byteCost(widths, default, nominal)
|
| 92 |
+
if cost < bestCost:
|
| 93 |
+
bestCost = cost
|
| 94 |
+
bestDefault = default
|
| 95 |
+
bestNominal = nominal
|
| 96 |
+
|
| 97 |
+
return bestDefault, bestNominal
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def optimizeWidths(widths):
|
| 101 |
+
"""Given a list of glyph widths, or dictionary mapping glyph width to number of
|
| 102 |
+
glyphs having that, returns a tuple of best CFF default and nominal glyph widths.
|
| 103 |
+
|
| 104 |
+
This algorithm is linear in UPEM+numGlyphs."""
|
| 105 |
+
|
| 106 |
+
if not hasattr(widths, "items"):
|
| 107 |
+
d = defaultdict(int)
|
| 108 |
+
for w in widths:
|
| 109 |
+
d[w] += 1
|
| 110 |
+
widths = d
|
| 111 |
+
|
| 112 |
+
keys = sorted(widths.keys())
|
| 113 |
+
minw, maxw = keys[0], keys[-1]
|
| 114 |
+
domain = list(range(minw, maxw + 1))
|
| 115 |
+
|
| 116 |
+
# Cumulative sum/max forward/backward.
|
| 117 |
+
cumFrqU = cumSum(widths, op=add)
|
| 118 |
+
cumMaxU = cumSum(widths, op=max)
|
| 119 |
+
cumFrqD = cumSum(widths, op=add, decreasing=True)
|
| 120 |
+
cumMaxD = cumSum(widths, op=max, decreasing=True)
|
| 121 |
+
|
| 122 |
+
# Cost per nominal choice, without default consideration.
|
| 123 |
+
nomnCostU = missingdict(
|
| 124 |
+
lambda x: cumFrqU[x] + cumFrqU[x - 108] + cumFrqU[x - 1132] * 3
|
| 125 |
+
)
|
| 126 |
+
nomnCostD = missingdict(
|
| 127 |
+
lambda x: cumFrqD[x] + cumFrqD[x + 108] + cumFrqD[x + 1132] * 3
|
| 128 |
+
)
|
| 129 |
+
nomnCost = missingdict(lambda x: nomnCostU[x] + nomnCostD[x] - widths[x])
|
| 130 |
+
|
| 131 |
+
# Cost-saving per nominal choice, by best default choice.
|
| 132 |
+
dfltCostU = missingdict(
|
| 133 |
+
lambda x: max(cumMaxU[x], cumMaxU[x - 108] * 2, cumMaxU[x - 1132] * 5)
|
| 134 |
+
)
|
| 135 |
+
dfltCostD = missingdict(
|
| 136 |
+
lambda x: max(cumMaxD[x], cumMaxD[x + 108] * 2, cumMaxD[x + 1132] * 5)
|
| 137 |
+
)
|
| 138 |
+
dfltCost = missingdict(lambda x: max(dfltCostU[x], dfltCostD[x]))
|
| 139 |
+
|
| 140 |
+
# Combined cost per nominal choice.
|
| 141 |
+
bestCost = missingdict(lambda x: nomnCost[x] - dfltCost[x])
|
| 142 |
+
|
| 143 |
+
# Best nominal.
|
| 144 |
+
nominal = min(domain, key=lambda x: bestCost[x])
|
| 145 |
+
|
| 146 |
+
# Work back the best default.
|
| 147 |
+
bestC = bestCost[nominal]
|
| 148 |
+
dfltC = nomnCost[nominal] - bestCost[nominal]
|
| 149 |
+
ends = []
|
| 150 |
+
if dfltC == dfltCostU[nominal]:
|
| 151 |
+
starts = [nominal, nominal - 108, nominal - 1132]
|
| 152 |
+
for start in starts:
|
| 153 |
+
while cumMaxU[start] and cumMaxU[start] == cumMaxU[start - 1]:
|
| 154 |
+
start -= 1
|
| 155 |
+
ends.append(start)
|
| 156 |
+
else:
|
| 157 |
+
starts = [nominal, nominal + 108, nominal + 1132]
|
| 158 |
+
for start in starts:
|
| 159 |
+
while cumMaxD[start] and cumMaxD[start] == cumMaxD[start + 1]:
|
| 160 |
+
start += 1
|
| 161 |
+
ends.append(start)
|
| 162 |
+
default = min(ends, key=lambda default: byteCost(widths, default, nominal))
|
| 163 |
+
|
| 164 |
+
return default, nominal
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def main(args=None):
|
| 168 |
+
"""Calculate optimum defaultWidthX/nominalWidthX values"""
|
| 169 |
+
|
| 170 |
+
import argparse
|
| 171 |
+
|
| 172 |
+
parser = argparse.ArgumentParser(
|
| 173 |
+
"fonttools cffLib.width",
|
| 174 |
+
description=main.__doc__,
|
| 175 |
+
)
|
| 176 |
+
parser.add_argument(
|
| 177 |
+
"inputs", metavar="FILE", type=str, nargs="+", help="Input TTF files"
|
| 178 |
+
)
|
| 179 |
+
parser.add_argument(
|
| 180 |
+
"-b",
|
| 181 |
+
"--brute-force",
|
| 182 |
+
dest="brute",
|
| 183 |
+
action="store_true",
|
| 184 |
+
help="Use brute-force approach (VERY slow)",
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
args = parser.parse_args(args)
|
| 188 |
+
|
| 189 |
+
for fontfile in args.inputs:
|
| 190 |
+
font = TTFont(fontfile)
|
| 191 |
+
hmtx = font["hmtx"]
|
| 192 |
+
widths = [m[0] for m in hmtx.metrics.values()]
|
| 193 |
+
if args.brute:
|
| 194 |
+
default, nominal = optimizeWidthsBruteforce(widths)
|
| 195 |
+
else:
|
| 196 |
+
default, nominal = optimizeWidths(widths)
|
| 197 |
+
print(
|
| 198 |
+
"glyphs=%d default=%d nominal=%d byteCost=%d"
|
| 199 |
+
% (len(widths), default, nominal, byteCost(widths, default, nominal))
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
if __name__ == "__main__":
|
| 204 |
+
import sys
|
| 205 |
+
|
| 206 |
+
if len(sys.argv) == 1:
|
| 207 |
+
import doctest
|
| 208 |
+
|
| 209 |
+
sys.exit(doctest.testmod().failed)
|
| 210 |
+
main()
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__init__.py
ADDED
|
File without changes
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__pycache__/errors.cpython-310.pyc
ADDED
|
Binary file (345 Bytes). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/__pycache__/table_builder.cpython-310.pyc
ADDED
|
Binary file (6.16 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/errors.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class ColorLibError(Exception):
|
| 2 |
+
pass
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/table_builder.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
colorLib.table_builder: Generic helper for filling in BaseTable derivatives from tuples and maps and such.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import collections
|
| 7 |
+
import enum
|
| 8 |
+
from fontTools.ttLib.tables.otBase import (
|
| 9 |
+
BaseTable,
|
| 10 |
+
FormatSwitchingBaseTable,
|
| 11 |
+
UInt8FormatSwitchingBaseTable,
|
| 12 |
+
)
|
| 13 |
+
from fontTools.ttLib.tables.otConverters import (
|
| 14 |
+
ComputedInt,
|
| 15 |
+
SimpleValue,
|
| 16 |
+
Struct,
|
| 17 |
+
Short,
|
| 18 |
+
UInt8,
|
| 19 |
+
UShort,
|
| 20 |
+
IntValue,
|
| 21 |
+
FloatValue,
|
| 22 |
+
OptionalValue,
|
| 23 |
+
)
|
| 24 |
+
from fontTools.misc.roundTools import otRound
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class BuildCallback(enum.Enum):
|
| 28 |
+
"""Keyed on (BEFORE_BUILD, class[, Format if available]).
|
| 29 |
+
Receives (dest, source).
|
| 30 |
+
Should return (dest, source), which can be new objects.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
BEFORE_BUILD = enum.auto()
|
| 34 |
+
|
| 35 |
+
"""Keyed on (AFTER_BUILD, class[, Format if available]).
|
| 36 |
+
Receives (dest).
|
| 37 |
+
Should return dest, which can be a new object.
|
| 38 |
+
"""
|
| 39 |
+
AFTER_BUILD = enum.auto()
|
| 40 |
+
|
| 41 |
+
"""Keyed on (CREATE_DEFAULT, class[, Format if available]).
|
| 42 |
+
Receives no arguments.
|
| 43 |
+
Should return a new instance of class.
|
| 44 |
+
"""
|
| 45 |
+
CREATE_DEFAULT = enum.auto()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _assignable(convertersByName):
|
| 49 |
+
return {k: v for k, v in convertersByName.items() if not isinstance(v, ComputedInt)}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def _isNonStrSequence(value):
|
| 53 |
+
return isinstance(value, collections.abc.Sequence) and not isinstance(value, str)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _split_format(cls, source):
|
| 57 |
+
if _isNonStrSequence(source):
|
| 58 |
+
assert len(source) > 0, f"{cls} needs at least format from {source}"
|
| 59 |
+
fmt, remainder = source[0], source[1:]
|
| 60 |
+
elif isinstance(source, collections.abc.Mapping):
|
| 61 |
+
assert "Format" in source, f"{cls} needs at least Format from {source}"
|
| 62 |
+
remainder = source.copy()
|
| 63 |
+
fmt = remainder.pop("Format")
|
| 64 |
+
else:
|
| 65 |
+
raise ValueError(f"Not sure how to populate {cls} from {source}")
|
| 66 |
+
|
| 67 |
+
assert isinstance(
|
| 68 |
+
fmt, collections.abc.Hashable
|
| 69 |
+
), f"{cls} Format is not hashable: {fmt!r}"
|
| 70 |
+
assert fmt in cls.convertersByName, f"{cls} invalid Format: {fmt!r}"
|
| 71 |
+
|
| 72 |
+
return fmt, remainder
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class TableBuilder:
|
| 76 |
+
"""
|
| 77 |
+
Helps to populate things derived from BaseTable from maps, tuples, etc.
|
| 78 |
+
|
| 79 |
+
A table of lifecycle callbacks may be provided to add logic beyond what is possible
|
| 80 |
+
based on otData info for the target class. See BuildCallbacks.
|
| 81 |
+
"""
|
| 82 |
+
|
| 83 |
+
def __init__(self, callbackTable=None):
|
| 84 |
+
if callbackTable is None:
|
| 85 |
+
callbackTable = {}
|
| 86 |
+
self._callbackTable = callbackTable
|
| 87 |
+
|
| 88 |
+
def _convert(self, dest, field, converter, value):
|
| 89 |
+
enumClass = getattr(converter, "enumClass", None)
|
| 90 |
+
|
| 91 |
+
if enumClass:
|
| 92 |
+
if isinstance(value, enumClass):
|
| 93 |
+
pass
|
| 94 |
+
elif isinstance(value, str):
|
| 95 |
+
try:
|
| 96 |
+
value = getattr(enumClass, value.upper())
|
| 97 |
+
except AttributeError:
|
| 98 |
+
raise ValueError(f"{value} is not a valid {enumClass}")
|
| 99 |
+
else:
|
| 100 |
+
value = enumClass(value)
|
| 101 |
+
|
| 102 |
+
elif isinstance(converter, IntValue):
|
| 103 |
+
value = otRound(value)
|
| 104 |
+
elif isinstance(converter, FloatValue):
|
| 105 |
+
value = float(value)
|
| 106 |
+
|
| 107 |
+
elif isinstance(converter, Struct):
|
| 108 |
+
if converter.repeat:
|
| 109 |
+
if _isNonStrSequence(value):
|
| 110 |
+
value = [self.build(converter.tableClass, v) for v in value]
|
| 111 |
+
else:
|
| 112 |
+
value = [self.build(converter.tableClass, value)]
|
| 113 |
+
setattr(dest, converter.repeat, len(value))
|
| 114 |
+
else:
|
| 115 |
+
value = self.build(converter.tableClass, value)
|
| 116 |
+
elif callable(converter):
|
| 117 |
+
value = converter(value)
|
| 118 |
+
|
| 119 |
+
setattr(dest, field, value)
|
| 120 |
+
|
| 121 |
+
def build(self, cls, source):
|
| 122 |
+
assert issubclass(cls, BaseTable)
|
| 123 |
+
|
| 124 |
+
if isinstance(source, cls):
|
| 125 |
+
return source
|
| 126 |
+
|
| 127 |
+
callbackKey = (cls,)
|
| 128 |
+
fmt = None
|
| 129 |
+
if issubclass(cls, FormatSwitchingBaseTable):
|
| 130 |
+
fmt, source = _split_format(cls, source)
|
| 131 |
+
callbackKey = (cls, fmt)
|
| 132 |
+
|
| 133 |
+
dest = self._callbackTable.get(
|
| 134 |
+
(BuildCallback.CREATE_DEFAULT,) + callbackKey, lambda: cls()
|
| 135 |
+
)()
|
| 136 |
+
assert isinstance(dest, cls)
|
| 137 |
+
|
| 138 |
+
convByName = _assignable(cls.convertersByName)
|
| 139 |
+
skippedFields = set()
|
| 140 |
+
|
| 141 |
+
# For format switchers we need to resolve converters based on format
|
| 142 |
+
if issubclass(cls, FormatSwitchingBaseTable):
|
| 143 |
+
dest.Format = fmt
|
| 144 |
+
convByName = _assignable(convByName[dest.Format])
|
| 145 |
+
skippedFields.add("Format")
|
| 146 |
+
|
| 147 |
+
# Convert sequence => mapping so before thunk only has to handle one format
|
| 148 |
+
if _isNonStrSequence(source):
|
| 149 |
+
# Sequence (typically list or tuple) assumed to match fields in declaration order
|
| 150 |
+
assert len(source) <= len(
|
| 151 |
+
convByName
|
| 152 |
+
), f"Sequence of {len(source)} too long for {cls}; expected <= {len(convByName)} values"
|
| 153 |
+
source = dict(zip(convByName.keys(), source))
|
| 154 |
+
|
| 155 |
+
dest, source = self._callbackTable.get(
|
| 156 |
+
(BuildCallback.BEFORE_BUILD,) + callbackKey, lambda d, s: (d, s)
|
| 157 |
+
)(dest, source)
|
| 158 |
+
|
| 159 |
+
if isinstance(source, collections.abc.Mapping):
|
| 160 |
+
for field, value in source.items():
|
| 161 |
+
if field in skippedFields:
|
| 162 |
+
continue
|
| 163 |
+
converter = convByName.get(field, None)
|
| 164 |
+
if not converter:
|
| 165 |
+
raise ValueError(
|
| 166 |
+
f"Unrecognized field {field} for {cls}; expected one of {sorted(convByName.keys())}"
|
| 167 |
+
)
|
| 168 |
+
self._convert(dest, field, converter, value)
|
| 169 |
+
else:
|
| 170 |
+
# let's try as a 1-tuple
|
| 171 |
+
dest = self.build(cls, (source,))
|
| 172 |
+
|
| 173 |
+
for field, conv in convByName.items():
|
| 174 |
+
if not hasattr(dest, field) and isinstance(conv, OptionalValue):
|
| 175 |
+
setattr(dest, field, conv.DEFAULT)
|
| 176 |
+
|
| 177 |
+
dest = self._callbackTable.get(
|
| 178 |
+
(BuildCallback.AFTER_BUILD,) + callbackKey, lambda d: d
|
| 179 |
+
)(dest)
|
| 180 |
+
|
| 181 |
+
return dest
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class TableUnbuilder:
|
| 185 |
+
def __init__(self, callbackTable=None):
|
| 186 |
+
if callbackTable is None:
|
| 187 |
+
callbackTable = {}
|
| 188 |
+
self._callbackTable = callbackTable
|
| 189 |
+
|
| 190 |
+
def unbuild(self, table):
|
| 191 |
+
assert isinstance(table, BaseTable)
|
| 192 |
+
|
| 193 |
+
source = {}
|
| 194 |
+
|
| 195 |
+
callbackKey = (type(table),)
|
| 196 |
+
if isinstance(table, FormatSwitchingBaseTable):
|
| 197 |
+
source["Format"] = int(table.Format)
|
| 198 |
+
callbackKey += (table.Format,)
|
| 199 |
+
|
| 200 |
+
for converter in table.getConverters():
|
| 201 |
+
if isinstance(converter, ComputedInt):
|
| 202 |
+
continue
|
| 203 |
+
value = getattr(table, converter.name)
|
| 204 |
+
|
| 205 |
+
enumClass = getattr(converter, "enumClass", None)
|
| 206 |
+
if enumClass:
|
| 207 |
+
source[converter.name] = value.name.lower()
|
| 208 |
+
elif isinstance(converter, Struct):
|
| 209 |
+
if converter.repeat:
|
| 210 |
+
source[converter.name] = [self.unbuild(v) for v in value]
|
| 211 |
+
else:
|
| 212 |
+
source[converter.name] = self.unbuild(value)
|
| 213 |
+
elif isinstance(converter, SimpleValue):
|
| 214 |
+
# "simple" values (e.g. int, float, str) need no further un-building
|
| 215 |
+
source[converter.name] = value
|
| 216 |
+
else:
|
| 217 |
+
raise NotImplementedError(
|
| 218 |
+
"Don't know how unbuild {value!r} with {converter!r}"
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
source = self._callbackTable.get(callbackKey, lambda s: s)(source)
|
| 222 |
+
|
| 223 |
+
return source
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/colorLib/unbuilder.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.ttLib.tables import otTables as ot
|
| 2 |
+
from .table_builder import TableUnbuilder
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def unbuildColrV1(layerList, baseGlyphList):
|
| 6 |
+
layers = []
|
| 7 |
+
if layerList:
|
| 8 |
+
layers = layerList.Paint
|
| 9 |
+
unbuilder = LayerListUnbuilder(layers)
|
| 10 |
+
return {
|
| 11 |
+
rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)
|
| 12 |
+
for rec in baseGlyphList.BaseGlyphPaintRecord
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _flatten_layers(lst):
|
| 17 |
+
for paint in lst:
|
| 18 |
+
if paint["Format"] == ot.PaintFormat.PaintColrLayers:
|
| 19 |
+
yield from _flatten_layers(paint["Layers"])
|
| 20 |
+
else:
|
| 21 |
+
yield paint
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class LayerListUnbuilder:
|
| 25 |
+
def __init__(self, layers):
|
| 26 |
+
self.layers = layers
|
| 27 |
+
|
| 28 |
+
callbacks = {
|
| 29 |
+
(
|
| 30 |
+
ot.Paint,
|
| 31 |
+
ot.PaintFormat.PaintColrLayers,
|
| 32 |
+
): self._unbuildPaintColrLayers,
|
| 33 |
+
}
|
| 34 |
+
self.tableUnbuilder = TableUnbuilder(callbacks)
|
| 35 |
+
|
| 36 |
+
def unbuildPaint(self, paint):
|
| 37 |
+
assert isinstance(paint, ot.Paint)
|
| 38 |
+
return self.tableUnbuilder.unbuild(paint)
|
| 39 |
+
|
| 40 |
+
def _unbuildPaintColrLayers(self, source):
|
| 41 |
+
assert source["Format"] == ot.PaintFormat.PaintColrLayers
|
| 42 |
+
|
| 43 |
+
layers = list(
|
| 44 |
+
_flatten_layers(
|
| 45 |
+
[
|
| 46 |
+
self.unbuildPaint(childPaint)
|
| 47 |
+
for childPaint in self.layers[
|
| 48 |
+
source["FirstLayerIndex"] : source["FirstLayerIndex"]
|
| 49 |
+
+ source["NumLayers"]
|
| 50 |
+
]
|
| 51 |
+
]
|
| 52 |
+
)
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
if len(layers) == 1:
|
| 56 |
+
return layers[0]
|
| 57 |
+
|
| 58 |
+
return {"Format": source["Format"], "Layers": layers}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
from pprint import pprint
|
| 63 |
+
import sys
|
| 64 |
+
from fontTools.ttLib import TTFont
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
fontfile = sys.argv[1]
|
| 68 |
+
except IndexError:
|
| 69 |
+
sys.exit("usage: fonttools colorLib.unbuilder FONTFILE")
|
| 70 |
+
|
| 71 |
+
font = TTFont(fontfile)
|
| 72 |
+
colr = font["COLR"]
|
| 73 |
+
if colr.version < 1:
|
| 74 |
+
sys.exit(f"error: No COLR table version=1 found in {fontfile}")
|
| 75 |
+
|
| 76 |
+
colorGlyphs = unbuildColrV1(
|
| 77 |
+
colr.table.LayerList,
|
| 78 |
+
colr.table.BaseGlyphList,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
pprint(colorGlyphs)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/config/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Define all configuration options that can affect the working of fontTools
|
| 3 |
+
modules. E.g. optimization levels of varLib IUP, otlLib GPOS compression level,
|
| 4 |
+
etc. If this file gets too big, split it into smaller files per-module.
|
| 5 |
+
|
| 6 |
+
An instance of the Config class can be attached to a TTFont object, so that
|
| 7 |
+
the various modules can access their configuration options from it.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from textwrap import dedent
|
| 11 |
+
|
| 12 |
+
from fontTools.misc.configTools import *
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class Config(AbstractConfig):
|
| 16 |
+
options = Options()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
OPTIONS = Config.options
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Config.register_option(
|
| 23 |
+
name="fontTools.otlLib.optimize.gpos:COMPRESSION_LEVEL",
|
| 24 |
+
help=dedent(
|
| 25 |
+
"""\
|
| 26 |
+
GPOS Lookup type 2 (PairPos) compression level:
|
| 27 |
+
0 = do not attempt to compact PairPos lookups;
|
| 28 |
+
1 to 8 = create at most 1 to 8 new subtables for each existing
|
| 29 |
+
subtable, provided that it would yield a 50%% file size saving;
|
| 30 |
+
9 = create as many new subtables as needed to yield a file size saving.
|
| 31 |
+
Default: 0.
|
| 32 |
+
|
| 33 |
+
This compaction aims to save file size, by splitting large class
|
| 34 |
+
kerning subtables (Format 2) that contain many zero values into
|
| 35 |
+
smaller and denser subtables. It's a trade-off between the overhead
|
| 36 |
+
of several subtables versus the sparseness of one big subtable.
|
| 37 |
+
|
| 38 |
+
See the pull request: https://github.com/fonttools/fonttools/pull/2326
|
| 39 |
+
"""
|
| 40 |
+
),
|
| 41 |
+
default=0,
|
| 42 |
+
parse=int,
|
| 43 |
+
validate=lambda v: v in range(10),
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
Config.register_option(
|
| 47 |
+
name="fontTools.ttLib.tables.otBase:USE_HARFBUZZ_REPACKER",
|
| 48 |
+
help=dedent(
|
| 49 |
+
"""\
|
| 50 |
+
FontTools tries to use the HarfBuzz Repacker to serialize GPOS/GSUB tables
|
| 51 |
+
if the uharfbuzz python bindings are importable, otherwise falls back to its
|
| 52 |
+
slower, less efficient serializer. Set to False to always use the latter.
|
| 53 |
+
Set to True to explicitly request the HarfBuzz Repacker (will raise an
|
| 54 |
+
error if uharfbuzz cannot be imported).
|
| 55 |
+
"""
|
| 56 |
+
),
|
| 57 |
+
default=None,
|
| 58 |
+
parse=Option.parse_optional_bool,
|
| 59 |
+
validate=Option.validate_optional_bool,
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
Config.register_option(
|
| 63 |
+
name="fontTools.otlLib.builder:WRITE_GPOS7",
|
| 64 |
+
help=dedent(
|
| 65 |
+
"""\
|
| 66 |
+
macOS before 13.2 didn’t support GPOS LookupType 7 (non-chaining
|
| 67 |
+
ContextPos lookups), so FontTools.otlLib.builder disables a file size
|
| 68 |
+
optimisation that would use LookupType 7 instead of 8 when there is no
|
| 69 |
+
chaining (no prefix or suffix). Set to True to enable the optimization.
|
| 70 |
+
"""
|
| 71 |
+
),
|
| 72 |
+
default=False,
|
| 73 |
+
parse=Option.parse_optional_bool,
|
| 74 |
+
validate=Option.validate_optional_bool,
|
| 75 |
+
)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/cu2qu/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (289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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import argparse
|
| 3 |
+
import logging
|
| 4 |
+
import shutil
|
| 5 |
+
import multiprocessing as mp
|
| 6 |
+
from contextlib import closing
|
| 7 |
+
from functools import partial
|
| 8 |
+
|
| 9 |
+
import fontTools
|
| 10 |
+
from .ufo import font_to_quadratic, fonts_to_quadratic
|
| 11 |
+
|
| 12 |
+
ufo_module = None
|
| 13 |
+
try:
|
| 14 |
+
import ufoLib2 as ufo_module
|
| 15 |
+
except ImportError:
|
| 16 |
+
try:
|
| 17 |
+
import defcon as ufo_module
|
| 18 |
+
except ImportError as e:
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
logger = logging.getLogger("fontTools.cu2qu")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _cpu_count():
|
| 26 |
+
try:
|
| 27 |
+
return mp.cpu_count()
|
| 28 |
+
except NotImplementedError: # pragma: no cover
|
| 29 |
+
return 1
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def open_ufo(path):
|
| 33 |
+
if hasattr(ufo_module.Font, "open"): # ufoLib2
|
| 34 |
+
return ufo_module.Font.open(path)
|
| 35 |
+
return ufo_module.Font(path) # defcon
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _font_to_quadratic(input_path, output_path=None, **kwargs):
|
| 39 |
+
ufo = open_ufo(input_path)
|
| 40 |
+
logger.info("Converting curves for %s", input_path)
|
| 41 |
+
if font_to_quadratic(ufo, **kwargs):
|
| 42 |
+
logger.info("Saving %s", output_path)
|
| 43 |
+
if output_path:
|
| 44 |
+
ufo.save(output_path)
|
| 45 |
+
else:
|
| 46 |
+
ufo.save() # save in-place
|
| 47 |
+
elif output_path:
|
| 48 |
+
_copytree(input_path, output_path)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _samepath(path1, path2):
|
| 52 |
+
# TODO on python3+, there's os.path.samefile
|
| 53 |
+
path1 = os.path.normcase(os.path.abspath(os.path.realpath(path1)))
|
| 54 |
+
path2 = os.path.normcase(os.path.abspath(os.path.realpath(path2)))
|
| 55 |
+
return path1 == path2
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _copytree(input_path, output_path):
|
| 59 |
+
if _samepath(input_path, output_path):
|
| 60 |
+
logger.debug("input and output paths are the same file; skipped copy")
|
| 61 |
+
return
|
| 62 |
+
if os.path.exists(output_path):
|
| 63 |
+
shutil.rmtree(output_path)
|
| 64 |
+
shutil.copytree(input_path, output_path)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _main(args=None):
|
| 68 |
+
"""Convert a UFO font from cubic to quadratic curves"""
|
| 69 |
+
parser = argparse.ArgumentParser(prog="cu2qu")
|
| 70 |
+
parser.add_argument("--version", action="version", version=fontTools.__version__)
|
| 71 |
+
parser.add_argument(
|
| 72 |
+
"infiles",
|
| 73 |
+
nargs="+",
|
| 74 |
+
metavar="INPUT",
|
| 75 |
+
help="one or more input UFO source file(s).",
|
| 76 |
+
)
|
| 77 |
+
parser.add_argument("-v", "--verbose", action="count", default=0)
|
| 78 |
+
parser.add_argument(
|
| 79 |
+
"-e",
|
| 80 |
+
"--conversion-error",
|
| 81 |
+
type=float,
|
| 82 |
+
metavar="ERROR",
|
| 83 |
+
default=None,
|
| 84 |
+
help="maxiumum approximation error measured in EM (default: 0.001)",
|
| 85 |
+
)
|
| 86 |
+
parser.add_argument(
|
| 87 |
+
"-m",
|
| 88 |
+
"--mixed",
|
| 89 |
+
default=False,
|
| 90 |
+
action="store_true",
|
| 91 |
+
help="whether to used mixed quadratic and cubic curves",
|
| 92 |
+
)
|
| 93 |
+
parser.add_argument(
|
| 94 |
+
"--keep-direction",
|
| 95 |
+
dest="reverse_direction",
|
| 96 |
+
action="store_false",
|
| 97 |
+
help="do not reverse the contour direction",
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
mode_parser = parser.add_mutually_exclusive_group()
|
| 101 |
+
mode_parser.add_argument(
|
| 102 |
+
"-i",
|
| 103 |
+
"--interpolatable",
|
| 104 |
+
action="store_true",
|
| 105 |
+
help="whether curve conversion should keep interpolation compatibility",
|
| 106 |
+
)
|
| 107 |
+
mode_parser.add_argument(
|
| 108 |
+
"-j",
|
| 109 |
+
"--jobs",
|
| 110 |
+
type=int,
|
| 111 |
+
nargs="?",
|
| 112 |
+
default=1,
|
| 113 |
+
const=_cpu_count(),
|
| 114 |
+
metavar="N",
|
| 115 |
+
help="Convert using N multiple processes (default: %(default)s)",
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
output_parser = parser.add_mutually_exclusive_group()
|
| 119 |
+
output_parser.add_argument(
|
| 120 |
+
"-o",
|
| 121 |
+
"--output-file",
|
| 122 |
+
default=None,
|
| 123 |
+
metavar="OUTPUT",
|
| 124 |
+
help=(
|
| 125 |
+
"output filename for the converted UFO. By default fonts are "
|
| 126 |
+
"modified in place. This only works with a single input."
|
| 127 |
+
),
|
| 128 |
+
)
|
| 129 |
+
output_parser.add_argument(
|
| 130 |
+
"-d",
|
| 131 |
+
"--output-dir",
|
| 132 |
+
default=None,
|
| 133 |
+
metavar="DIRECTORY",
|
| 134 |
+
help="output directory where to save converted UFOs",
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
options = parser.parse_args(args)
|
| 138 |
+
|
| 139 |
+
if ufo_module is None:
|
| 140 |
+
parser.error("Either ufoLib2 or defcon are required to run this script.")
|
| 141 |
+
|
| 142 |
+
if not options.verbose:
|
| 143 |
+
level = "WARNING"
|
| 144 |
+
elif options.verbose == 1:
|
| 145 |
+
level = "INFO"
|
| 146 |
+
else:
|
| 147 |
+
level = "DEBUG"
|
| 148 |
+
logging.basicConfig(level=level)
|
| 149 |
+
|
| 150 |
+
if len(options.infiles) > 1 and options.output_file:
|
| 151 |
+
parser.error("-o/--output-file can't be used with multile inputs")
|
| 152 |
+
|
| 153 |
+
if options.output_dir:
|
| 154 |
+
output_dir = options.output_dir
|
| 155 |
+
if not os.path.exists(output_dir):
|
| 156 |
+
os.mkdir(output_dir)
|
| 157 |
+
elif not os.path.isdir(output_dir):
|
| 158 |
+
parser.error("'%s' is not a directory" % output_dir)
|
| 159 |
+
output_paths = [
|
| 160 |
+
os.path.join(output_dir, os.path.basename(p)) for p in options.infiles
|
| 161 |
+
]
|
| 162 |
+
elif options.output_file:
|
| 163 |
+
output_paths = [options.output_file]
|
| 164 |
+
else:
|
| 165 |
+
# save in-place
|
| 166 |
+
output_paths = [None] * len(options.infiles)
|
| 167 |
+
|
| 168 |
+
kwargs = dict(
|
| 169 |
+
dump_stats=options.verbose > 0,
|
| 170 |
+
max_err_em=options.conversion_error,
|
| 171 |
+
reverse_direction=options.reverse_direction,
|
| 172 |
+
all_quadratic=False if options.mixed else True,
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
if options.interpolatable:
|
| 176 |
+
logger.info("Converting curves compatibly")
|
| 177 |
+
ufos = [open_ufo(infile) for infile in options.infiles]
|
| 178 |
+
if fonts_to_quadratic(ufos, **kwargs):
|
| 179 |
+
for ufo, output_path in zip(ufos, output_paths):
|
| 180 |
+
logger.info("Saving %s", output_path)
|
| 181 |
+
if output_path:
|
| 182 |
+
ufo.save(output_path)
|
| 183 |
+
else:
|
| 184 |
+
ufo.save()
|
| 185 |
+
else:
|
| 186 |
+
for input_path, output_path in zip(options.infiles, output_paths):
|
| 187 |
+
if output_path:
|
| 188 |
+
_copytree(input_path, output_path)
|
| 189 |
+
else:
|
| 190 |
+
jobs = min(len(options.infiles), options.jobs) if options.jobs > 1 else 1
|
| 191 |
+
if jobs > 1:
|
| 192 |
+
func = partial(_font_to_quadratic, **kwargs)
|
| 193 |
+
logger.info("Running %d parallel processes", jobs)
|
| 194 |
+
with closing(mp.Pool(jobs)) as pool:
|
| 195 |
+
pool.starmap(func, zip(options.infiles, output_paths))
|
| 196 |
+
else:
|
| 197 |
+
for input_path, output_path in zip(options.infiles, output_paths):
|
| 198 |
+
_font_to_quadratic(input_path, output_path, **kwargs)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/designspaceLib/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (81.5 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/designspaceLib/__pycache__/statNames.cpython-310.pyc
ADDED
|
Binary file (6.19 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/StandardEncoding.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 4 |
+
".notdef",
|
| 5 |
+
".notdef",
|
| 6 |
+
".notdef",
|
| 7 |
+
".notdef",
|
| 8 |
+
".notdef",
|
| 9 |
+
".notdef",
|
| 10 |
+
".notdef",
|
| 11 |
+
".notdef",
|
| 12 |
+
".notdef",
|
| 13 |
+
".notdef",
|
| 14 |
+
".notdef",
|
| 15 |
+
".notdef",
|
| 16 |
+
".notdef",
|
| 17 |
+
".notdef",
|
| 18 |
+
".notdef",
|
| 19 |
+
".notdef",
|
| 20 |
+
".notdef",
|
| 21 |
+
".notdef",
|
| 22 |
+
".notdef",
|
| 23 |
+
".notdef",
|
| 24 |
+
".notdef",
|
| 25 |
+
".notdef",
|
| 26 |
+
".notdef",
|
| 27 |
+
".notdef",
|
| 28 |
+
".notdef",
|
| 29 |
+
".notdef",
|
| 30 |
+
".notdef",
|
| 31 |
+
".notdef",
|
| 32 |
+
".notdef",
|
| 33 |
+
".notdef",
|
| 34 |
+
"space",
|
| 35 |
+
"exclam",
|
| 36 |
+
"quotedbl",
|
| 37 |
+
"numbersign",
|
| 38 |
+
"dollar",
|
| 39 |
+
"percent",
|
| 40 |
+
"ampersand",
|
| 41 |
+
"quoteright",
|
| 42 |
+
"parenleft",
|
| 43 |
+
"parenright",
|
| 44 |
+
"asterisk",
|
| 45 |
+
"plus",
|
| 46 |
+
"comma",
|
| 47 |
+
"hyphen",
|
| 48 |
+
"period",
|
| 49 |
+
"slash",
|
| 50 |
+
"zero",
|
| 51 |
+
"one",
|
| 52 |
+
"two",
|
| 53 |
+
"three",
|
| 54 |
+
"four",
|
| 55 |
+
"five",
|
| 56 |
+
"six",
|
| 57 |
+
"seven",
|
| 58 |
+
"eight",
|
| 59 |
+
"nine",
|
| 60 |
+
"colon",
|
| 61 |
+
"semicolon",
|
| 62 |
+
"less",
|
| 63 |
+
"equal",
|
| 64 |
+
"greater",
|
| 65 |
+
"question",
|
| 66 |
+
"at",
|
| 67 |
+
"A",
|
| 68 |
+
"B",
|
| 69 |
+
"C",
|
| 70 |
+
"D",
|
| 71 |
+
"E",
|
| 72 |
+
"F",
|
| 73 |
+
"G",
|
| 74 |
+
"H",
|
| 75 |
+
"I",
|
| 76 |
+
"J",
|
| 77 |
+
"K",
|
| 78 |
+
"L",
|
| 79 |
+
"M",
|
| 80 |
+
"N",
|
| 81 |
+
"O",
|
| 82 |
+
"P",
|
| 83 |
+
"Q",
|
| 84 |
+
"R",
|
| 85 |
+
"S",
|
| 86 |
+
"T",
|
| 87 |
+
"U",
|
| 88 |
+
"V",
|
| 89 |
+
"W",
|
| 90 |
+
"X",
|
| 91 |
+
"Y",
|
| 92 |
+
"Z",
|
| 93 |
+
"bracketleft",
|
| 94 |
+
"backslash",
|
| 95 |
+
"bracketright",
|
| 96 |
+
"asciicircum",
|
| 97 |
+
"underscore",
|
| 98 |
+
"quoteleft",
|
| 99 |
+
"a",
|
| 100 |
+
"b",
|
| 101 |
+
"c",
|
| 102 |
+
"d",
|
| 103 |
+
"e",
|
| 104 |
+
"f",
|
| 105 |
+
"g",
|
| 106 |
+
"h",
|
| 107 |
+
"i",
|
| 108 |
+
"j",
|
| 109 |
+
"k",
|
| 110 |
+
"l",
|
| 111 |
+
"m",
|
| 112 |
+
"n",
|
| 113 |
+
"o",
|
| 114 |
+
"p",
|
| 115 |
+
"q",
|
| 116 |
+
"r",
|
| 117 |
+
"s",
|
| 118 |
+
"t",
|
| 119 |
+
"u",
|
| 120 |
+
"v",
|
| 121 |
+
"w",
|
| 122 |
+
"x",
|
| 123 |
+
"y",
|
| 124 |
+
"z",
|
| 125 |
+
"braceleft",
|
| 126 |
+
"bar",
|
| 127 |
+
"braceright",
|
| 128 |
+
"asciitilde",
|
| 129 |
+
".notdef",
|
| 130 |
+
".notdef",
|
| 131 |
+
".notdef",
|
| 132 |
+
".notdef",
|
| 133 |
+
".notdef",
|
| 134 |
+
".notdef",
|
| 135 |
+
".notdef",
|
| 136 |
+
".notdef",
|
| 137 |
+
".notdef",
|
| 138 |
+
".notdef",
|
| 139 |
+
".notdef",
|
| 140 |
+
".notdef",
|
| 141 |
+
".notdef",
|
| 142 |
+
".notdef",
|
| 143 |
+
".notdef",
|
| 144 |
+
".notdef",
|
| 145 |
+
".notdef",
|
| 146 |
+
".notdef",
|
| 147 |
+
".notdef",
|
| 148 |
+
".notdef",
|
| 149 |
+
".notdef",
|
| 150 |
+
".notdef",
|
| 151 |
+
".notdef",
|
| 152 |
+
".notdef",
|
| 153 |
+
".notdef",
|
| 154 |
+
".notdef",
|
| 155 |
+
".notdef",
|
| 156 |
+
".notdef",
|
| 157 |
+
".notdef",
|
| 158 |
+
".notdef",
|
| 159 |
+
".notdef",
|
| 160 |
+
".notdef",
|
| 161 |
+
".notdef",
|
| 162 |
+
".notdef",
|
| 163 |
+
"exclamdown",
|
| 164 |
+
"cent",
|
| 165 |
+
"sterling",
|
| 166 |
+
"fraction",
|
| 167 |
+
"yen",
|
| 168 |
+
"florin",
|
| 169 |
+
"section",
|
| 170 |
+
"currency",
|
| 171 |
+
"quotesingle",
|
| 172 |
+
"quotedblleft",
|
| 173 |
+
"guillemotleft",
|
| 174 |
+
"guilsinglleft",
|
| 175 |
+
"guilsinglright",
|
| 176 |
+
"fi",
|
| 177 |
+
"fl",
|
| 178 |
+
".notdef",
|
| 179 |
+
"endash",
|
| 180 |
+
"dagger",
|
| 181 |
+
"daggerdbl",
|
| 182 |
+
"periodcentered",
|
| 183 |
+
".notdef",
|
| 184 |
+
"paragraph",
|
| 185 |
+
"bullet",
|
| 186 |
+
"quotesinglbase",
|
| 187 |
+
"quotedblbase",
|
| 188 |
+
"quotedblright",
|
| 189 |
+
"guillemotright",
|
| 190 |
+
"ellipsis",
|
| 191 |
+
"perthousand",
|
| 192 |
+
".notdef",
|
| 193 |
+
"questiondown",
|
| 194 |
+
".notdef",
|
| 195 |
+
"grave",
|
| 196 |
+
"acute",
|
| 197 |
+
"circumflex",
|
| 198 |
+
"tilde",
|
| 199 |
+
"macron",
|
| 200 |
+
"breve",
|
| 201 |
+
"dotaccent",
|
| 202 |
+
"dieresis",
|
| 203 |
+
".notdef",
|
| 204 |
+
"ring",
|
| 205 |
+
"cedilla",
|
| 206 |
+
".notdef",
|
| 207 |
+
"hungarumlaut",
|
| 208 |
+
"ogonek",
|
| 209 |
+
"caron",
|
| 210 |
+
"emdash",
|
| 211 |
+
".notdef",
|
| 212 |
+
".notdef",
|
| 213 |
+
".notdef",
|
| 214 |
+
".notdef",
|
| 215 |
+
".notdef",
|
| 216 |
+
".notdef",
|
| 217 |
+
".notdef",
|
| 218 |
+
".notdef",
|
| 219 |
+
".notdef",
|
| 220 |
+
".notdef",
|
| 221 |
+
".notdef",
|
| 222 |
+
".notdef",
|
| 223 |
+
".notdef",
|
| 224 |
+
".notdef",
|
| 225 |
+
".notdef",
|
| 226 |
+
".notdef",
|
| 227 |
+
"AE",
|
| 228 |
+
".notdef",
|
| 229 |
+
"ordfeminine",
|
| 230 |
+
".notdef",
|
| 231 |
+
".notdef",
|
| 232 |
+
".notdef",
|
| 233 |
+
".notdef",
|
| 234 |
+
"Lslash",
|
| 235 |
+
"Oslash",
|
| 236 |
+
"OE",
|
| 237 |
+
"ordmasculine",
|
| 238 |
+
".notdef",
|
| 239 |
+
".notdef",
|
| 240 |
+
".notdef",
|
| 241 |
+
".notdef",
|
| 242 |
+
".notdef",
|
| 243 |
+
"ae",
|
| 244 |
+
".notdef",
|
| 245 |
+
".notdef",
|
| 246 |
+
".notdef",
|
| 247 |
+
"dotlessi",
|
| 248 |
+
".notdef",
|
| 249 |
+
".notdef",
|
| 250 |
+
"lslash",
|
| 251 |
+
"oslash",
|
| 252 |
+
"oe",
|
| 253 |
+
"germandbls",
|
| 254 |
+
".notdef",
|
| 255 |
+
".notdef",
|
| 256 |
+
".notdef",
|
| 257 |
+
".notdef",
|
| 258 |
+
]
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Empty __init__.py file to signal Python this directory is a package."""
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__pycache__/StandardEncoding.cpython-310.pyc
ADDED
|
Binary file (1.81 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (258 Bytes). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/encodings/codecs.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extend the Python codecs module with a few encodings that are used in OpenType (name table)
|
| 2 |
+
but missing from Python. See https://github.com/fonttools/fonttools/issues/236 for details."""
|
| 3 |
+
|
| 4 |
+
import codecs
|
| 5 |
+
import encodings
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ExtendCodec(codecs.Codec):
|
| 9 |
+
def __init__(self, name, base_encoding, mapping):
|
| 10 |
+
self.name = name
|
| 11 |
+
self.base_encoding = base_encoding
|
| 12 |
+
self.mapping = mapping
|
| 13 |
+
self.reverse = {v: k for k, v in mapping.items()}
|
| 14 |
+
self.max_len = max(len(v) for v in mapping.values())
|
| 15 |
+
self.info = codecs.CodecInfo(
|
| 16 |
+
name=self.name, encode=self.encode, decode=self.decode
|
| 17 |
+
)
|
| 18 |
+
codecs.register_error(name, self.error)
|
| 19 |
+
|
| 20 |
+
def _map(self, mapper, output_type, exc_type, input, errors):
|
| 21 |
+
base_error_handler = codecs.lookup_error(errors)
|
| 22 |
+
length = len(input)
|
| 23 |
+
out = output_type()
|
| 24 |
+
while input:
|
| 25 |
+
# first try to use self.error as the error handler
|
| 26 |
+
try:
|
| 27 |
+
part = mapper(input, self.base_encoding, errors=self.name)
|
| 28 |
+
out += part
|
| 29 |
+
break # All converted
|
| 30 |
+
except exc_type as e:
|
| 31 |
+
# else convert the correct part, handle error as requested and continue
|
| 32 |
+
out += mapper(input[: e.start], self.base_encoding, self.name)
|
| 33 |
+
replacement, pos = base_error_handler(e)
|
| 34 |
+
out += replacement
|
| 35 |
+
input = input[pos:]
|
| 36 |
+
return out, length
|
| 37 |
+
|
| 38 |
+
def encode(self, input, errors="strict"):
|
| 39 |
+
return self._map(codecs.encode, bytes, UnicodeEncodeError, input, errors)
|
| 40 |
+
|
| 41 |
+
def decode(self, input, errors="strict"):
|
| 42 |
+
return self._map(codecs.decode, str, UnicodeDecodeError, input, errors)
|
| 43 |
+
|
| 44 |
+
def error(self, e):
|
| 45 |
+
if isinstance(e, UnicodeDecodeError):
|
| 46 |
+
for end in range(e.start + 1, e.end + 1):
|
| 47 |
+
s = e.object[e.start : end]
|
| 48 |
+
if s in self.mapping:
|
| 49 |
+
return self.mapping[s], end
|
| 50 |
+
elif isinstance(e, UnicodeEncodeError):
|
| 51 |
+
for end in range(e.start + 1, e.start + self.max_len + 1):
|
| 52 |
+
s = e.object[e.start : end]
|
| 53 |
+
if s in self.reverse:
|
| 54 |
+
return self.reverse[s], end
|
| 55 |
+
e.encoding = self.name
|
| 56 |
+
raise e
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
_extended_encodings = {
|
| 60 |
+
"x_mac_japanese_ttx": (
|
| 61 |
+
"shift_jis",
|
| 62 |
+
{
|
| 63 |
+
b"\xFC": chr(0x007C),
|
| 64 |
+
b"\x7E": chr(0x007E),
|
| 65 |
+
b"\x80": chr(0x005C),
|
| 66 |
+
b"\xA0": chr(0x00A0),
|
| 67 |
+
b"\xFD": chr(0x00A9),
|
| 68 |
+
b"\xFE": chr(0x2122),
|
| 69 |
+
b"\xFF": chr(0x2026),
|
| 70 |
+
},
|
| 71 |
+
),
|
| 72 |
+
"x_mac_trad_chinese_ttx": (
|
| 73 |
+
"big5",
|
| 74 |
+
{
|
| 75 |
+
b"\x80": chr(0x005C),
|
| 76 |
+
b"\xA0": chr(0x00A0),
|
| 77 |
+
b"\xFD": chr(0x00A9),
|
| 78 |
+
b"\xFE": chr(0x2122),
|
| 79 |
+
b"\xFF": chr(0x2026),
|
| 80 |
+
},
|
| 81 |
+
),
|
| 82 |
+
"x_mac_korean_ttx": (
|
| 83 |
+
"euc_kr",
|
| 84 |
+
{
|
| 85 |
+
b"\x80": chr(0x00A0),
|
| 86 |
+
b"\x81": chr(0x20A9),
|
| 87 |
+
b"\x82": chr(0x2014),
|
| 88 |
+
b"\x83": chr(0x00A9),
|
| 89 |
+
b"\xFE": chr(0x2122),
|
| 90 |
+
b"\xFF": chr(0x2026),
|
| 91 |
+
},
|
| 92 |
+
),
|
| 93 |
+
"x_mac_simp_chinese_ttx": (
|
| 94 |
+
"gb2312",
|
| 95 |
+
{
|
| 96 |
+
b"\x80": chr(0x00FC),
|
| 97 |
+
b"\xA0": chr(0x00A0),
|
| 98 |
+
b"\xFD": chr(0x00A9),
|
| 99 |
+
b"\xFE": chr(0x2122),
|
| 100 |
+
b"\xFF": chr(0x2026),
|
| 101 |
+
},
|
| 102 |
+
),
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
_cache = {}
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def search_function(name):
|
| 109 |
+
name = encodings.normalize_encoding(name) # Rather undocumented...
|
| 110 |
+
if name in _extended_encodings:
|
| 111 |
+
if name not in _cache:
|
| 112 |
+
base_encoding, mapping = _extended_encodings[name]
|
| 113 |
+
assert name[-4:] == "_ttx"
|
| 114 |
+
# Python 2 didn't have any of the encodings that we are implementing
|
| 115 |
+
# in this file. Python 3 added aliases for the East Asian ones, mapping
|
| 116 |
+
# them "temporarily" to the same base encoding as us, with a comment
|
| 117 |
+
# suggesting that full implementation will appear some time later.
|
| 118 |
+
# As such, try the Python version of the x_mac_... first, if that is found,
|
| 119 |
+
# use *that* as our base encoding. This would make our encoding upgrade
|
| 120 |
+
# to the full encoding when and if Python finally implements that.
|
| 121 |
+
# http://bugs.python.org/issue24041
|
| 122 |
+
base_encodings = [name[:-4], base_encoding]
|
| 123 |
+
for base_encoding in base_encodings:
|
| 124 |
+
try:
|
| 125 |
+
codecs.lookup(base_encoding)
|
| 126 |
+
except LookupError:
|
| 127 |
+
continue
|
| 128 |
+
_cache[name] = ExtendCodec(name, base_encoding, mapping)
|
| 129 |
+
break
|
| 130 |
+
return _cache[name].info
|
| 131 |
+
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
codecs.register(search_function)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/feaLib/__pycache__/builder.cpython-310.pyc
ADDED
|
Binary file (47 kB). View file
|
|
|
ev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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2013 Google, Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Google Author(s): Behdad Esfahbod, Roozbeh Pournader
|
| 4 |
+
|
| 5 |
+
from fontTools import ttLib
|
| 6 |
+
import fontTools.merge.base
|
| 7 |
+
from fontTools.merge.cmap import (
|
| 8 |
+
computeMegaGlyphOrder,
|
| 9 |
+
computeMegaCmap,
|
| 10 |
+
renameCFFCharStrings,
|
| 11 |
+
)
|
| 12 |
+
from fontTools.merge.layout import layoutPreMerge, layoutPostMerge
|
| 13 |
+
from fontTools.merge.options import Options
|
| 14 |
+
import fontTools.merge.tables
|
| 15 |
+
from fontTools.misc.loggingTools import Timer
|
| 16 |
+
from functools import reduce
|
| 17 |
+
import sys
|
| 18 |
+
import logging
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
log = logging.getLogger("fontTools.merge")
|
| 22 |
+
timer = Timer(logger=logging.getLogger(__name__ + ".timer"), level=logging.INFO)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class Merger(object):
|
| 26 |
+
"""Font merger.
|
| 27 |
+
|
| 28 |
+
This class merges multiple files into a single OpenType font, taking into
|
| 29 |
+
account complexities such as OpenType layout (``GSUB``/``GPOS``) tables and
|
| 30 |
+
cross-font metrics (for example ``hhea.ascent`` is set to the maximum value
|
| 31 |
+
across all the fonts).
|
| 32 |
+
|
| 33 |
+
If multiple glyphs map to the same Unicode value, and the glyphs are considered
|
| 34 |
+
sufficiently different (that is, they differ in any of paths, widths, or
|
| 35 |
+
height), then subsequent glyphs are renamed and a lookup in the ``locl``
|
| 36 |
+
feature will be created to disambiguate them. For example, if the arguments
|
| 37 |
+
are an Arabic font and a Latin font and both contain a set of parentheses,
|
| 38 |
+
the Latin glyphs will be renamed to ``parenleft.1`` and ``parenright.1``,
|
| 39 |
+
and a lookup will be inserted into the to ``locl`` feature (creating it if
|
| 40 |
+
necessary) under the ``latn`` script to substitute ``parenleft`` with
|
| 41 |
+
``parenleft.1`` etc.
|
| 42 |
+
|
| 43 |
+
Restrictions:
|
| 44 |
+
|
| 45 |
+
- All fonts must have the same units per em.
|
| 46 |
+
- If duplicate glyph disambiguation takes place as described above then the
|
| 47 |
+
fonts must have a ``GSUB`` table.
|
| 48 |
+
|
| 49 |
+
Attributes:
|
| 50 |
+
options: Currently unused.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(self, options=None):
|
| 54 |
+
if not options:
|
| 55 |
+
options = Options()
|
| 56 |
+
|
| 57 |
+
self.options = options
|
| 58 |
+
|
| 59 |
+
def _openFonts(self, fontfiles):
|
| 60 |
+
fonts = [ttLib.TTFont(fontfile) for fontfile in fontfiles]
|
| 61 |
+
for font, fontfile in zip(fonts, fontfiles):
|
| 62 |
+
font._merger__fontfile = fontfile
|
| 63 |
+
font._merger__name = font["name"].getDebugName(4)
|
| 64 |
+
return fonts
|
| 65 |
+
|
| 66 |
+
def merge(self, fontfiles):
|
| 67 |
+
"""Merges fonts together.
|
| 68 |
+
|
| 69 |
+
Args:
|
| 70 |
+
fontfiles: A list of file names to be merged
|
| 71 |
+
|
| 72 |
+
Returns:
|
| 73 |
+
A :class:`fontTools.ttLib.TTFont` object. Call the ``save`` method on
|
| 74 |
+
this to write it out to an OTF file.
|
| 75 |
+
"""
|
| 76 |
+
#
|
| 77 |
+
# Settle on a mega glyph order.
|
| 78 |
+
#
|
| 79 |
+
fonts = self._openFonts(fontfiles)
|
| 80 |
+
glyphOrders = [list(font.getGlyphOrder()) for font in fonts]
|
| 81 |
+
computeMegaGlyphOrder(self, glyphOrders)
|
| 82 |
+
|
| 83 |
+
# Take first input file sfntVersion
|
| 84 |
+
sfntVersion = fonts[0].sfntVersion
|
| 85 |
+
|
| 86 |
+
# Reload fonts and set new glyph names on them.
|
| 87 |
+
fonts = self._openFonts(fontfiles)
|
| 88 |
+
for font, glyphOrder in zip(fonts, glyphOrders):
|
| 89 |
+
font.setGlyphOrder(glyphOrder)
|
| 90 |
+
if "CFF " in font:
|
| 91 |
+
renameCFFCharStrings(self, glyphOrder, font["CFF "])
|
| 92 |
+
|
| 93 |
+
cmaps = [font["cmap"] for font in fonts]
|
| 94 |
+
self.duplicateGlyphsPerFont = [{} for _ in fonts]
|
| 95 |
+
computeMegaCmap(self, cmaps)
|
| 96 |
+
|
| 97 |
+
mega = ttLib.TTFont(sfntVersion=sfntVersion)
|
| 98 |
+
mega.setGlyphOrder(self.glyphOrder)
|
| 99 |
+
|
| 100 |
+
for font in fonts:
|
| 101 |
+
self._preMerge(font)
|
| 102 |
+
|
| 103 |
+
self.fonts = fonts
|
| 104 |
+
|
| 105 |
+
allTags = reduce(set.union, (list(font.keys()) for font in fonts), set())
|
| 106 |
+
allTags.remove("GlyphOrder")
|
| 107 |
+
|
| 108 |
+
for tag in sorted(allTags):
|
| 109 |
+
if tag in self.options.drop_tables:
|
| 110 |
+
continue
|
| 111 |
+
|
| 112 |
+
with timer("merge '%s'" % tag):
|
| 113 |
+
tables = [font.get(tag, NotImplemented) for font in fonts]
|
| 114 |
+
|
| 115 |
+
log.info("Merging '%s'.", tag)
|
| 116 |
+
clazz = ttLib.getTableClass(tag)
|
| 117 |
+
table = clazz(tag).merge(self, tables)
|
| 118 |
+
# XXX Clean this up and use: table = mergeObjects(tables)
|
| 119 |
+
|
| 120 |
+
if table is not NotImplemented and table is not False:
|
| 121 |
+
mega[tag] = table
|
| 122 |
+
log.info("Merged '%s'.", tag)
|
| 123 |
+
else:
|
| 124 |
+
log.info("Dropped '%s'.", tag)
|
| 125 |
+
|
| 126 |
+
del self.duplicateGlyphsPerFont
|
| 127 |
+
del self.fonts
|
| 128 |
+
|
| 129 |
+
self._postMerge(mega)
|
| 130 |
+
|
| 131 |
+
return mega
|
| 132 |
+
|
| 133 |
+
def mergeObjects(self, returnTable, logic, tables):
|
| 134 |
+
# Right now we don't use self at all. Will use in the future
|
| 135 |
+
# for options and logging.
|
| 136 |
+
|
| 137 |
+
allKeys = set.union(
|
| 138 |
+
set(),
|
| 139 |
+
*(vars(table).keys() for table in tables if table is not NotImplemented),
|
| 140 |
+
)
|
| 141 |
+
for key in allKeys:
|
| 142 |
+
log.info(" %s", key)
|
| 143 |
+
try:
|
| 144 |
+
mergeLogic = logic[key]
|
| 145 |
+
except KeyError:
|
| 146 |
+
try:
|
| 147 |
+
mergeLogic = logic["*"]
|
| 148 |
+
except KeyError:
|
| 149 |
+
raise Exception(
|
| 150 |
+
"Don't know how to merge key %s of class %s"
|
| 151 |
+
% (key, returnTable.__class__.__name__)
|
| 152 |
+
)
|
| 153 |
+
if mergeLogic is NotImplemented:
|
| 154 |
+
continue
|
| 155 |
+
value = mergeLogic(getattr(table, key, NotImplemented) for table in tables)
|
| 156 |
+
if value is not NotImplemented:
|
| 157 |
+
setattr(returnTable, key, value)
|
| 158 |
+
|
| 159 |
+
return returnTable
|
| 160 |
+
|
| 161 |
+
def _preMerge(self, font):
|
| 162 |
+
layoutPreMerge(font)
|
| 163 |
+
|
| 164 |
+
def _postMerge(self, font):
|
| 165 |
+
layoutPostMerge(font)
|
| 166 |
+
|
| 167 |
+
if "OS/2" in font:
|
| 168 |
+
# https://github.com/fonttools/fonttools/issues/2538
|
| 169 |
+
# TODO: Add an option to disable this?
|
| 170 |
+
font["OS/2"].recalcAvgCharWidth(font)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
__all__ = ["Options", "Merger", "main"]
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
@timer("make one with everything (TOTAL TIME)")
|
| 177 |
+
def main(args=None):
|
| 178 |
+
"""Merge multiple fonts into one"""
|
| 179 |
+
from fontTools import configLogger
|
| 180 |
+
|
| 181 |
+
if args is None:
|
| 182 |
+
args = sys.argv[1:]
|
| 183 |
+
|
| 184 |
+
options = Options()
|
| 185 |
+
args = options.parse_opts(args)
|
| 186 |
+
fontfiles = []
|
| 187 |
+
if options.input_file:
|
| 188 |
+
with open(options.input_file) as inputfile:
|
| 189 |
+
fontfiles = [
|
| 190 |
+
line.strip()
|
| 191 |
+
for line in inputfile.readlines()
|
| 192 |
+
if not line.lstrip().startswith("#")
|
| 193 |
+
]
|
| 194 |
+
for g in args:
|
| 195 |
+
fontfiles.append(g)
|
| 196 |
+
|
| 197 |
+
if len(fontfiles) < 1:
|
| 198 |
+
print(
|
| 199 |
+
"usage: pyftmerge [font1 ... fontN] [--input-file=filelist.txt] [--output-file=merged.ttf] [--import-file=tables.ttx]",
|
| 200 |
+
file=sys.stderr,
|
| 201 |
+
)
|
| 202 |
+
print(
|
| 203 |
+
" [--drop-tables=tags] [--verbose] [--timing]",
|
| 204 |
+
file=sys.stderr,
|
| 205 |
+
)
|
| 206 |
+
print("", file=sys.stderr)
|
| 207 |
+
print(" font1 ... fontN Files to merge.", file=sys.stderr)
|
| 208 |
+
print(
|
| 209 |
+
" --input-file=<filename> Read files to merge from a text file, each path new line. # Comment lines allowed.",
|
| 210 |
+
file=sys.stderr,
|
| 211 |
+
)
|
| 212 |
+
print(
|
| 213 |
+
" --output-file=<filename> Specify output file name (default: merged.ttf).",
|
| 214 |
+
file=sys.stderr,
|
| 215 |
+
)
|
| 216 |
+
print(
|
| 217 |
+
" --import-file=<filename> TTX file to import after merging. This can be used to set metadata.",
|
| 218 |
+
file=sys.stderr,
|
| 219 |
+
)
|
| 220 |
+
print(
|
| 221 |
+
" --drop-tables=<table tags> Comma separated list of table tags to skip, case sensitive.",
|
| 222 |
+
file=sys.stderr,
|
| 223 |
+
)
|
| 224 |
+
print(
|
| 225 |
+
" --verbose Output progress information.",
|
| 226 |
+
file=sys.stderr,
|
| 227 |
+
)
|
| 228 |
+
print(" --timing Output progress timing.", file=sys.stderr)
|
| 229 |
+
return 1
|
| 230 |
+
|
| 231 |
+
configLogger(level=logging.INFO if options.verbose else logging.WARNING)
|
| 232 |
+
if options.timing:
|
| 233 |
+
timer.logger.setLevel(logging.DEBUG)
|
| 234 |
+
else:
|
| 235 |
+
timer.logger.disabled = True
|
| 236 |
+
|
| 237 |
+
merger = Merger(options=options)
|
| 238 |
+
font = merger.merge(fontfiles)
|
| 239 |
+
|
| 240 |
+
if options.import_file:
|
| 241 |
+
font.importXML(options.import_file)
|
| 242 |
+
|
| 243 |
+
with timer("compile and save font"):
|
| 244 |
+
font.save(options.output_file)
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
if __name__ == "__main__":
|
| 248 |
+
sys.exit(main())
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/__pycache__/cmap.cpython-310.pyc
ADDED
|
Binary file (3.34 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/base.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2013 Google, Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Google Author(s): Behdad Esfahbod, Roozbeh Pournader
|
| 4 |
+
|
| 5 |
+
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
log = logging.getLogger("fontTools.merge")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def add_method(*clazzes, **kwargs):
|
| 13 |
+
"""Returns a decorator function that adds a new method to one or
|
| 14 |
+
more classes."""
|
| 15 |
+
allowDefault = kwargs.get("allowDefaultTable", False)
|
| 16 |
+
|
| 17 |
+
def wrapper(method):
|
| 18 |
+
done = []
|
| 19 |
+
for clazz in clazzes:
|
| 20 |
+
if clazz in done:
|
| 21 |
+
continue # Support multiple names of a clazz
|
| 22 |
+
done.append(clazz)
|
| 23 |
+
assert allowDefault or clazz != DefaultTable, "Oops, table class not found."
|
| 24 |
+
assert (
|
| 25 |
+
method.__name__ not in clazz.__dict__
|
| 26 |
+
), "Oops, class '%s' has method '%s'." % (clazz.__name__, method.__name__)
|
| 27 |
+
setattr(clazz, method.__name__, method)
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
return wrapper
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def mergeObjects(lst):
|
| 34 |
+
lst = [item for item in lst if item is not NotImplemented]
|
| 35 |
+
if not lst:
|
| 36 |
+
return NotImplemented
|
| 37 |
+
lst = [item for item in lst if item is not None]
|
| 38 |
+
if not lst:
|
| 39 |
+
return None
|
| 40 |
+
|
| 41 |
+
clazz = lst[0].__class__
|
| 42 |
+
assert all(type(item) == clazz for item in lst), lst
|
| 43 |
+
|
| 44 |
+
logic = clazz.mergeMap
|
| 45 |
+
returnTable = clazz()
|
| 46 |
+
returnDict = {}
|
| 47 |
+
|
| 48 |
+
allKeys = set.union(set(), *(vars(table).keys() for table in lst))
|
| 49 |
+
for key in allKeys:
|
| 50 |
+
try:
|
| 51 |
+
mergeLogic = logic[key]
|
| 52 |
+
except KeyError:
|
| 53 |
+
try:
|
| 54 |
+
mergeLogic = logic["*"]
|
| 55 |
+
except KeyError:
|
| 56 |
+
raise Exception(
|
| 57 |
+
"Don't know how to merge key %s of class %s" % (key, clazz.__name__)
|
| 58 |
+
)
|
| 59 |
+
if mergeLogic is NotImplemented:
|
| 60 |
+
continue
|
| 61 |
+
value = mergeLogic(getattr(table, key, NotImplemented) for table in lst)
|
| 62 |
+
if value is not NotImplemented:
|
| 63 |
+
returnDict[key] = value
|
| 64 |
+
|
| 65 |
+
returnTable.__dict__ = returnDict
|
| 66 |
+
|
| 67 |
+
return returnTable
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
@add_method(DefaultTable, allowDefaultTable=True)
|
| 71 |
+
def merge(self, m, tables):
|
| 72 |
+
if not hasattr(self, "mergeMap"):
|
| 73 |
+
log.info("Don't know how to merge '%s'.", self.tableTag)
|
| 74 |
+
return NotImplemented
|
| 75 |
+
|
| 76 |
+
logic = self.mergeMap
|
| 77 |
+
|
| 78 |
+
if isinstance(logic, dict):
|
| 79 |
+
return m.mergeObjects(self, self.mergeMap, tables)
|
| 80 |
+
else:
|
| 81 |
+
return logic(tables)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/tables.py
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
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copyright 2013 Google, Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Google Author(s): Behdad Esfahbod, Roozbeh Pournader
|
| 4 |
+
|
| 5 |
+
from fontTools import ttLib, cffLib
|
| 6 |
+
from fontTools.misc.psCharStrings import T2WidthExtractor
|
| 7 |
+
from fontTools.ttLib.tables.DefaultTable import DefaultTable
|
| 8 |
+
from fontTools.merge.base import add_method, mergeObjects
|
| 9 |
+
from fontTools.merge.cmap import computeMegaCmap
|
| 10 |
+
from fontTools.merge.util import *
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
log = logging.getLogger("fontTools.merge")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
ttLib.getTableClass("maxp").mergeMap = {
|
| 18 |
+
"*": max,
|
| 19 |
+
"tableTag": equal,
|
| 20 |
+
"tableVersion": equal,
|
| 21 |
+
"numGlyphs": sum,
|
| 22 |
+
"maxStorage": first,
|
| 23 |
+
"maxFunctionDefs": first,
|
| 24 |
+
"maxInstructionDefs": first,
|
| 25 |
+
# TODO When we correctly merge hinting data, update these values:
|
| 26 |
+
# maxFunctionDefs, maxInstructionDefs, maxSizeOfInstructions
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
headFlagsMergeBitMap = {
|
| 30 |
+
"size": 16,
|
| 31 |
+
"*": bitwise_or,
|
| 32 |
+
1: bitwise_and, # Baseline at y = 0
|
| 33 |
+
2: bitwise_and, # lsb at x = 0
|
| 34 |
+
3: bitwise_and, # Force ppem to integer values. FIXME?
|
| 35 |
+
5: bitwise_and, # Font is vertical
|
| 36 |
+
6: lambda bit: 0, # Always set to zero
|
| 37 |
+
11: bitwise_and, # Font data is 'lossless'
|
| 38 |
+
13: bitwise_and, # Optimized for ClearType
|
| 39 |
+
14: bitwise_and, # Last resort font. FIXME? equal or first may be better
|
| 40 |
+
15: lambda bit: 0, # Always set to zero
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
ttLib.getTableClass("head").mergeMap = {
|
| 44 |
+
"tableTag": equal,
|
| 45 |
+
"tableVersion": max,
|
| 46 |
+
"fontRevision": max,
|
| 47 |
+
"checkSumAdjustment": lambda lst: 0, # We need *something* here
|
| 48 |
+
"magicNumber": equal,
|
| 49 |
+
"flags": mergeBits(headFlagsMergeBitMap),
|
| 50 |
+
"unitsPerEm": equal,
|
| 51 |
+
"created": current_time,
|
| 52 |
+
"modified": current_time,
|
| 53 |
+
"xMin": min,
|
| 54 |
+
"yMin": min,
|
| 55 |
+
"xMax": max,
|
| 56 |
+
"yMax": max,
|
| 57 |
+
"macStyle": first,
|
| 58 |
+
"lowestRecPPEM": max,
|
| 59 |
+
"fontDirectionHint": lambda lst: 2,
|
| 60 |
+
"indexToLocFormat": first,
|
| 61 |
+
"glyphDataFormat": equal,
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
ttLib.getTableClass("hhea").mergeMap = {
|
| 65 |
+
"*": equal,
|
| 66 |
+
"tableTag": equal,
|
| 67 |
+
"tableVersion": max,
|
| 68 |
+
"ascent": max,
|
| 69 |
+
"descent": min,
|
| 70 |
+
"lineGap": max,
|
| 71 |
+
"advanceWidthMax": max,
|
| 72 |
+
"minLeftSideBearing": min,
|
| 73 |
+
"minRightSideBearing": min,
|
| 74 |
+
"xMaxExtent": max,
|
| 75 |
+
"caretSlopeRise": first,
|
| 76 |
+
"caretSlopeRun": first,
|
| 77 |
+
"caretOffset": first,
|
| 78 |
+
"numberOfHMetrics": recalculate,
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
ttLib.getTableClass("vhea").mergeMap = {
|
| 82 |
+
"*": equal,
|
| 83 |
+
"tableTag": equal,
|
| 84 |
+
"tableVersion": max,
|
| 85 |
+
"ascent": max,
|
| 86 |
+
"descent": min,
|
| 87 |
+
"lineGap": max,
|
| 88 |
+
"advanceHeightMax": max,
|
| 89 |
+
"minTopSideBearing": min,
|
| 90 |
+
"minBottomSideBearing": min,
|
| 91 |
+
"yMaxExtent": max,
|
| 92 |
+
"caretSlopeRise": first,
|
| 93 |
+
"caretSlopeRun": first,
|
| 94 |
+
"caretOffset": first,
|
| 95 |
+
"numberOfVMetrics": recalculate,
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
os2FsTypeMergeBitMap = {
|
| 99 |
+
"size": 16,
|
| 100 |
+
"*": lambda bit: 0,
|
| 101 |
+
1: bitwise_or, # no embedding permitted
|
| 102 |
+
2: bitwise_and, # allow previewing and printing documents
|
| 103 |
+
3: bitwise_and, # allow editing documents
|
| 104 |
+
8: bitwise_or, # no subsetting permitted
|
| 105 |
+
9: bitwise_or, # no embedding of outlines permitted
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def mergeOs2FsType(lst):
|
| 110 |
+
lst = list(lst)
|
| 111 |
+
if all(item == 0 for item in lst):
|
| 112 |
+
return 0
|
| 113 |
+
|
| 114 |
+
# Compute least restrictive logic for each fsType value
|
| 115 |
+
for i in range(len(lst)):
|
| 116 |
+
# unset bit 1 (no embedding permitted) if either bit 2 or 3 is set
|
| 117 |
+
if lst[i] & 0x000C:
|
| 118 |
+
lst[i] &= ~0x0002
|
| 119 |
+
# set bit 2 (allow previewing) if bit 3 is set (allow editing)
|
| 120 |
+
elif lst[i] & 0x0008:
|
| 121 |
+
lst[i] |= 0x0004
|
| 122 |
+
# set bits 2 and 3 if everything is allowed
|
| 123 |
+
elif lst[i] == 0:
|
| 124 |
+
lst[i] = 0x000C
|
| 125 |
+
|
| 126 |
+
fsType = mergeBits(os2FsTypeMergeBitMap)(lst)
|
| 127 |
+
# unset bits 2 and 3 if bit 1 is set (some font is "no embedding")
|
| 128 |
+
if fsType & 0x0002:
|
| 129 |
+
fsType &= ~0x000C
|
| 130 |
+
return fsType
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
ttLib.getTableClass("OS/2").mergeMap = {
|
| 134 |
+
"*": first,
|
| 135 |
+
"tableTag": equal,
|
| 136 |
+
"version": max,
|
| 137 |
+
"xAvgCharWidth": first, # Will be recalculated at the end on the merged font
|
| 138 |
+
"fsType": mergeOs2FsType, # Will be overwritten
|
| 139 |
+
"panose": first, # FIXME: should really be the first Latin font
|
| 140 |
+
"ulUnicodeRange1": bitwise_or,
|
| 141 |
+
"ulUnicodeRange2": bitwise_or,
|
| 142 |
+
"ulUnicodeRange3": bitwise_or,
|
| 143 |
+
"ulUnicodeRange4": bitwise_or,
|
| 144 |
+
"fsFirstCharIndex": min,
|
| 145 |
+
"fsLastCharIndex": max,
|
| 146 |
+
"sTypoAscender": max,
|
| 147 |
+
"sTypoDescender": min,
|
| 148 |
+
"sTypoLineGap": max,
|
| 149 |
+
"usWinAscent": max,
|
| 150 |
+
"usWinDescent": max,
|
| 151 |
+
# Version 1
|
| 152 |
+
"ulCodePageRange1": onlyExisting(bitwise_or),
|
| 153 |
+
"ulCodePageRange2": onlyExisting(bitwise_or),
|
| 154 |
+
# Version 2, 3, 4
|
| 155 |
+
"sxHeight": onlyExisting(max),
|
| 156 |
+
"sCapHeight": onlyExisting(max),
|
| 157 |
+
"usDefaultChar": onlyExisting(first),
|
| 158 |
+
"usBreakChar": onlyExisting(first),
|
| 159 |
+
"usMaxContext": onlyExisting(max),
|
| 160 |
+
# version 5
|
| 161 |
+
"usLowerOpticalPointSize": onlyExisting(min),
|
| 162 |
+
"usUpperOpticalPointSize": onlyExisting(max),
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
@add_method(ttLib.getTableClass("OS/2"))
|
| 167 |
+
def merge(self, m, tables):
|
| 168 |
+
DefaultTable.merge(self, m, tables)
|
| 169 |
+
if self.version < 2:
|
| 170 |
+
# bits 8 and 9 are reserved and should be set to zero
|
| 171 |
+
self.fsType &= ~0x0300
|
| 172 |
+
if self.version >= 3:
|
| 173 |
+
# Only one of bits 1, 2, and 3 may be set. We already take
|
| 174 |
+
# care of bit 1 implications in mergeOs2FsType. So unset
|
| 175 |
+
# bit 2 if bit 3 is already set.
|
| 176 |
+
if self.fsType & 0x0008:
|
| 177 |
+
self.fsType &= ~0x0004
|
| 178 |
+
return self
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
ttLib.getTableClass("post").mergeMap = {
|
| 182 |
+
"*": first,
|
| 183 |
+
"tableTag": equal,
|
| 184 |
+
"formatType": max,
|
| 185 |
+
"isFixedPitch": min,
|
| 186 |
+
"minMemType42": max,
|
| 187 |
+
"maxMemType42": lambda lst: 0,
|
| 188 |
+
"minMemType1": max,
|
| 189 |
+
"maxMemType1": lambda lst: 0,
|
| 190 |
+
"mapping": onlyExisting(sumDicts),
|
| 191 |
+
"extraNames": lambda lst: [],
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
ttLib.getTableClass("vmtx").mergeMap = ttLib.getTableClass("hmtx").mergeMap = {
|
| 195 |
+
"tableTag": equal,
|
| 196 |
+
"metrics": sumDicts,
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
ttLib.getTableClass("name").mergeMap = {
|
| 200 |
+
"tableTag": equal,
|
| 201 |
+
"names": first, # FIXME? Does mixing name records make sense?
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
ttLib.getTableClass("loca").mergeMap = {
|
| 205 |
+
"*": recalculate,
|
| 206 |
+
"tableTag": equal,
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
ttLib.getTableClass("glyf").mergeMap = {
|
| 210 |
+
"tableTag": equal,
|
| 211 |
+
"glyphs": sumDicts,
|
| 212 |
+
"glyphOrder": sumLists,
|
| 213 |
+
"_reverseGlyphOrder": recalculate,
|
| 214 |
+
"axisTags": equal,
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
@add_method(ttLib.getTableClass("glyf"))
|
| 219 |
+
def merge(self, m, tables):
|
| 220 |
+
for i, table in enumerate(tables):
|
| 221 |
+
for g in table.glyphs.values():
|
| 222 |
+
if i:
|
| 223 |
+
# Drop hints for all but first font, since
|
| 224 |
+
# we don't map functions / CVT values.
|
| 225 |
+
g.removeHinting()
|
| 226 |
+
# Expand composite glyphs to load their
|
| 227 |
+
# composite glyph names.
|
| 228 |
+
if g.isComposite():
|
| 229 |
+
g.expand(table)
|
| 230 |
+
return DefaultTable.merge(self, m, tables)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
ttLib.getTableClass("prep").mergeMap = lambda self, lst: first(lst)
|
| 234 |
+
ttLib.getTableClass("fpgm").mergeMap = lambda self, lst: first(lst)
|
| 235 |
+
ttLib.getTableClass("cvt ").mergeMap = lambda self, lst: first(lst)
|
| 236 |
+
ttLib.getTableClass("gasp").mergeMap = lambda self, lst: first(
|
| 237 |
+
lst
|
| 238 |
+
) # FIXME? Appears irreconcilable
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
@add_method(ttLib.getTableClass("CFF "))
|
| 242 |
+
def merge(self, m, tables):
|
| 243 |
+
if any(hasattr(table.cff[0], "FDSelect") for table in tables):
|
| 244 |
+
raise NotImplementedError("Merging CID-keyed CFF tables is not supported yet")
|
| 245 |
+
|
| 246 |
+
for table in tables:
|
| 247 |
+
table.cff.desubroutinize()
|
| 248 |
+
|
| 249 |
+
newcff = tables[0]
|
| 250 |
+
newfont = newcff.cff[0]
|
| 251 |
+
private = newfont.Private
|
| 252 |
+
newDefaultWidthX, newNominalWidthX = private.defaultWidthX, private.nominalWidthX
|
| 253 |
+
storedNamesStrings = []
|
| 254 |
+
glyphOrderStrings = []
|
| 255 |
+
glyphOrder = set(newfont.getGlyphOrder())
|
| 256 |
+
|
| 257 |
+
for name in newfont.strings.strings:
|
| 258 |
+
if name not in glyphOrder:
|
| 259 |
+
storedNamesStrings.append(name)
|
| 260 |
+
else:
|
| 261 |
+
glyphOrderStrings.append(name)
|
| 262 |
+
|
| 263 |
+
chrset = list(newfont.charset)
|
| 264 |
+
newcs = newfont.CharStrings
|
| 265 |
+
log.debug("FONT 0 CharStrings: %d.", len(newcs))
|
| 266 |
+
|
| 267 |
+
for i, table in enumerate(tables[1:], start=1):
|
| 268 |
+
font = table.cff[0]
|
| 269 |
+
defaultWidthX, nominalWidthX = (
|
| 270 |
+
font.Private.defaultWidthX,
|
| 271 |
+
font.Private.nominalWidthX,
|
| 272 |
+
)
|
| 273 |
+
widthsDiffer = (
|
| 274 |
+
defaultWidthX != newDefaultWidthX or nominalWidthX != newNominalWidthX
|
| 275 |
+
)
|
| 276 |
+
font.Private = private
|
| 277 |
+
fontGlyphOrder = set(font.getGlyphOrder())
|
| 278 |
+
for name in font.strings.strings:
|
| 279 |
+
if name in fontGlyphOrder:
|
| 280 |
+
glyphOrderStrings.append(name)
|
| 281 |
+
cs = font.CharStrings
|
| 282 |
+
gs = table.cff.GlobalSubrs
|
| 283 |
+
log.debug("Font %d CharStrings: %d.", i, len(cs))
|
| 284 |
+
chrset.extend(font.charset)
|
| 285 |
+
if newcs.charStringsAreIndexed:
|
| 286 |
+
for i, name in enumerate(cs.charStrings, start=len(newcs)):
|
| 287 |
+
newcs.charStrings[name] = i
|
| 288 |
+
newcs.charStringsIndex.items.append(None)
|
| 289 |
+
for name in cs.charStrings:
|
| 290 |
+
if widthsDiffer:
|
| 291 |
+
c = cs[name]
|
| 292 |
+
defaultWidthXToken = object()
|
| 293 |
+
extractor = T2WidthExtractor([], [], nominalWidthX, defaultWidthXToken)
|
| 294 |
+
extractor.execute(c)
|
| 295 |
+
width = extractor.width
|
| 296 |
+
if width is not defaultWidthXToken:
|
| 297 |
+
# The following will be wrong if the width is added
|
| 298 |
+
# by a subroutine. Ouch!
|
| 299 |
+
c.program.pop(0)
|
| 300 |
+
else:
|
| 301 |
+
width = defaultWidthX
|
| 302 |
+
if width != newDefaultWidthX:
|
| 303 |
+
c.program.insert(0, width - newNominalWidthX)
|
| 304 |
+
newcs[name] = cs[name]
|
| 305 |
+
|
| 306 |
+
newfont.charset = chrset
|
| 307 |
+
newfont.numGlyphs = len(chrset)
|
| 308 |
+
newfont.strings.strings = glyphOrderStrings + storedNamesStrings
|
| 309 |
+
|
| 310 |
+
return newcff
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
@add_method(ttLib.getTableClass("cmap"))
|
| 314 |
+
def merge(self, m, tables):
|
| 315 |
+
# TODO Handle format=14.
|
| 316 |
+
if not hasattr(m, "cmap"):
|
| 317 |
+
computeMegaCmap(m, tables)
|
| 318 |
+
cmap = m.cmap
|
| 319 |
+
|
| 320 |
+
cmapBmpOnly = {uni: gid for uni, gid in cmap.items() if uni <= 0xFFFF}
|
| 321 |
+
self.tables = []
|
| 322 |
+
module = ttLib.getTableModule("cmap")
|
| 323 |
+
if len(cmapBmpOnly) != len(cmap):
|
| 324 |
+
# format-12 required.
|
| 325 |
+
cmapTable = module.cmap_classes[12](12)
|
| 326 |
+
cmapTable.platformID = 3
|
| 327 |
+
cmapTable.platEncID = 10
|
| 328 |
+
cmapTable.language = 0
|
| 329 |
+
cmapTable.cmap = cmap
|
| 330 |
+
self.tables.append(cmapTable)
|
| 331 |
+
# always create format-4
|
| 332 |
+
cmapTable = module.cmap_classes[4](4)
|
| 333 |
+
cmapTable.platformID = 3
|
| 334 |
+
cmapTable.platEncID = 1
|
| 335 |
+
cmapTable.language = 0
|
| 336 |
+
cmapTable.cmap = cmapBmpOnly
|
| 337 |
+
# ordered by platform then encoding
|
| 338 |
+
self.tables.insert(0, cmapTable)
|
| 339 |
+
self.tableVersion = 0
|
| 340 |
+
self.numSubTables = len(self.tables)
|
| 341 |
+
return self
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/merge/unicode.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2021 Behdad Esfahbod. All Rights Reserved.
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def is_Default_Ignorable(u):
|
| 5 |
+
# http://www.unicode.org/reports/tr44/#Default_Ignorable_Code_Point
|
| 6 |
+
#
|
| 7 |
+
# TODO Move me to unicodedata module and autogenerate.
|
| 8 |
+
#
|
| 9 |
+
# Unicode 14.0:
|
| 10 |
+
# $ grep '; Default_Ignorable_Code_Point ' DerivedCoreProperties.txt | sed 's/;.*#/#/'
|
| 11 |
+
# 00AD # Cf SOFT HYPHEN
|
| 12 |
+
# 034F # Mn COMBINING GRAPHEME JOINER
|
| 13 |
+
# 061C # Cf ARABIC LETTER MARK
|
| 14 |
+
# 115F..1160 # Lo [2] HANGUL CHOSEONG FILLER..HANGUL JUNGSEONG FILLER
|
| 15 |
+
# 17B4..17B5 # Mn [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA
|
| 16 |
+
# 180B..180D # Mn [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE
|
| 17 |
+
# 180E # Cf MONGOLIAN VOWEL SEPARATOR
|
| 18 |
+
# 180F # Mn MONGOLIAN FREE VARIATION SELECTOR FOUR
|
| 19 |
+
# 200B..200F # Cf [5] ZERO WIDTH SPACE..RIGHT-TO-LEFT MARK
|
| 20 |
+
# 202A..202E # Cf [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE
|
| 21 |
+
# 2060..2064 # Cf [5] WORD JOINER..INVISIBLE PLUS
|
| 22 |
+
# 2065 # Cn <reserved-2065>
|
| 23 |
+
# 2066..206F # Cf [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES
|
| 24 |
+
# 3164 # Lo HANGUL FILLER
|
| 25 |
+
# FE00..FE0F # Mn [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16
|
| 26 |
+
# FEFF # Cf ZERO WIDTH NO-BREAK SPACE
|
| 27 |
+
# FFA0 # Lo HALFWIDTH HANGUL FILLER
|
| 28 |
+
# FFF0..FFF8 # Cn [9] <reserved-FFF0>..<reserved-FFF8>
|
| 29 |
+
# 1BCA0..1BCA3 # Cf [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP
|
| 30 |
+
# 1D173..1D17A # Cf [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE
|
| 31 |
+
# E0000 # Cn <reserved-E0000>
|
| 32 |
+
# E0001 # Cf LANGUAGE TAG
|
| 33 |
+
# E0002..E001F # Cn [30] <reserved-E0002>..<reserved-E001F>
|
| 34 |
+
# E0020..E007F # Cf [96] TAG SPACE..CANCEL TAG
|
| 35 |
+
# E0080..E00FF # Cn [128] <reserved-E0080>..<reserved-E00FF>
|
| 36 |
+
# E0100..E01EF # Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256
|
| 37 |
+
# E01F0..E0FFF # Cn [3600] <reserved-E01F0>..<reserved-E0FFF>
|
| 38 |
+
return (
|
| 39 |
+
u == 0x00AD
|
| 40 |
+
or u == 0x034F # Cf SOFT HYPHEN
|
| 41 |
+
or u == 0x061C # Mn COMBINING GRAPHEME JOINER
|
| 42 |
+
or 0x115F <= u <= 0x1160 # Cf ARABIC LETTER MARK
|
| 43 |
+
or 0x17B4 # Lo [2] HANGUL CHOSEONG FILLER..HANGUL JUNGSEONG FILLER
|
| 44 |
+
<= u
|
| 45 |
+
<= 0x17B5
|
| 46 |
+
or 0x180B # Mn [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA
|
| 47 |
+
<= u
|
| 48 |
+
<= 0x180D
|
| 49 |
+
or u # Mn [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE
|
| 50 |
+
== 0x180E
|
| 51 |
+
or u == 0x180F # Cf MONGOLIAN VOWEL SEPARATOR
|
| 52 |
+
or 0x200B <= u <= 0x200F # Mn MONGOLIAN FREE VARIATION SELECTOR FOUR
|
| 53 |
+
or 0x202A <= u <= 0x202E # Cf [5] ZERO WIDTH SPACE..RIGHT-TO-LEFT MARK
|
| 54 |
+
or 0x2060 # Cf [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE
|
| 55 |
+
<= u
|
| 56 |
+
<= 0x2064
|
| 57 |
+
or u == 0x2065 # Cf [5] WORD JOINER..INVISIBLE PLUS
|
| 58 |
+
or 0x2066 <= u <= 0x206F # Cn <reserved-2065>
|
| 59 |
+
or u == 0x3164 # Cf [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES
|
| 60 |
+
or 0xFE00 <= u <= 0xFE0F # Lo HANGUL FILLER
|
| 61 |
+
or u == 0xFEFF # Mn [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16
|
| 62 |
+
or u == 0xFFA0 # Cf ZERO WIDTH NO-BREAK SPACE
|
| 63 |
+
or 0xFFF0 <= u <= 0xFFF8 # Lo HALFWIDTH HANGUL FILLER
|
| 64 |
+
or 0x1BCA0 <= u <= 0x1BCA3 # Cn [9] <reserved-FFF0>..<reserved-FFF8>
|
| 65 |
+
or 0x1D173 # Cf [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP
|
| 66 |
+
<= u
|
| 67 |
+
<= 0x1D17A
|
| 68 |
+
or u == 0xE0000 # Cf [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE
|
| 69 |
+
or u == 0xE0001 # Cn <reserved-E0000>
|
| 70 |
+
or 0xE0002 <= u <= 0xE001F # Cf LANGUAGE TAG
|
| 71 |
+
or 0xE0020 <= u <= 0xE007F # Cn [30] <reserved-E0002>..<reserved-E001F>
|
| 72 |
+
or 0xE0080 <= u <= 0xE00FF # Cf [96] TAG SPACE..CANCEL TAG
|
| 73 |
+
or 0xE0100 <= u <= 0xE01EF # Cn [128] <reserved-E0080>..<reserved-E00FF>
|
| 74 |
+
or 0xE01F0 # Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256
|
| 75 |
+
<= u
|
| 76 |
+
<= 0xE0FFF
|
| 77 |
+
or False # Cn [3600] <reserved-E01F0>..<reserved-E0FFF>
|
| 78 |
+
)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/cairoPen.cpython-310.pyc
ADDED
|
Binary file (1.25 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/pointInsidePen.cpython-310.pyc
ADDED
|
Binary file (5.26 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/recordingPen.cpython-310.pyc
ADDED
|
Binary file (13.5 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/roundingPen.cpython-310.pyc
ADDED
|
Binary file (5.02 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/statisticsPen.cpython-310.pyc
ADDED
|
Binary file (8.38 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/svgPathPen.cpython-310.pyc
ADDED
|
Binary file (8.55 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/__pycache__/wxPen.cpython-310.pyc
ADDED
|
Binary file (1.44 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/boundsPen.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc.arrayTools import updateBounds, pointInRect, unionRect
|
| 2 |
+
from fontTools.misc.bezierTools import calcCubicBounds, calcQuadraticBounds
|
| 3 |
+
from fontTools.pens.basePen import BasePen
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
__all__ = ["BoundsPen", "ControlBoundsPen"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class ControlBoundsPen(BasePen):
|
| 10 |
+
"""Pen to calculate the "control bounds" of a shape. This is the
|
| 11 |
+
bounding box of all control points, so may be larger than the
|
| 12 |
+
actual bounding box if there are curves that don't have points
|
| 13 |
+
on their extremes.
|
| 14 |
+
|
| 15 |
+
When the shape has been drawn, the bounds are available as the
|
| 16 |
+
``bounds`` attribute of the pen object. It's a 4-tuple::
|
| 17 |
+
|
| 18 |
+
(xMin, yMin, xMax, yMax).
|
| 19 |
+
|
| 20 |
+
If ``ignoreSinglePoints`` is True, single points are ignored.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
def __init__(self, glyphSet, ignoreSinglePoints=False):
|
| 24 |
+
BasePen.__init__(self, glyphSet)
|
| 25 |
+
self.ignoreSinglePoints = ignoreSinglePoints
|
| 26 |
+
self.init()
|
| 27 |
+
|
| 28 |
+
def init(self):
|
| 29 |
+
self.bounds = None
|
| 30 |
+
self._start = None
|
| 31 |
+
|
| 32 |
+
def _moveTo(self, pt):
|
| 33 |
+
self._start = pt
|
| 34 |
+
if not self.ignoreSinglePoints:
|
| 35 |
+
self._addMoveTo()
|
| 36 |
+
|
| 37 |
+
def _addMoveTo(self):
|
| 38 |
+
if self._start is None:
|
| 39 |
+
return
|
| 40 |
+
bounds = self.bounds
|
| 41 |
+
if bounds:
|
| 42 |
+
self.bounds = updateBounds(bounds, self._start)
|
| 43 |
+
else:
|
| 44 |
+
x, y = self._start
|
| 45 |
+
self.bounds = (x, y, x, y)
|
| 46 |
+
self._start = None
|
| 47 |
+
|
| 48 |
+
def _lineTo(self, pt):
|
| 49 |
+
self._addMoveTo()
|
| 50 |
+
self.bounds = updateBounds(self.bounds, pt)
|
| 51 |
+
|
| 52 |
+
def _curveToOne(self, bcp1, bcp2, pt):
|
| 53 |
+
self._addMoveTo()
|
| 54 |
+
bounds = self.bounds
|
| 55 |
+
bounds = updateBounds(bounds, bcp1)
|
| 56 |
+
bounds = updateBounds(bounds, bcp2)
|
| 57 |
+
bounds = updateBounds(bounds, pt)
|
| 58 |
+
self.bounds = bounds
|
| 59 |
+
|
| 60 |
+
def _qCurveToOne(self, bcp, pt):
|
| 61 |
+
self._addMoveTo()
|
| 62 |
+
bounds = self.bounds
|
| 63 |
+
bounds = updateBounds(bounds, bcp)
|
| 64 |
+
bounds = updateBounds(bounds, pt)
|
| 65 |
+
self.bounds = bounds
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class BoundsPen(ControlBoundsPen):
|
| 69 |
+
"""Pen to calculate the bounds of a shape. It calculates the
|
| 70 |
+
correct bounds even when the shape contains curves that don't
|
| 71 |
+
have points on their extremes. This is somewhat slower to compute
|
| 72 |
+
than the "control bounds".
|
| 73 |
+
|
| 74 |
+
When the shape has been drawn, the bounds are available as the
|
| 75 |
+
``bounds`` attribute of the pen object. It's a 4-tuple::
|
| 76 |
+
|
| 77 |
+
(xMin, yMin, xMax, yMax)
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
def _curveToOne(self, bcp1, bcp2, pt):
|
| 81 |
+
self._addMoveTo()
|
| 82 |
+
bounds = self.bounds
|
| 83 |
+
bounds = updateBounds(bounds, pt)
|
| 84 |
+
if not pointInRect(bcp1, bounds) or not pointInRect(bcp2, bounds):
|
| 85 |
+
bounds = unionRect(
|
| 86 |
+
bounds, calcCubicBounds(self._getCurrentPoint(), bcp1, bcp2, pt)
|
| 87 |
+
)
|
| 88 |
+
self.bounds = bounds
|
| 89 |
+
|
| 90 |
+
def _qCurveToOne(self, bcp, pt):
|
| 91 |
+
self._addMoveTo()
|
| 92 |
+
bounds = self.bounds
|
| 93 |
+
bounds = updateBounds(bounds, pt)
|
| 94 |
+
if not pointInRect(bcp, bounds):
|
| 95 |
+
bounds = unionRect(
|
| 96 |
+
bounds, calcQuadraticBounds(self._getCurrentPoint(), bcp, pt)
|
| 97 |
+
)
|
| 98 |
+
self.bounds = bounds
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/cu2quPen.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2016 Google Inc. All Rights Reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
|
| 15 |
+
import operator
|
| 16 |
+
from fontTools.cu2qu import curve_to_quadratic, curves_to_quadratic
|
| 17 |
+
from fontTools.pens.basePen import decomposeSuperBezierSegment
|
| 18 |
+
from fontTools.pens.filterPen import FilterPen
|
| 19 |
+
from fontTools.pens.reverseContourPen import ReverseContourPen
|
| 20 |
+
from fontTools.pens.pointPen import BasePointToSegmentPen
|
| 21 |
+
from fontTools.pens.pointPen import ReverseContourPointPen
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Cu2QuPen(FilterPen):
|
| 25 |
+
"""A filter pen to convert cubic bezier curves to quadratic b-splines
|
| 26 |
+
using the FontTools SegmentPen protocol.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
|
| 30 |
+
other_pen: another SegmentPen used to draw the transformed outline.
|
| 31 |
+
max_err: maximum approximation error in font units. For optimal results,
|
| 32 |
+
if you know the UPEM of the font, we recommend setting this to a
|
| 33 |
+
value equal, or close to UPEM / 1000.
|
| 34 |
+
reverse_direction: flip the contours' direction but keep starting point.
|
| 35 |
+
stats: a dictionary counting the point numbers of quadratic segments.
|
| 36 |
+
all_quadratic: if True (default), only quadratic b-splines are generated.
|
| 37 |
+
if False, quadratic curves or cubic curves are generated depending
|
| 38 |
+
on which one is more economical.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
def __init__(
|
| 42 |
+
self,
|
| 43 |
+
other_pen,
|
| 44 |
+
max_err,
|
| 45 |
+
reverse_direction=False,
|
| 46 |
+
stats=None,
|
| 47 |
+
all_quadratic=True,
|
| 48 |
+
):
|
| 49 |
+
if reverse_direction:
|
| 50 |
+
other_pen = ReverseContourPen(other_pen)
|
| 51 |
+
super().__init__(other_pen)
|
| 52 |
+
self.max_err = max_err
|
| 53 |
+
self.stats = stats
|
| 54 |
+
self.all_quadratic = all_quadratic
|
| 55 |
+
|
| 56 |
+
def _convert_curve(self, pt1, pt2, pt3):
|
| 57 |
+
curve = (self.current_pt, pt1, pt2, pt3)
|
| 58 |
+
result = curve_to_quadratic(curve, self.max_err, self.all_quadratic)
|
| 59 |
+
if self.stats is not None:
|
| 60 |
+
n = str(len(result) - 2)
|
| 61 |
+
self.stats[n] = self.stats.get(n, 0) + 1
|
| 62 |
+
if self.all_quadratic:
|
| 63 |
+
self.qCurveTo(*result[1:])
|
| 64 |
+
else:
|
| 65 |
+
if len(result) == 3:
|
| 66 |
+
self.qCurveTo(*result[1:])
|
| 67 |
+
else:
|
| 68 |
+
assert len(result) == 4
|
| 69 |
+
super().curveTo(*result[1:])
|
| 70 |
+
|
| 71 |
+
def curveTo(self, *points):
|
| 72 |
+
n = len(points)
|
| 73 |
+
if n == 3:
|
| 74 |
+
# this is the most common case, so we special-case it
|
| 75 |
+
self._convert_curve(*points)
|
| 76 |
+
elif n > 3:
|
| 77 |
+
for segment in decomposeSuperBezierSegment(points):
|
| 78 |
+
self._convert_curve(*segment)
|
| 79 |
+
else:
|
| 80 |
+
self.qCurveTo(*points)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
class Cu2QuPointPen(BasePointToSegmentPen):
|
| 84 |
+
"""A filter pen to convert cubic bezier curves to quadratic b-splines
|
| 85 |
+
using the FontTools PointPen protocol.
|
| 86 |
+
|
| 87 |
+
Args:
|
| 88 |
+
other_point_pen: another PointPen used to draw the transformed outline.
|
| 89 |
+
max_err: maximum approximation error in font units. For optimal results,
|
| 90 |
+
if you know the UPEM of the font, we recommend setting this to a
|
| 91 |
+
value equal, or close to UPEM / 1000.
|
| 92 |
+
reverse_direction: reverse the winding direction of all contours.
|
| 93 |
+
stats: a dictionary counting the point numbers of quadratic segments.
|
| 94 |
+
all_quadratic: if True (default), only quadratic b-splines are generated.
|
| 95 |
+
if False, quadratic curves or cubic curves are generated depending
|
| 96 |
+
on which one is more economical.
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
__points_required = {
|
| 100 |
+
"move": (1, operator.eq),
|
| 101 |
+
"line": (1, operator.eq),
|
| 102 |
+
"qcurve": (2, operator.ge),
|
| 103 |
+
"curve": (3, operator.eq),
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
def __init__(
|
| 107 |
+
self,
|
| 108 |
+
other_point_pen,
|
| 109 |
+
max_err,
|
| 110 |
+
reverse_direction=False,
|
| 111 |
+
stats=None,
|
| 112 |
+
all_quadratic=True,
|
| 113 |
+
):
|
| 114 |
+
BasePointToSegmentPen.__init__(self)
|
| 115 |
+
if reverse_direction:
|
| 116 |
+
self.pen = ReverseContourPointPen(other_point_pen)
|
| 117 |
+
else:
|
| 118 |
+
self.pen = other_point_pen
|
| 119 |
+
self.max_err = max_err
|
| 120 |
+
self.stats = stats
|
| 121 |
+
self.all_quadratic = all_quadratic
|
| 122 |
+
|
| 123 |
+
def _flushContour(self, segments):
|
| 124 |
+
assert len(segments) >= 1
|
| 125 |
+
closed = segments[0][0] != "move"
|
| 126 |
+
new_segments = []
|
| 127 |
+
prev_points = segments[-1][1]
|
| 128 |
+
prev_on_curve = prev_points[-1][0]
|
| 129 |
+
for segment_type, points in segments:
|
| 130 |
+
if segment_type == "curve":
|
| 131 |
+
for sub_points in self._split_super_bezier_segments(points):
|
| 132 |
+
on_curve, smooth, name, kwargs = sub_points[-1]
|
| 133 |
+
bcp1, bcp2 = sub_points[0][0], sub_points[1][0]
|
| 134 |
+
cubic = [prev_on_curve, bcp1, bcp2, on_curve]
|
| 135 |
+
quad = curve_to_quadratic(cubic, self.max_err, self.all_quadratic)
|
| 136 |
+
if self.stats is not None:
|
| 137 |
+
n = str(len(quad) - 2)
|
| 138 |
+
self.stats[n] = self.stats.get(n, 0) + 1
|
| 139 |
+
new_points = [(pt, False, None, {}) for pt in quad[1:-1]]
|
| 140 |
+
new_points.append((on_curve, smooth, name, kwargs))
|
| 141 |
+
if self.all_quadratic or len(new_points) == 2:
|
| 142 |
+
new_segments.append(["qcurve", new_points])
|
| 143 |
+
else:
|
| 144 |
+
new_segments.append(["curve", new_points])
|
| 145 |
+
prev_on_curve = sub_points[-1][0]
|
| 146 |
+
else:
|
| 147 |
+
new_segments.append([segment_type, points])
|
| 148 |
+
prev_on_curve = points[-1][0]
|
| 149 |
+
if closed:
|
| 150 |
+
# the BasePointToSegmentPen.endPath method that calls _flushContour
|
| 151 |
+
# rotates the point list of closed contours so that they end with
|
| 152 |
+
# the first on-curve point. We restore the original starting point.
|
| 153 |
+
new_segments = new_segments[-1:] + new_segments[:-1]
|
| 154 |
+
self._drawPoints(new_segments)
|
| 155 |
+
|
| 156 |
+
def _split_super_bezier_segments(self, points):
|
| 157 |
+
sub_segments = []
|
| 158 |
+
# n is the number of control points
|
| 159 |
+
n = len(points) - 1
|
| 160 |
+
if n == 2:
|
| 161 |
+
# a simple bezier curve segment
|
| 162 |
+
sub_segments.append(points)
|
| 163 |
+
elif n > 2:
|
| 164 |
+
# a "super" bezier; decompose it
|
| 165 |
+
on_curve, smooth, name, kwargs = points[-1]
|
| 166 |
+
num_sub_segments = n - 1
|
| 167 |
+
for i, sub_points in enumerate(
|
| 168 |
+
decomposeSuperBezierSegment([pt for pt, _, _, _ in points])
|
| 169 |
+
):
|
| 170 |
+
new_segment = []
|
| 171 |
+
for point in sub_points[:-1]:
|
| 172 |
+
new_segment.append((point, False, None, {}))
|
| 173 |
+
if i == (num_sub_segments - 1):
|
| 174 |
+
# the last on-curve keeps its original attributes
|
| 175 |
+
new_segment.append((on_curve, smooth, name, kwargs))
|
| 176 |
+
else:
|
| 177 |
+
# on-curves of sub-segments are always "smooth"
|
| 178 |
+
new_segment.append((sub_points[-1], True, None, {}))
|
| 179 |
+
sub_segments.append(new_segment)
|
| 180 |
+
else:
|
| 181 |
+
raise AssertionError("expected 2 control points, found: %d" % n)
|
| 182 |
+
return sub_segments
|
| 183 |
+
|
| 184 |
+
def _drawPoints(self, segments):
|
| 185 |
+
pen = self.pen
|
| 186 |
+
pen.beginPath()
|
| 187 |
+
last_offcurves = []
|
| 188 |
+
points_required = self.__points_required
|
| 189 |
+
for i, (segment_type, points) in enumerate(segments):
|
| 190 |
+
if segment_type in points_required:
|
| 191 |
+
n, op = points_required[segment_type]
|
| 192 |
+
assert op(len(points), n), (
|
| 193 |
+
f"illegal {segment_type!r} segment point count: "
|
| 194 |
+
f"expected {n}, got {len(points)}"
|
| 195 |
+
)
|
| 196 |
+
offcurves = points[:-1]
|
| 197 |
+
if i == 0:
|
| 198 |
+
# any off-curve points preceding the first on-curve
|
| 199 |
+
# will be appended at the end of the contour
|
| 200 |
+
last_offcurves = offcurves
|
| 201 |
+
else:
|
| 202 |
+
for pt, smooth, name, kwargs in offcurves:
|
| 203 |
+
pen.addPoint(pt, None, smooth, name, **kwargs)
|
| 204 |
+
pt, smooth, name, kwargs = points[-1]
|
| 205 |
+
if pt is None:
|
| 206 |
+
assert segment_type == "qcurve"
|
| 207 |
+
# special quadratic contour with no on-curve points:
|
| 208 |
+
# we need to skip the "None" point. See also the Pen
|
| 209 |
+
# protocol's qCurveTo() method and fontTools.pens.basePen
|
| 210 |
+
pass
|
| 211 |
+
else:
|
| 212 |
+
pen.addPoint(pt, segment_type, smooth, name, **kwargs)
|
| 213 |
+
else:
|
| 214 |
+
raise AssertionError("unexpected segment type: %r" % segment_type)
|
| 215 |
+
for pt, smooth, name, kwargs in last_offcurves:
|
| 216 |
+
pen.addPoint(pt, None, smooth, name, **kwargs)
|
| 217 |
+
pen.endPath()
|
| 218 |
+
|
| 219 |
+
def addComponent(self, baseGlyphName, transformation):
|
| 220 |
+
assert self.currentPath is None
|
| 221 |
+
self.pen.addComponent(baseGlyphName, transformation)
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class Cu2QuMultiPen:
|
| 225 |
+
"""A filter multi-pen to convert cubic bezier curves to quadratic b-splines
|
| 226 |
+
in a interpolation-compatible manner, using the FontTools SegmentPen protocol.
|
| 227 |
+
|
| 228 |
+
Args:
|
| 229 |
+
|
| 230 |
+
other_pens: list of SegmentPens used to draw the transformed outlines.
|
| 231 |
+
max_err: maximum approximation error in font units. For optimal results,
|
| 232 |
+
if you know the UPEM of the font, we recommend setting this to a
|
| 233 |
+
value equal, or close to UPEM / 1000.
|
| 234 |
+
reverse_direction: flip the contours' direction but keep starting point.
|
| 235 |
+
|
| 236 |
+
This pen does not follow the normal SegmentPen protocol. Instead, its
|
| 237 |
+
moveTo/lineTo/qCurveTo/curveTo methods take a list of tuples that are
|
| 238 |
+
arguments that would normally be passed to a SegmentPen, one item for
|
| 239 |
+
each of the pens in other_pens.
|
| 240 |
+
"""
|
| 241 |
+
|
| 242 |
+
# TODO Simplify like 3e8ebcdce592fe8a59ca4c3a294cc9724351e1ce
|
| 243 |
+
# Remove start_pts and _add_moveTO
|
| 244 |
+
|
| 245 |
+
def __init__(self, other_pens, max_err, reverse_direction=False):
|
| 246 |
+
if reverse_direction:
|
| 247 |
+
other_pens = [
|
| 248 |
+
ReverseContourPen(pen, outputImpliedClosingLine=True)
|
| 249 |
+
for pen in other_pens
|
| 250 |
+
]
|
| 251 |
+
self.pens = other_pens
|
| 252 |
+
self.max_err = max_err
|
| 253 |
+
self.start_pts = None
|
| 254 |
+
self.current_pts = None
|
| 255 |
+
|
| 256 |
+
def _check_contour_is_open(self):
|
| 257 |
+
if self.current_pts is None:
|
| 258 |
+
raise AssertionError("moveTo is required")
|
| 259 |
+
|
| 260 |
+
def _check_contour_is_closed(self):
|
| 261 |
+
if self.current_pts is not None:
|
| 262 |
+
raise AssertionError("closePath or endPath is required")
|
| 263 |
+
|
| 264 |
+
def _add_moveTo(self):
|
| 265 |
+
if self.start_pts is not None:
|
| 266 |
+
for pt, pen in zip(self.start_pts, self.pens):
|
| 267 |
+
pen.moveTo(*pt)
|
| 268 |
+
self.start_pts = None
|
| 269 |
+
|
| 270 |
+
def moveTo(self, pts):
|
| 271 |
+
self._check_contour_is_closed()
|
| 272 |
+
self.start_pts = self.current_pts = pts
|
| 273 |
+
self._add_moveTo()
|
| 274 |
+
|
| 275 |
+
def lineTo(self, pts):
|
| 276 |
+
self._check_contour_is_open()
|
| 277 |
+
self._add_moveTo()
|
| 278 |
+
for pt, pen in zip(pts, self.pens):
|
| 279 |
+
pen.lineTo(*pt)
|
| 280 |
+
self.current_pts = pts
|
| 281 |
+
|
| 282 |
+
def qCurveTo(self, pointsList):
|
| 283 |
+
self._check_contour_is_open()
|
| 284 |
+
if len(pointsList[0]) == 1:
|
| 285 |
+
self.lineTo([(points[0],) for points in pointsList])
|
| 286 |
+
return
|
| 287 |
+
self._add_moveTo()
|
| 288 |
+
current_pts = []
|
| 289 |
+
for points, pen in zip(pointsList, self.pens):
|
| 290 |
+
pen.qCurveTo(*points)
|
| 291 |
+
current_pts.append((points[-1],))
|
| 292 |
+
self.current_pts = current_pts
|
| 293 |
+
|
| 294 |
+
def _curves_to_quadratic(self, pointsList):
|
| 295 |
+
curves = []
|
| 296 |
+
for current_pt, points in zip(self.current_pts, pointsList):
|
| 297 |
+
curves.append(current_pt + points)
|
| 298 |
+
quadratics = curves_to_quadratic(curves, [self.max_err] * len(curves))
|
| 299 |
+
pointsList = []
|
| 300 |
+
for quadratic in quadratics:
|
| 301 |
+
pointsList.append(quadratic[1:])
|
| 302 |
+
self.qCurveTo(pointsList)
|
| 303 |
+
|
| 304 |
+
def curveTo(self, pointsList):
|
| 305 |
+
self._check_contour_is_open()
|
| 306 |
+
self._curves_to_quadratic(pointsList)
|
| 307 |
+
|
| 308 |
+
def closePath(self):
|
| 309 |
+
self._check_contour_is_open()
|
| 310 |
+
if self.start_pts is None:
|
| 311 |
+
for pen in self.pens:
|
| 312 |
+
pen.closePath()
|
| 313 |
+
self.current_pts = self.start_pts = None
|
| 314 |
+
|
| 315 |
+
def endPath(self):
|
| 316 |
+
self._check_contour_is_open()
|
| 317 |
+
if self.start_pts is None:
|
| 318 |
+
for pen in self.pens:
|
| 319 |
+
pen.endPath()
|
| 320 |
+
self.current_pts = self.start_pts = None
|
| 321 |
+
|
| 322 |
+
def addComponent(self, glyphName, transformations):
|
| 323 |
+
self._check_contour_is_closed()
|
| 324 |
+
for trans, pen in zip(transformations, self.pens):
|
| 325 |
+
pen.addCompon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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""fontTools.pens.pointInsidePen -- Pen implementing "point inside" testing
|
| 2 |
+
for shapes.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from fontTools.pens.basePen import BasePen
|
| 6 |
+
from fontTools.misc.bezierTools import solveQuadratic, solveCubic
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
__all__ = ["PointInsidePen"]
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class PointInsidePen(BasePen):
|
| 13 |
+
"""This pen implements "point inside" testing: to test whether
|
| 14 |
+
a given point lies inside the shape (black) or outside (white).
|
| 15 |
+
Instances of this class can be recycled, as long as the
|
| 16 |
+
setTestPoint() method is used to set the new point to test.
|
| 17 |
+
|
| 18 |
+
:Example:
|
| 19 |
+
.. code-block::
|
| 20 |
+
|
| 21 |
+
pen = PointInsidePen(glyphSet, (100, 200))
|
| 22 |
+
outline.draw(pen)
|
| 23 |
+
isInside = pen.getResult()
|
| 24 |
+
|
| 25 |
+
Both the even-odd algorithm and the non-zero-winding-rule
|
| 26 |
+
algorithm are implemented. The latter is the default, specify
|
| 27 |
+
True for the evenOdd argument of __init__ or setTestPoint
|
| 28 |
+
to use the even-odd algorithm.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
# This class implements the classical "shoot a ray from the test point
|
| 32 |
+
# to infinity and count how many times it intersects the outline" (as well
|
| 33 |
+
# as the non-zero variant, where the counter is incremented if the outline
|
| 34 |
+
# intersects the ray in one direction and decremented if it intersects in
|
| 35 |
+
# the other direction).
|
| 36 |
+
# I found an amazingly clear explanation of the subtleties involved in
|
| 37 |
+
# implementing this correctly for polygons here:
|
| 38 |
+
# http://graphics.cs.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html
|
| 39 |
+
# I extended the principles outlined on that page to curves.
|
| 40 |
+
|
| 41 |
+
def __init__(self, glyphSet, testPoint, evenOdd=False):
|
| 42 |
+
BasePen.__init__(self, glyphSet)
|
| 43 |
+
self.setTestPoint(testPoint, evenOdd)
|
| 44 |
+
|
| 45 |
+
def setTestPoint(self, testPoint, evenOdd=False):
|
| 46 |
+
"""Set the point to test. Call this _before_ the outline gets drawn."""
|
| 47 |
+
self.testPoint = testPoint
|
| 48 |
+
self.evenOdd = evenOdd
|
| 49 |
+
self.firstPoint = None
|
| 50 |
+
self.intersectionCount = 0
|
| 51 |
+
|
| 52 |
+
def getWinding(self):
|
| 53 |
+
if self.firstPoint is not None:
|
| 54 |
+
# always make sure the sub paths are closed; the algorithm only works
|
| 55 |
+
# for closed paths.
|
| 56 |
+
self.closePath()
|
| 57 |
+
return self.intersectionCount
|
| 58 |
+
|
| 59 |
+
def getResult(self):
|
| 60 |
+
"""After the shape has been drawn, getResult() returns True if the test
|
| 61 |
+
point lies within the (black) shape, and False if it doesn't.
|
| 62 |
+
"""
|
| 63 |
+
winding = self.getWinding()
|
| 64 |
+
if self.evenOdd:
|
| 65 |
+
result = winding % 2
|
| 66 |
+
else: # non-zero
|
| 67 |
+
result = self.intersectionCount != 0
|
| 68 |
+
return not not result
|
| 69 |
+
|
| 70 |
+
def _addIntersection(self, goingUp):
|
| 71 |
+
if self.evenOdd or goingUp:
|
| 72 |
+
self.intersectionCount += 1
|
| 73 |
+
else:
|
| 74 |
+
self.intersectionCount -= 1
|
| 75 |
+
|
| 76 |
+
def _moveTo(self, point):
|
| 77 |
+
if self.firstPoint is not None:
|
| 78 |
+
# always make sure the sub paths are closed; the algorithm only works
|
| 79 |
+
# for closed paths.
|
| 80 |
+
self.closePath()
|
| 81 |
+
self.firstPoint = point
|
| 82 |
+
|
| 83 |
+
def _lineTo(self, point):
|
| 84 |
+
x, y = self.testPoint
|
| 85 |
+
x1, y1 = self._getCurrentPoint()
|
| 86 |
+
x2, y2 = point
|
| 87 |
+
|
| 88 |
+
if x1 < x and x2 < x:
|
| 89 |
+
return
|
| 90 |
+
if y1 < y and y2 < y:
|
| 91 |
+
return
|
| 92 |
+
if y1 >= y and y2 >= y:
|
| 93 |
+
return
|
| 94 |
+
|
| 95 |
+
dx = x2 - x1
|
| 96 |
+
dy = y2 - y1
|
| 97 |
+
t = (y - y1) / dy
|
| 98 |
+
ix = dx * t + x1
|
| 99 |
+
if ix < x:
|
| 100 |
+
return
|
| 101 |
+
self._addIntersection(y2 > y1)
|
| 102 |
+
|
| 103 |
+
def _curveToOne(self, bcp1, bcp2, point):
|
| 104 |
+
x, y = self.testPoint
|
| 105 |
+
x1, y1 = self._getCurrentPoint()
|
| 106 |
+
x2, y2 = bcp1
|
| 107 |
+
x3, y3 = bcp2
|
| 108 |
+
x4, y4 = point
|
| 109 |
+
|
| 110 |
+
if x1 < x and x2 < x and x3 < x and x4 < x:
|
| 111 |
+
return
|
| 112 |
+
if y1 < y and y2 < y and y3 < y and y4 < y:
|
| 113 |
+
return
|
| 114 |
+
if y1 >= y and y2 >= y and y3 >= y and y4 >= y:
|
| 115 |
+
return
|
| 116 |
+
|
| 117 |
+
dy = y1
|
| 118 |
+
cy = (y2 - dy) * 3.0
|
| 119 |
+
by = (y3 - y2) * 3.0 - cy
|
| 120 |
+
ay = y4 - dy - cy - by
|
| 121 |
+
solutions = sorted(solveCubic(ay, by, cy, dy - y))
|
| 122 |
+
solutions = [t for t in solutions if -0.0 <= t <= 1.0]
|
| 123 |
+
if not solutions:
|
| 124 |
+
return
|
| 125 |
+
|
| 126 |
+
dx = x1
|
| 127 |
+
cx = (x2 - dx) * 3.0
|
| 128 |
+
bx = (x3 - x2) * 3.0 - cx
|
| 129 |
+
ax = x4 - dx - cx - bx
|
| 130 |
+
|
| 131 |
+
above = y1 >= y
|
| 132 |
+
lastT = None
|
| 133 |
+
for t in solutions:
|
| 134 |
+
if t == lastT:
|
| 135 |
+
continue
|
| 136 |
+
lastT = t
|
| 137 |
+
t2 = t * t
|
| 138 |
+
t3 = t2 * t
|
| 139 |
+
|
| 140 |
+
direction = 3 * ay * t2 + 2 * by * t + cy
|
| 141 |
+
incomingGoingUp = outgoingGoingUp = direction > 0.0
|
| 142 |
+
if direction == 0.0:
|
| 143 |
+
direction = 6 * ay * t + 2 * by
|
| 144 |
+
outgoingGoingUp = direction > 0.0
|
| 145 |
+
incomingGoingUp = not outgoingGoingUp
|
| 146 |
+
if direction == 0.0:
|
| 147 |
+
direction = ay
|
| 148 |
+
incomingGoingUp = outgoingGoingUp = direction > 0.0
|
| 149 |
+
|
| 150 |
+
xt = ax * t3 + bx * t2 + cx * t + dx
|
| 151 |
+
if xt < x:
|
| 152 |
+
continue
|
| 153 |
+
|
| 154 |
+
if t in (0.0, -0.0):
|
| 155 |
+
if not outgoingGoingUp:
|
| 156 |
+
self._addIntersection(outgoingGoingUp)
|
| 157 |
+
elif t == 1.0:
|
| 158 |
+
if incomingGoingUp:
|
| 159 |
+
self._addIntersection(incomingGoingUp)
|
| 160 |
+
else:
|
| 161 |
+
if incomingGoingUp == outgoingGoingUp:
|
| 162 |
+
self._addIntersection(outgoingGoingUp)
|
| 163 |
+
# else:
|
| 164 |
+
# we're not really intersecting, merely touching
|
| 165 |
+
|
| 166 |
+
def _qCurveToOne_unfinished(self, bcp, point):
|
| 167 |
+
# XXX need to finish this, for now doing it through a cubic
|
| 168 |
+
# (BasePen implements _qCurveTo in terms of a cubic) will
|
| 169 |
+
# have to do.
|
| 170 |
+
x, y = self.testPoint
|
| 171 |
+
x1, y1 = self._getCurrentPoint()
|
| 172 |
+
x2, y2 = bcp
|
| 173 |
+
x3, y3 = point
|
| 174 |
+
c = y1
|
| 175 |
+
b = (y2 - c) * 2.0
|
| 176 |
+
a = y3 - c - b
|
| 177 |
+
solutions = sorted(solveQuadratic(a, b, c - y))
|
| 178 |
+
solutions = [
|
| 179 |
+
t for t in solutions if ZERO_MINUS_EPSILON <= t <= ONE_PLUS_EPSILON
|
| 180 |
+
]
|
| 181 |
+
if not solutions:
|
| 182 |
+
return
|
| 183 |
+
# XXX
|
| 184 |
+
|
| 185 |
+
def _closePath(self):
|
| 186 |
+
if self._getCurrentPoint() != self.firstPoint:
|
| 187 |
+
self.lineTo(self.firstPoint)
|
| 188 |
+
self.firstPoint = None
|
| 189 |
+
|
| 190 |
+
def _endPath(self):
|
| 191 |
+
"""Insideness is not defined for open contours."""
|
| 192 |
+
raise NotImplementedError
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/qtPen.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.pens.basePen import BasePen
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
__all__ = ["QtPen"]
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class QtPen(BasePen):
|
| 8 |
+
def __init__(self, glyphSet, path=None):
|
| 9 |
+
BasePen.__init__(self, glyphSet)
|
| 10 |
+
if path is None:
|
| 11 |
+
from PyQt5.QtGui import QPainterPath
|
| 12 |
+
|
| 13 |
+
path = QPainterPath()
|
| 14 |
+
self.path = path
|
| 15 |
+
|
| 16 |
+
def _moveTo(self, p):
|
| 17 |
+
self.path.moveTo(*p)
|
| 18 |
+
|
| 19 |
+
def _lineTo(self, p):
|
| 20 |
+
self.path.lineTo(*p)
|
| 21 |
+
|
| 22 |
+
def _curveToOne(self, p1, p2, p3):
|
| 23 |
+
self.path.cubicTo(*p1, *p2, *p3)
|
| 24 |
+
|
| 25 |
+
def _qCurveToO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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pen recording operations that can be accessed or replayed."""
|
| 2 |
+
|
| 3 |
+
from fontTools.pens.basePen import AbstractPen, DecomposingPen
|
| 4 |
+
from fontTools.pens.pointPen import AbstractPointPen, DecomposingPointPen
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
__all__ = [
|
| 8 |
+
"replayRecording",
|
| 9 |
+
"RecordingPen",
|
| 10 |
+
"DecomposingRecordingPen",
|
| 11 |
+
"DecomposingRecordingPointPen",
|
| 12 |
+
"RecordingPointPen",
|
| 13 |
+
"lerpRecordings",
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def replayRecording(recording, pen):
|
| 18 |
+
"""Replay a recording, as produced by RecordingPen or DecomposingRecordingPen,
|
| 19 |
+
to a pen.
|
| 20 |
+
|
| 21 |
+
Note that recording does not have to be produced by those pens.
|
| 22 |
+
It can be any iterable of tuples of method name and tuple-of-arguments.
|
| 23 |
+
Likewise, pen can be any objects receiving those method calls.
|
| 24 |
+
"""
|
| 25 |
+
for operator, operands in recording:
|
| 26 |
+
getattr(pen, operator)(*operands)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class RecordingPen(AbstractPen):
|
| 30 |
+
"""Pen recording operations that can be accessed or replayed.
|
| 31 |
+
|
| 32 |
+
The recording can be accessed as pen.value; or replayed using
|
| 33 |
+
pen.replay(otherPen).
|
| 34 |
+
|
| 35 |
+
:Example:
|
| 36 |
+
.. code-block::
|
| 37 |
+
|
| 38 |
+
from fontTools.ttLib import TTFont
|
| 39 |
+
from fontTools.pens.recordingPen import RecordingPen
|
| 40 |
+
|
| 41 |
+
glyph_name = 'dollar'
|
| 42 |
+
font_path = 'MyFont.otf'
|
| 43 |
+
|
| 44 |
+
font = TTFont(font_path)
|
| 45 |
+
glyphset = font.getGlyphSet()
|
| 46 |
+
glyph = glyphset[glyph_name]
|
| 47 |
+
|
| 48 |
+
pen = RecordingPen()
|
| 49 |
+
glyph.draw(pen)
|
| 50 |
+
print(pen.value)
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(self):
|
| 54 |
+
self.value = []
|
| 55 |
+
|
| 56 |
+
def moveTo(self, p0):
|
| 57 |
+
self.value.append(("moveTo", (p0,)))
|
| 58 |
+
|
| 59 |
+
def lineTo(self, p1):
|
| 60 |
+
self.value.append(("lineTo", (p1,)))
|
| 61 |
+
|
| 62 |
+
def qCurveTo(self, *points):
|
| 63 |
+
self.value.append(("qCurveTo", points))
|
| 64 |
+
|
| 65 |
+
def curveTo(self, *points):
|
| 66 |
+
self.value.append(("curveTo", points))
|
| 67 |
+
|
| 68 |
+
def closePath(self):
|
| 69 |
+
self.value.append(("closePath", ()))
|
| 70 |
+
|
| 71 |
+
def endPath(self):
|
| 72 |
+
self.value.append(("endPath", ()))
|
| 73 |
+
|
| 74 |
+
def addComponent(self, glyphName, transformation):
|
| 75 |
+
self.value.append(("addComponent", (glyphName, transformation)))
|
| 76 |
+
|
| 77 |
+
def addVarComponent(self, glyphName, transformation, location):
|
| 78 |
+
self.value.append(("addVarComponent", (glyphName, transformation, location)))
|
| 79 |
+
|
| 80 |
+
def replay(self, pen):
|
| 81 |
+
replayRecording(self.value, pen)
|
| 82 |
+
|
| 83 |
+
draw = replay
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class DecomposingRecordingPen(DecomposingPen, RecordingPen):
|
| 87 |
+
"""Same as RecordingPen, except that it doesn't keep components
|
| 88 |
+
as references, but draws them decomposed as regular contours.
|
| 89 |
+
|
| 90 |
+
The constructor takes a required 'glyphSet' positional argument,
|
| 91 |
+
a dictionary of glyph objects (i.e. with a 'draw' method) keyed
|
| 92 |
+
by thir name; other arguments are forwarded to the DecomposingPen's
|
| 93 |
+
constructor::
|
| 94 |
+
|
| 95 |
+
>>> class SimpleGlyph(object):
|
| 96 |
+
... def draw(self, pen):
|
| 97 |
+
... pen.moveTo((0, 0))
|
| 98 |
+
... pen.curveTo((1, 1), (2, 2), (3, 3))
|
| 99 |
+
... pen.closePath()
|
| 100 |
+
>>> class CompositeGlyph(object):
|
| 101 |
+
... def draw(self, pen):
|
| 102 |
+
... pen.addComponent('a', (1, 0, 0, 1, -1, 1))
|
| 103 |
+
>>> class MissingComponent(object):
|
| 104 |
+
... def draw(self, pen):
|
| 105 |
+
... pen.addComponent('foobar', (1, 0, 0, 1, 0, 0))
|
| 106 |
+
>>> class FlippedComponent(object):
|
| 107 |
+
... def draw(self, pen):
|
| 108 |
+
... pen.addComponent('a', (-1, 0, 0, 1, 0, 0))
|
| 109 |
+
>>> glyphSet = {
|
| 110 |
+
... 'a': SimpleGlyph(),
|
| 111 |
+
... 'b': CompositeGlyph(),
|
| 112 |
+
... 'c': MissingComponent(),
|
| 113 |
+
... 'd': FlippedComponent(),
|
| 114 |
+
... }
|
| 115 |
+
>>> for name, glyph in sorted(glyphSet.items()):
|
| 116 |
+
... pen = DecomposingRecordingPen(glyphSet)
|
| 117 |
+
... try:
|
| 118 |
+
... glyph.draw(pen)
|
| 119 |
+
... except pen.MissingComponentError:
|
| 120 |
+
... pass
|
| 121 |
+
... print("{}: {}".format(name, pen.value))
|
| 122 |
+
a: [('moveTo', ((0, 0),)), ('curveTo', ((1, 1), (2, 2), (3, 3))), ('closePath', ())]
|
| 123 |
+
b: [('moveTo', ((-1, 1),)), ('curveTo', ((0, 2), (1, 3), (2, 4))), ('closePath', ())]
|
| 124 |
+
c: []
|
| 125 |
+
d: [('moveTo', ((0, 0),)), ('curveTo', ((-1, 1), (-2, 2), (-3, 3))), ('closePath', ())]
|
| 126 |
+
|
| 127 |
+
>>> for name, glyph in sorted(glyphSet.items()):
|
| 128 |
+
... pen = DecomposingRecordingPen(
|
| 129 |
+
... glyphSet, skipMissingComponents=True, reverseFlipped=True,
|
| 130 |
+
... )
|
| 131 |
+
... glyph.draw(pen)
|
| 132 |
+
... print("{}: {}".format(name, pen.value))
|
| 133 |
+
a: [('moveTo', ((0, 0),)), ('curveTo', ((1, 1), (2, 2), (3, 3))), ('closePath', ())]
|
| 134 |
+
b: [('moveTo', ((-1, 1),)), ('curveTo', ((0, 2), (1, 3), (2, 4))), ('closePath', ())]
|
| 135 |
+
c: []
|
| 136 |
+
d: [('moveTo', ((0, 0),)), ('lineTo', ((-3, 3),)), ('curveTo', ((-2, 2), (-1, 1), (0, 0))), ('closePath', ())]
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
# raises MissingComponentError(KeyError) if base glyph is not found in glyphSet
|
| 140 |
+
skipMissingComponents = False
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
class RecordingPointPen(AbstractPointPen):
|
| 144 |
+
"""PointPen recording operations that can be accessed or replayed.
|
| 145 |
+
|
| 146 |
+
The recording can be accessed as pen.value; or replayed using
|
| 147 |
+
pointPen.replay(otherPointPen).
|
| 148 |
+
|
| 149 |
+
:Example:
|
| 150 |
+
.. code-block::
|
| 151 |
+
|
| 152 |
+
from defcon import Font
|
| 153 |
+
from fontTools.pens.recordingPen import RecordingPointPen
|
| 154 |
+
|
| 155 |
+
glyph_name = 'a'
|
| 156 |
+
font_path = 'MyFont.ufo'
|
| 157 |
+
|
| 158 |
+
font = Font(font_path)
|
| 159 |
+
glyph = font[glyph_name]
|
| 160 |
+
|
| 161 |
+
pen = RecordingPointPen()
|
| 162 |
+
glyph.drawPoints(pen)
|
| 163 |
+
print(pen.value)
|
| 164 |
+
|
| 165 |
+
new_glyph = font.newGlyph('b')
|
| 166 |
+
pen.replay(new_glyph.getPointPen())
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
def __init__(self):
|
| 170 |
+
self.value = []
|
| 171 |
+
|
| 172 |
+
def beginPath(self, identifier=None, **kwargs):
|
| 173 |
+
if identifier is not None:
|
| 174 |
+
kwargs["identifier"] = identifier
|
| 175 |
+
self.value.append(("beginPath", (), kwargs))
|
| 176 |
+
|
| 177 |
+
def endPath(self):
|
| 178 |
+
self.value.append(("endPath", (), {}))
|
| 179 |
+
|
| 180 |
+
def addPoint(
|
| 181 |
+
self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
|
| 182 |
+
):
|
| 183 |
+
if identifier is not None:
|
| 184 |
+
kwargs["identifier"] = identifier
|
| 185 |
+
self.value.append(("addPoint", (pt, segmentType, smooth, name), kwargs))
|
| 186 |
+
|
| 187 |
+
def addComponent(self, baseGlyphName, transformation, identifier=None, **kwargs):
|
| 188 |
+
if identifier is not None:
|
| 189 |
+
kwargs["identifier"] = identifier
|
| 190 |
+
self.value.append(("addComponent", (baseGlyphName, transformation), kwargs))
|
| 191 |
+
|
| 192 |
+
def addVarComponent(
|
| 193 |
+
self, baseGlyphName, transformation, location, identifier=None, **kwargs
|
| 194 |
+
):
|
| 195 |
+
if identifier is not None:
|
| 196 |
+
kwargs["identifier"] = identifier
|
| 197 |
+
self.value.append(
|
| 198 |
+
("addVarComponent", (baseGlyphName, transformation, location), kwargs)
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
def replay(self, pointPen):
|
| 202 |
+
for operator, args, kwargs in self.value:
|
| 203 |
+
getattr(pointPen, operator)(*args, **kwargs)
|
| 204 |
+
|
| 205 |
+
drawPoints = replay
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class DecomposingRecordingPointPen(DecomposingPointPen, RecordingPointPen):
|
| 209 |
+
"""Same as RecordingPointPen, except that it doesn't keep components
|
| 210 |
+
as references, but draws them decomposed as regular contours.
|
| 211 |
+
|
| 212 |
+
The constructor takes a required 'glyphSet' positional argument,
|
| 213 |
+
a dictionary of pointPen-drawable glyph objects (i.e. with a 'drawPoints' method)
|
| 214 |
+
keyed by thir name; other arguments are forwarded to the DecomposingPointPen's
|
| 215 |
+
constructor::
|
| 216 |
+
|
| 217 |
+
>>> from pprint import pprint
|
| 218 |
+
>>> class SimpleGlyph(object):
|
| 219 |
+
... def drawPoints(self, pen):
|
| 220 |
+
... pen.beginPath()
|
| 221 |
+
... pen.addPoint((0, 0), "line")
|
| 222 |
+
... pen.addPoint((1, 1))
|
| 223 |
+
... pen.addPoint((2, 2))
|
| 224 |
+
... pen.addPoint((3, 3), "curve")
|
| 225 |
+
... pen.endPath()
|
| 226 |
+
>>> class CompositeGlyph(object):
|
| 227 |
+
... def drawPoints(self, pen):
|
| 228 |
+
... pen.addComponent('a', (1, 0, 0, 1, -1, 1))
|
| 229 |
+
>>> class MissingComponent(object):
|
| 230 |
+
... def drawPoints(self, pen):
|
| 231 |
+
... pen.addComponent('foobar', (1, 0, 0, 1, 0, 0))
|
| 232 |
+
>>> class FlippedComponent(object):
|
| 233 |
+
... def drawPoints(self, pen):
|
| 234 |
+
... pen.addComponent('a', (-1, 0, 0, 1, 0, 0))
|
| 235 |
+
>>> glyphSet = {
|
| 236 |
+
... 'a': SimpleGlyph(),
|
| 237 |
+
... 'b': CompositeGlyph(),
|
| 238 |
+
... 'c': MissingComponent(),
|
| 239 |
+
... 'd': FlippedComponent(),
|
| 240 |
+
... }
|
| 241 |
+
>>> for name, glyph in sorted(glyphSet.items()):
|
| 242 |
+
... pen = DecomposingRecordingPointPen(glyphSet)
|
| 243 |
+
... try:
|
| 244 |
+
... glyph.drawPoints(pen)
|
| 245 |
+
... except pen.MissingComponentError:
|
| 246 |
+
... pass
|
| 247 |
+
... pprint({name: pen.value})
|
| 248 |
+
{'a': [('beginPath', (), {}),
|
| 249 |
+
('addPoint', ((0, 0), 'line', False, None), {}),
|
| 250 |
+
('addPoint', ((1, 1), None, False, None), {}),
|
| 251 |
+
('addPoint', ((2, 2), None, False, None), {}),
|
| 252 |
+
('addPoint', ((3, 3), 'curve', False, None), {}),
|
| 253 |
+
('endPath', (), {})]}
|
| 254 |
+
{'b': [('beginPath', (), {}),
|
| 255 |
+
('addPoint', ((-1, 1), 'line', False, None), {}),
|
| 256 |
+
('addPoint', ((0, 2), None, False, None), {}),
|
| 257 |
+
('addPoint', ((1, 3), None, False, None), {}),
|
| 258 |
+
('addPoint', ((2, 4), 'curve', False, None), {}),
|
| 259 |
+
('endPath', (), {})]}
|
| 260 |
+
{'c': []}
|
| 261 |
+
{'d': [('beginPath', (), {}),
|
| 262 |
+
('addPoint', ((0, 0), 'line', False, None), {}),
|
| 263 |
+
('addPoint', ((-1, 1), None, False, None), {}),
|
| 264 |
+
('addPoint', ((-2, 2), None, False, None), {}),
|
| 265 |
+
('addPoint', ((-3, 3), 'curve', False, None), {}),
|
| 266 |
+
('endPath', (), {})]}
|
| 267 |
+
|
| 268 |
+
>>> for name, glyph in sorted(glyphSet.items()):
|
| 269 |
+
... pen = DecomposingRecordingPointPen(
|
| 270 |
+
... glyphSet, skipMissingComponents=True, reverseFlipped=True,
|
| 271 |
+
... )
|
| 272 |
+
... glyph.drawPoints(pen)
|
| 273 |
+
... pprint({name: pen.value})
|
| 274 |
+
{'a': [('beginPath', (), {}),
|
| 275 |
+
('addPoint', ((0, 0), 'line', False, None), {}),
|
| 276 |
+
('addPoint', ((1, 1), None, False, None), {}),
|
| 277 |
+
('addPoint', ((2, 2), None, False, None), {}),
|
| 278 |
+
('addPoint', ((3, 3), 'curve', False, None), {}),
|
| 279 |
+
('endPath', (), {})]}
|
| 280 |
+
{'b': [('beginPath', (), {}),
|
| 281 |
+
('addPoint', ((-1, 1), 'line', False, None), {}),
|
| 282 |
+
('addPoint', ((0, 2), None, False, None), {}),
|
| 283 |
+
('addPoint', ((1, 3), None, False, None), {}),
|
| 284 |
+
('addPoint', ((2, 4), 'curve', False, None), {}),
|
| 285 |
+
('endPath', (), {})]}
|
| 286 |
+
{'c': []}
|
| 287 |
+
{'d': [('beginPath', (), {}),
|
| 288 |
+
('addPoint', ((0, 0), 'curve', False, None), {}),
|
| 289 |
+
('addPoint', ((-3, 3), 'line', False, None), {}),
|
| 290 |
+
('addPoint', ((-2, 2), None, False, None), {}),
|
| 291 |
+
('addPoint', ((-1, 1), None, False, None), {}),
|
| 292 |
+
('endPath', (), {})]}
|
| 293 |
+
"""
|
| 294 |
+
|
| 295 |
+
# raises MissingComponentError(KeyError) if base glyph is not found in glyphSet
|
| 296 |
+
skipMissingComponents = False
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def lerpRecordings(recording1, recording2, factor=0.5):
|
| 300 |
+
"""Linearly interpolate between two recordings. The recordings
|
| 301 |
+
must be decomposed, i.e. they must not contain any components.
|
| 302 |
+
|
| 303 |
+
Factor is typically between 0 and 1. 0 means the first recording,
|
| 304 |
+
1 means the second recording, and 0.5 means the average of the
|
| 305 |
+
two recordings. Other values are possible, and can be useful to
|
| 306 |
+
extrapolate. Defaults to 0.5.
|
| 307 |
+
|
| 308 |
+
Returns a generator with the new recording.
|
| 309 |
+
"""
|
| 310 |
+
if len(recording1) != len(recording2):
|
| 311 |
+
raise ValueError(
|
| 312 |
+
"Mismatched lengths: %d and %d" % (len(recording1), len(recording2))
|
| 313 |
+
)
|
| 314 |
+
for (op1, args1), (op2, args2) in zip(recording1, recording2):
|
| 315 |
+
if op1 != op2:
|
| 316 |
+
raise ValueError("Mismatched operations: %s, %s" % (op1, op2))
|
| 317 |
+
if op1 == "addComponent":
|
| 318 |
+
raise ValueError("Cannot interpolate components")
|
| 319 |
+
else:
|
| 320 |
+
mid_args = [
|
| 321 |
+
(x1 + (x2 - x1) * factor, y1 + (y2 - y1) * factor)
|
| 322 |
+
for (x1, y1), (x2, y2) in zip(args1, args2)
|
| 323 |
+
]
|
| 324 |
+
yield (op1, mid_args)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if __name__ == "__main__":
|
| 328 |
+
pen = RecordingPen()
|
| 329 |
+
pen.moveTo((0, 0))
|
| 330 |
+
pen.lineTo((0, 100))
|
| 331 |
+
pen.curveTo((50, 75), (60, 50), (50, 25))
|
| 332 |
+
pen.closePath()
|
| 333 |
+
from pprint import pprint
|
| 334 |
+
|
| 335 |
+
pprint(pen.value)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/reportLabPen.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.pens.basePen import BasePen
|
| 2 |
+
from reportlab.graphics.shapes import Path
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
__all__ = ["ReportLabPen"]
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class ReportLabPen(BasePen):
|
| 9 |
+
"""A pen for drawing onto a ``reportlab.graphics.shapes.Path`` object."""
|
| 10 |
+
|
| 11 |
+
def __init__(self, glyphSet, path=None):
|
| 12 |
+
BasePen.__init__(self, glyphSet)
|
| 13 |
+
if path is None:
|
| 14 |
+
path = Path()
|
| 15 |
+
self.path = path
|
| 16 |
+
|
| 17 |
+
def _moveTo(self, p):
|
| 18 |
+
(x, y) = p
|
| 19 |
+
self.path.moveTo(x, y)
|
| 20 |
+
|
| 21 |
+
def _lineTo(self, p):
|
| 22 |
+
(x, y) = p
|
| 23 |
+
self.path.lineTo(x, y)
|
| 24 |
+
|
| 25 |
+
def _curveToOne(self, p1, p2, p3):
|
| 26 |
+
(x1, y1) = p1
|
| 27 |
+
(x2, y2) = p2
|
| 28 |
+
(x3, y3) = p3
|
| 29 |
+
self.path.curveTo(x1, y1, x2, y2, x3, y3)
|
| 30 |
+
|
| 31 |
+
def _closePath(self):
|
| 32 |
+
self.path.closePath()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
import sys
|
| 37 |
+
|
| 38 |
+
if len(sys.argv) < 3:
|
| 39 |
+
print(
|
| 40 |
+
"Usage: reportLabPen.py <OTF/TTF font> <glyphname> [<image file to create>]"
|
| 41 |
+
)
|
| 42 |
+
print(
|
| 43 |
+
" If no image file name is created, by default <glyphname>.png is created."
|
| 44 |
+
)
|
| 45 |
+
print(" example: reportLabPen.py Arial.TTF R test.png")
|
| 46 |
+
print(
|
| 47 |
+
" (The file format will be PNG, regardless of the image file name supplied)"
|
| 48 |
+
)
|
| 49 |
+
sys.exit(0)
|
| 50 |
+
|
| 51 |
+
from fontTools.ttLib import TTFont
|
| 52 |
+
from reportlab.lib import colors
|
| 53 |
+
|
| 54 |
+
path = sys.argv[1]
|
| 55 |
+
glyphName = sys.argv[2]
|
| 56 |
+
if len(sys.argv) > 3:
|
| 57 |
+
imageFile = sys.argv[3]
|
| 58 |
+
else:
|
| 59 |
+
imageFile = "%s.png" % glyphName
|
| 60 |
+
|
| 61 |
+
font = TTFont(path) # it would work just as well with fontTools.t1Lib.T1Font
|
| 62 |
+
gs = font.getGlyphSet()
|
| 63 |
+
pen = ReportLabPen(gs, Path(fillColor=colors.red, strokeWidth=5))
|
| 64 |
+
g = gs[glyphName]
|
| 65 |
+
g.draw(pen)
|
| 66 |
+
|
| 67 |
+
w, h = g.width, 1000
|
| 68 |
+
from reportlab.graphics import renderPM
|
| 69 |
+
from reportlab.graphics.shapes import Group, Drawing, scale
|
| 70 |
+
|
| 71 |
+
# Everything is wrapped in a group to allow transformations.
|
| 72 |
+
g = Group(pen.path)
|
| 73 |
+
g.translate(0, 200)
|
| 74 |
+
g.scale(0.3, 0.3)
|
| 75 |
+
|
| 76 |
+
d = Drawing(w, h)
|
| 77 |
+
d.add(g)
|
| 78 |
+
|
| 79 |
+
renderPM.drawToFile(d, imageFile, fmt="PNG")
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/teePen.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Pen multiplexing drawing to one or more pens."""
|
| 2 |
+
|
| 3 |
+
from fontTools.pens.basePen import AbstractPen
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
__all__ = ["TeePen"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class TeePen(AbstractPen):
|
| 10 |
+
"""Pen multiplexing drawing to one or more pens.
|
| 11 |
+
|
| 12 |
+
Use either as TeePen(pen1, pen2, ...) or TeePen(iterableOfPens)."""
|
| 13 |
+
|
| 14 |
+
def __init__(self, *pens):
|
| 15 |
+
if len(pens) == 1:
|
| 16 |
+
pens = pens[0]
|
| 17 |
+
self.pens = pens
|
| 18 |
+
|
| 19 |
+
def moveTo(self, p0):
|
| 20 |
+
for pen in self.pens:
|
| 21 |
+
pen.moveTo(p0)
|
| 22 |
+
|
| 23 |
+
def lineTo(self, p1):
|
| 24 |
+
for pen in self.pens:
|
| 25 |
+
pen.lineTo(p1)
|
| 26 |
+
|
| 27 |
+
def qCurveTo(self, *points):
|
| 28 |
+
for pen in self.pens:
|
| 29 |
+
pen.qCurveTo(*points)
|
| 30 |
+
|
| 31 |
+
def curveTo(self, *points):
|
| 32 |
+
for pen in self.pens:
|
| 33 |
+
pen.curveTo(*points)
|
| 34 |
+
|
| 35 |
+
def closePath(self):
|
| 36 |
+
for pen in self.pens:
|
| 37 |
+
pen.closePath()
|
| 38 |
+
|
| 39 |
+
def endPath(self):
|
| 40 |
+
for pen in self.pens:
|
| 41 |
+
pen.endPath()
|
| 42 |
+
|
| 43 |
+
def addComponent(self, glyphName, transformation):
|
| 44 |
+
for pen in self.pens:
|
| 45 |
+
pen.addComponent(glyphName, transformation)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
from fontTools.pens.basePen import _TestPen
|
| 50 |
+
|
| 51 |
+
pen = TeePen(_TestPen(), _TestPen())
|
| 52 |
+
pen.moveTo((0, 0))
|
| 53 |
+
pen.lineTo((0, 100))
|
| 54 |
+
pen.curveTo((50, 75), (60, 50), (50, 25))
|
| 55 |
+
pen.closePath()
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/transformPen.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.pens.filterPen import FilterPen, FilterPointPen
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
__all__ = ["TransformPen", "TransformPointPen"]
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TransformPen(FilterPen):
|
| 8 |
+
"""Pen that transforms all coordinates using a Affine transformation,
|
| 9 |
+
and passes them to another pen.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
def __init__(self, outPen, transformation):
|
| 13 |
+
"""The 'outPen' argument is another pen object. It will receive the
|
| 14 |
+
transformed coordinates. The 'transformation' argument can either
|
| 15 |
+
be a six-tuple, or a fontTools.misc.transform.Transform object.
|
| 16 |
+
"""
|
| 17 |
+
super(TransformPen, self).__init__(outPen)
|
| 18 |
+
if not hasattr(transformation, "transformPoint"):
|
| 19 |
+
from fontTools.misc.transform import Transform
|
| 20 |
+
|
| 21 |
+
transformation = Transform(*transformation)
|
| 22 |
+
self._transformation = transformation
|
| 23 |
+
self._transformPoint = transformation.transformPoint
|
| 24 |
+
self._stack = []
|
| 25 |
+
|
| 26 |
+
def moveTo(self, pt):
|
| 27 |
+
self._outPen.moveTo(self._transformPoint(pt))
|
| 28 |
+
|
| 29 |
+
def lineTo(self, pt):
|
| 30 |
+
self._outPen.lineTo(self._transformPoint(pt))
|
| 31 |
+
|
| 32 |
+
def curveTo(self, *points):
|
| 33 |
+
self._outPen.curveTo(*self._transformPoints(points))
|
| 34 |
+
|
| 35 |
+
def qCurveTo(self, *points):
|
| 36 |
+
if points[-1] is None:
|
| 37 |
+
points = self._transformPoints(points[:-1]) + [None]
|
| 38 |
+
else:
|
| 39 |
+
points = self._transformPoints(points)
|
| 40 |
+
self._outPen.qCurveTo(*points)
|
| 41 |
+
|
| 42 |
+
def _transformPoints(self, points):
|
| 43 |
+
transformPoint = self._transformPoint
|
| 44 |
+
return [transformPoint(pt) for pt in points]
|
| 45 |
+
|
| 46 |
+
def closePath(self):
|
| 47 |
+
self._outPen.closePath()
|
| 48 |
+
|
| 49 |
+
def endPath(self):
|
| 50 |
+
self._outPen.endPath()
|
| 51 |
+
|
| 52 |
+
def addComponent(self, glyphName, transformation):
|
| 53 |
+
transformation = self._transformation.transform(transformation)
|
| 54 |
+
self._outPen.addComponent(glyphName, transformation)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class TransformPointPen(FilterPointPen):
|
| 58 |
+
"""PointPen that transforms all coordinates using a Affine transformation,
|
| 59 |
+
and passes them to another PointPen.
|
| 60 |
+
|
| 61 |
+
For example::
|
| 62 |
+
|
| 63 |
+
>>> from fontTools.pens.recordingPen import RecordingPointPen
|
| 64 |
+
>>> rec = RecordingPointPen()
|
| 65 |
+
>>> pen = TransformPointPen(rec, (2, 0, 0, 2, -10, 5))
|
| 66 |
+
>>> v = iter(rec.value)
|
| 67 |
+
>>> pen.beginPath(identifier="contour-0")
|
| 68 |
+
>>> next(v)
|
| 69 |
+
('beginPath', (), {'identifier': 'contour-0'})
|
| 70 |
+
|
| 71 |
+
>>> pen.addPoint((100, 100), "line")
|
| 72 |
+
>>> next(v)
|
| 73 |
+
('addPoint', ((190, 205), 'line', False, None), {})
|
| 74 |
+
|
| 75 |
+
>>> pen.endPath()
|
| 76 |
+
>>> next(v)
|
| 77 |
+
('endPath', (), {})
|
| 78 |
+
|
| 79 |
+
>>> pen.addComponent("a", (1, 0, 0, 1, -10, 5), identifier="component-0")
|
| 80 |
+
>>> next(v)
|
| 81 |
+
('addComponent', ('a', <Transform [2 0 0 2 -30 15]>), {'identifier': 'component-0'})
|
| 82 |
+
"""
|
| 83 |
+
|
| 84 |
+
def __init__(self, outPointPen, transformation):
|
| 85 |
+
"""The 'outPointPen' argument is another point pen object.
|
| 86 |
+
It will receive the transformed coordinates.
|
| 87 |
+
The 'transformation' argument can either be a six-tuple, or a
|
| 88 |
+
fontTools.misc.transform.Transform object.
|
| 89 |
+
"""
|
| 90 |
+
super().__init__(outPointPen)
|
| 91 |
+
if not hasattr(transformation, "transformPoint"):
|
| 92 |
+
from fontTools.misc.transform import Transform
|
| 93 |
+
|
| 94 |
+
transformation = Transform(*transformation)
|
| 95 |
+
self._transformation = transformation
|
| 96 |
+
self._transformPoint = transformation.transformPoint
|
| 97 |
+
|
| 98 |
+
def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
|
| 99 |
+
self._outPen.addPoint(
|
| 100 |
+
self._transformPoint(pt), segmentType, smooth, name, **kwargs
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
def addComponent(self, baseGlyphName, transformation, **kwargs):
|
| 104 |
+
transformation = self._transformation.transform(transformation)
|
| 105 |
+
self._outPen.addComponent(baseGlyphName, transformation, **kwargs)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
from fontTools.pens.basePen import _TestPen
|
| 110 |
+
|
| 111 |
+
pen = TransformPen(_TestPen(None), (2, 0, 0.5, 2, -10, 0))
|
| 112 |
+
pen.moveTo((0, 0))
|
| 113 |
+
pen.lineTo((0, 100))
|
| 114 |
+
pen.curveTo((50, 75), (60, 50), (50, 25), (0, 0))
|
| 115 |
+
pen.closePath()
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/ttGlyphPen.py
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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Tools import LogMixin
|
| 5 |
+
from fontTools.pens.pointPen import AbstractPointPen
|
| 6 |
+
from fontTools.misc.roundTools import otRound
|
| 7 |
+
from fontTools.pens.basePen import LoggingPen, PenError
|
| 8 |
+
from fontTools.pens.transformPen import TransformPen, TransformPointPen
|
| 9 |
+
from fontTools.ttLib.tables import ttProgram
|
| 10 |
+
from fontTools.ttLib.tables._g_l_y_f import flagOnCurve, flagCubic
|
| 11 |
+
from fontTools.ttLib.tables._g_l_y_f import Glyph
|
| 12 |
+
from fontTools.ttLib.tables._g_l_y_f import GlyphComponent
|
| 13 |
+
from fontTools.ttLib.tables._g_l_y_f import GlyphCoordinates
|
| 14 |
+
from fontTools.ttLib.tables._g_l_y_f import dropImpliedOnCurvePoints
|
| 15 |
+
import math
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
__all__ = ["TTGlyphPen", "TTGlyphPointPen"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class _TTGlyphBasePen:
|
| 22 |
+
def __init__(
|
| 23 |
+
self,
|
| 24 |
+
glyphSet: Optional[Dict[str, Any]],
|
| 25 |
+
handleOverflowingTransforms: bool = True,
|
| 26 |
+
) -> None:
|
| 27 |
+
"""
|
| 28 |
+
Construct a new pen.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
glyphSet (Dict[str, Any]): A glyphset object, used to resolve components.
|
| 32 |
+
handleOverflowingTransforms (bool): See below.
|
| 33 |
+
|
| 34 |
+
If ``handleOverflowingTransforms`` is True, the components' transform values
|
| 35 |
+
are checked that they don't overflow the limits of a F2Dot14 number:
|
| 36 |
+
-2.0 <= v < +2.0. If any transform value exceeds these, the composite
|
| 37 |
+
glyph is decomposed.
|
| 38 |
+
|
| 39 |
+
An exception to this rule is done for values that are very close to +2.0
|
| 40 |
+
(both for consistency with the -2.0 case, and for the relative frequency
|
| 41 |
+
these occur in real fonts). When almost +2.0 values occur (and all other
|
| 42 |
+
values are within the range -2.0 <= x <= +2.0), they are clamped to the
|
| 43 |
+
maximum positive value that can still be encoded as an F2Dot14: i.e.
|
| 44 |
+
1.99993896484375.
|
| 45 |
+
|
| 46 |
+
If False, no check is done and all components are translated unmodified
|
| 47 |
+
into the glyf table, followed by an inevitable ``struct.error`` once an
|
| 48 |
+
attempt is made to compile them.
|
| 49 |
+
|
| 50 |
+
If both contours and components are present in a glyph, the components
|
| 51 |
+
are decomposed.
|
| 52 |
+
"""
|
| 53 |
+
self.glyphSet = glyphSet
|
| 54 |
+
self.handleOverflowingTransforms = handleOverflowingTransforms
|
| 55 |
+
self.init()
|
| 56 |
+
|
| 57 |
+
def _decompose(
|
| 58 |
+
self,
|
| 59 |
+
glyphName: str,
|
| 60 |
+
transformation: Tuple[float, float, float, float, float, float],
|
| 61 |
+
):
|
| 62 |
+
tpen = self.transformPen(self, transformation)
|
| 63 |
+
getattr(self.glyphSet[glyphName], self.drawMethod)(tpen)
|
| 64 |
+
|
| 65 |
+
def _isClosed(self):
|
| 66 |
+
"""
|
| 67 |
+
Check if the current path is closed.
|
| 68 |
+
"""
|
| 69 |
+
raise NotImplementedError
|
| 70 |
+
|
| 71 |
+
def init(self) -> None:
|
| 72 |
+
self.points = []
|
| 73 |
+
self.endPts = []
|
| 74 |
+
self.types = []
|
| 75 |
+
self.components = []
|
| 76 |
+
|
| 77 |
+
def addComponent(
|
| 78 |
+
self,
|
| 79 |
+
baseGlyphName: str,
|
| 80 |
+
transformation: Tuple[float, float, float, float, float, float],
|
| 81 |
+
identifier: Optional[str] = None,
|
| 82 |
+
**kwargs: Any,
|
| 83 |
+
) -> None:
|
| 84 |
+
"""
|
| 85 |
+
Add a sub glyph.
|
| 86 |
+
"""
|
| 87 |
+
self.components.append((baseGlyphName, transformation))
|
| 88 |
+
|
| 89 |
+
def _buildComponents(self, componentFlags):
|
| 90 |
+
if self.handleOverflowingTransforms:
|
| 91 |
+
# we can't encode transform values > 2 or < -2 in F2Dot14,
|
| 92 |
+
# so we must decompose the glyph if any transform exceeds these
|
| 93 |
+
overflowing = any(
|
| 94 |
+
s > 2 or s < -2
|
| 95 |
+
for (glyphName, transformation) in self.components
|
| 96 |
+
for s in transformation[:4]
|
| 97 |
+
)
|
| 98 |
+
components = []
|
| 99 |
+
for glyphName, transformation in self.components:
|
| 100 |
+
if glyphName not in self.glyphSet:
|
| 101 |
+
self.log.warning(f"skipped non-existing component '{glyphName}'")
|
| 102 |
+
continue
|
| 103 |
+
if self.points or (self.handleOverflowingTransforms and overflowing):
|
| 104 |
+
# can't have both coordinates and components, so decompose
|
| 105 |
+
self._decompose(glyphName, transformation)
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
component = GlyphComponent()
|
| 109 |
+
component.glyphName = glyphName
|
| 110 |
+
component.x, component.y = (otRound(v) for v in transformation[4:])
|
| 111 |
+
# quantize floats to F2Dot14 so we get same values as when decompiled
|
| 112 |
+
# from a binary glyf table
|
| 113 |
+
transformation = tuple(
|
| 114 |
+
floatToFixedToFloat(v, 14) for v in transformation[:4]
|
| 115 |
+
)
|
| 116 |
+
if transformation != (1, 0, 0, 1):
|
| 117 |
+
if self.handleOverflowingTransforms and any(
|
| 118 |
+
MAX_F2DOT14 < s <= 2 for s in transformation
|
| 119 |
+
):
|
| 120 |
+
# clamp values ~= +2.0 so we can keep the component
|
| 121 |
+
transformation = tuple(
|
| 122 |
+
MAX_F2DOT14 if MAX_F2DOT14 < s <= 2 else s
|
| 123 |
+
for s in transformation
|
| 124 |
+
)
|
| 125 |
+
component.transform = (transformation[:2], transformation[2:])
|
| 126 |
+
component.flags = componentFlags
|
| 127 |
+
components.append(component)
|
| 128 |
+
return components
|
| 129 |
+
|
| 130 |
+
def glyph(
|
| 131 |
+
self,
|
| 132 |
+
componentFlags: int = 0x04,
|
| 133 |
+
dropImpliedOnCurves: bool = False,
|
| 134 |
+
*,
|
| 135 |
+
round: Callable[[float], int] = otRound,
|
| 136 |
+
) -> Glyph:
|
| 137 |
+
"""
|
| 138 |
+
Returns a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
|
| 139 |
+
|
| 140 |
+
Args:
|
| 141 |
+
componentFlags: Flags to use for component glyphs. (default: 0x04)
|
| 142 |
+
|
| 143 |
+
dropImpliedOnCurves: Whether to remove implied-oncurve points. (default: False)
|
| 144 |
+
"""
|
| 145 |
+
if not self._isClosed():
|
| 146 |
+
raise PenError("Didn't close last contour.")
|
| 147 |
+
components = self._buildComponents(componentFlags)
|
| 148 |
+
|
| 149 |
+
glyph = Glyph()
|
| 150 |
+
glyph.coordinates = GlyphCoordinates(self.points)
|
| 151 |
+
glyph.endPtsOfContours = self.endPts
|
| 152 |
+
glyph.flags = array("B", self.types)
|
| 153 |
+
self.init()
|
| 154 |
+
|
| 155 |
+
if components:
|
| 156 |
+
# If both components and contours were present, they have by now
|
| 157 |
+
# been decomposed by _buildComponents.
|
| 158 |
+
glyph.components = components
|
| 159 |
+
glyph.numberOfContours = -1
|
| 160 |
+
else:
|
| 161 |
+
glyph.numberOfContours = len(glyph.endPtsOfContours)
|
| 162 |
+
glyph.program = ttProgram.Program()
|
| 163 |
+
glyph.program.fromBytecode(b"")
|
| 164 |
+
if dropImpliedOnCurves:
|
| 165 |
+
dropImpliedOnCurvePoints(glyph)
|
| 166 |
+
glyph.coordinates.toInt(round=round)
|
| 167 |
+
|
| 168 |
+
return glyph
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class TTGlyphPen(_TTGlyphBasePen, LoggingPen):
|
| 172 |
+
"""
|
| 173 |
+
Pen used for drawing to a TrueType glyph.
|
| 174 |
+
|
| 175 |
+
This pen can be used to construct or modify glyphs in a TrueType format
|
| 176 |
+
font. After using the pen to draw, use the ``.glyph()`` method to retrieve
|
| 177 |
+
a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
drawMethod = "draw"
|
| 181 |
+
transformPen = TransformPen
|
| 182 |
+
|
| 183 |
+
def __init__(
|
| 184 |
+
self,
|
| 185 |
+
glyphSet: Optional[Dict[str, Any]] = None,
|
| 186 |
+
handleOverflowingTransforms: bool = True,
|
| 187 |
+
outputImpliedClosingLine: bool = False,
|
| 188 |
+
) -> None:
|
| 189 |
+
super().__init__(glyphSet, handleOverflowingTransforms)
|
| 190 |
+
self.outputImpliedClosingLine = outputImpliedClosingLine
|
| 191 |
+
|
| 192 |
+
def _addPoint(self, pt: Tuple[float, float], tp: int) -> None:
|
| 193 |
+
self.points.append(pt)
|
| 194 |
+
self.types.append(tp)
|
| 195 |
+
|
| 196 |
+
def _popPoint(self) -> None:
|
| 197 |
+
self.points.pop()
|
| 198 |
+
self.types.pop()
|
| 199 |
+
|
| 200 |
+
def _isClosed(self) -> bool:
|
| 201 |
+
return (not self.points) or (
|
| 202 |
+
self.endPts and self.endPts[-1] == len(self.points) - 1
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
def lineTo(self, pt: Tuple[float, float]) -> None:
|
| 206 |
+
self._addPoint(pt, flagOnCurve)
|
| 207 |
+
|
| 208 |
+
def moveTo(self, pt: Tuple[float, float]) -> None:
|
| 209 |
+
if not self._isClosed():
|
| 210 |
+
raise PenError('"move"-type point must begin a new contour.')
|
| 211 |
+
self._addPoint(pt, flagOnCurve)
|
| 212 |
+
|
| 213 |
+
def curveTo(self, *points) -> None:
|
| 214 |
+
assert len(points) % 2 == 1
|
| 215 |
+
for pt in points[:-1]:
|
| 216 |
+
self._addPoint(pt, flagCubic)
|
| 217 |
+
|
| 218 |
+
# last point is None if there are no on-curve points
|
| 219 |
+
if points[-1] is not None:
|
| 220 |
+
self._addPoint(points[-1], 1)
|
| 221 |
+
|
| 222 |
+
def qCurveTo(self, *points) -> None:
|
| 223 |
+
assert len(points) >= 1
|
| 224 |
+
for pt in points[:-1]:
|
| 225 |
+
self._addPoint(pt, 0)
|
| 226 |
+
|
| 227 |
+
# last point is None if there are no on-curve points
|
| 228 |
+
if points[-1] is not None:
|
| 229 |
+
self._addPoint(points[-1], 1)
|
| 230 |
+
|
| 231 |
+
def closePath(self) -> None:
|
| 232 |
+
endPt = len(self.points) - 1
|
| 233 |
+
|
| 234 |
+
# ignore anchors (one-point paths)
|
| 235 |
+
if endPt == 0 or (self.endPts and endPt == self.endPts[-1] + 1):
|
| 236 |
+
self._popPoint()
|
| 237 |
+
return
|
| 238 |
+
|
| 239 |
+
if not self.outputImpliedClosingLine:
|
| 240 |
+
# if first and last point on this path are the same, remove last
|
| 241 |
+
startPt = 0
|
| 242 |
+
if self.endPts:
|
| 243 |
+
startPt = self.endPts[-1] + 1
|
| 244 |
+
if self.points[startPt] == self.points[endPt]:
|
| 245 |
+
self._popPoint()
|
| 246 |
+
endPt -= 1
|
| 247 |
+
|
| 248 |
+
self.endPts.append(endPt)
|
| 249 |
+
|
| 250 |
+
def endPath(self) -> None:
|
| 251 |
+
# TrueType contours are always "closed"
|
| 252 |
+
self.closePath()
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
class TTGlyphPointPen(_TTGlyphBasePen, LogMixin, AbstractPointPen):
|
| 256 |
+
"""
|
| 257 |
+
Point pen used for drawing to a TrueType glyph.
|
| 258 |
+
|
| 259 |
+
This pen can be used to construct or modify glyphs in a TrueType format
|
| 260 |
+
font. After using the pen to draw, use the ``.glyph()`` method to retrieve
|
| 261 |
+
a :py:class:`~._g_l_y_f.Glyph` object representing the glyph.
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
+
drawMethod = "drawPoints"
|
| 265 |
+
transformPen = TransformPointPen
|
| 266 |
+
|
| 267 |
+
def init(self) -> None:
|
| 268 |
+
super().init()
|
| 269 |
+
self._currentContourStartIndex = None
|
| 270 |
+
|
| 271 |
+
def _isClosed(self) -> bool:
|
| 272 |
+
return self._currentContourStartIndex is None
|
| 273 |
+
|
| 274 |
+
def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
|
| 275 |
+
"""
|
| 276 |
+
Start a new sub path.
|
| 277 |
+
"""
|
| 278 |
+
if not self._isClosed():
|
| 279 |
+
raise PenError("Didn't close previous contour.")
|
| 280 |
+
self._currentContourStartIndex = len(self.points)
|
| 281 |
+
|
| 282 |
+
def endPath(self) -> None:
|
| 283 |
+
"""
|
| 284 |
+
End the current sub path.
|
| 285 |
+
"""
|
| 286 |
+
# TrueType contours are always "closed"
|
| 287 |
+
if self._isClosed():
|
| 288 |
+
raise PenError("Contour is already closed.")
|
| 289 |
+
if self._currentContourStartIndex == len(self.points):
|
| 290 |
+
# ignore empty contours
|
| 291 |
+
self._currentContourStartIndex = None
|
| 292 |
+
return
|
| 293 |
+
|
| 294 |
+
contourStart = self.endPts[-1] + 1 if self.endPts else 0
|
| 295 |
+
self.endPts.append(len(self.points) - 1)
|
| 296 |
+
self._currentContourStartIndex = None
|
| 297 |
+
|
| 298 |
+
# Resolve types for any cubic segments
|
| 299 |
+
flags = self.types
|
| 300 |
+
for i in range(contourStart, len(flags)):
|
| 301 |
+
if flags[i] == "curve":
|
| 302 |
+
j = i - 1
|
| 303 |
+
if j < contourStart:
|
| 304 |
+
j = len(flags) - 1
|
| 305 |
+
while flags[j] == 0:
|
| 306 |
+
flags[j] = flagCubic
|
| 307 |
+
j -= 1
|
| 308 |
+
flags[i] = flagOnCurve
|
| 309 |
+
|
| 310 |
+
def addPoint(
|
| 311 |
+
self,
|
| 312 |
+
pt: Tuple[float, float],
|
| 313 |
+
segmentType: Optional[str] = None,
|
| 314 |
+
smooth: bool = False,
|
| 315 |
+
name: Optional[str] = None,
|
| 316 |
+
identifier: Optional[str] = None,
|
| 317 |
+
**kwargs: Any,
|
| 318 |
+
) -> None:
|
| 319 |
+
"""
|
| 320 |
+
Add a point to the current sub path.
|
| 321 |
+
"""
|
| 322 |
+
if self._isClosed():
|
| 323 |
+
raise PenError("Can't add a point to a closed contour.")
|
| 324 |
+
if segmentType is None:
|
| 325 |
+
self.types.append(0)
|
| 326 |
+
elif segmentType in ("line", "move"):
|
| 327 |
+
self.types.append(flagOnCurve)
|
| 328 |
+
elif segmentType == "qcurve":
|
| 329 |
+
self.types.append(flagOnCurve)
|
| 330 |
+
elif segmentType == "curve":
|
| 331 |
+
self.types.append("curve")
|
| 332 |
+
else:
|
| 333 |
+
raise AssertionError(segmentType)
|
| 334 |
+
|
| 335 |
+
self.points.append(pt)
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/pens/wxPen.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.pens.basePen import BasePen
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
__all__ = ["WxPen"]
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class WxPen(BasePen):
|
| 8 |
+
def __init__(self, glyphSet, path=None):
|
| 9 |
+
BasePen.__init__(self, glyphSet)
|
| 10 |
+
if path is None:
|
| 11 |
+
import wx
|
| 12 |
+
|
| 13 |
+
path = wx.GraphicsRenderer.GetDefaultRenderer().CreatePath()
|
| 14 |
+
self.path = path
|
| 15 |
+
|
| 16 |
+
def _moveTo(self, p):
|
| 17 |
+
self.path.MoveToPoint(*p)
|
| 18 |
+
|
| 19 |
+
def _lineTo(self, p):
|
| 20 |
+
self.path.AddLineToPoint(*p)
|
| 21 |
+
|
| 22 |
+
def _curveToOne(self, p1, p2, p3):
|
| 23 |
+
self.path.AddCurveToPoint(*p1 + p2 + p3)
|
| 24 |
+
|
| 25 |
+
def _qCurveToOne(self, p1, p2):
|
| 26 |
+
self.path.AddQuadCurveToPoint(*p1 + p2)
|
| 27 |
+
|
| 28 |
+
def _closePath(self):
|
| 29 |
+
self.path.CloseSubpath()
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/t1Lib/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (15.5 kB). View file
|
|
|
evalkit_t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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fontTools.misc import sstruct
|
| 2 |
+
from fontTools.misc.fixedTools import floatToFixedToStr
|
| 3 |
+
from fontTools.misc.textTools import byteord, safeEval
|
| 4 |
+
|
| 5 |
+
# from itertools import *
|
| 6 |
+
from . import DefaultTable
|
| 7 |
+
from . import grUtils
|
| 8 |
+
from array import array
|
| 9 |
+
from functools import reduce
|
| 10 |
+
import struct, re, sys
|
| 11 |
+
|
| 12 |
+
Silf_hdr_format = """
|
| 13 |
+
>
|
| 14 |
+
version: 16.16F
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
Silf_hdr_format_3 = """
|
| 18 |
+
>
|
| 19 |
+
version: 16.16F
|
| 20 |
+
compilerVersion: L
|
| 21 |
+
numSilf: H
|
| 22 |
+
x
|
| 23 |
+
x
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
Silf_part1_format_v3 = """
|
| 27 |
+
>
|
| 28 |
+
ruleVersion: 16.16F
|
| 29 |
+
passOffset: H
|
| 30 |
+
pseudosOffset: H
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
Silf_part1_format = """
|
| 34 |
+
>
|
| 35 |
+
maxGlyphID: H
|
| 36 |
+
extraAscent: h
|
| 37 |
+
extraDescent: h
|
| 38 |
+
numPasses: B
|
| 39 |
+
iSubst: B
|
| 40 |
+
iPos: B
|
| 41 |
+
iJust: B
|
| 42 |
+
iBidi: B
|
| 43 |
+
flags: B
|
| 44 |
+
maxPreContext: B
|
| 45 |
+
maxPostContext: B
|
| 46 |
+
attrPseudo: B
|
| 47 |
+
attrBreakWeight: B
|
| 48 |
+
attrDirectionality: B
|
| 49 |
+
attrMirroring: B
|
| 50 |
+
attrSkipPasses: B
|
| 51 |
+
numJLevels: B
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
Silf_justify_format = """
|
| 55 |
+
>
|
| 56 |
+
attrStretch: B
|
| 57 |
+
attrShrink: B
|
| 58 |
+
attrStep: B
|
| 59 |
+
attrWeight: B
|
| 60 |
+
runto: B
|
| 61 |
+
x
|
| 62 |
+
x
|
| 63 |
+
x
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
Silf_part2_format = """
|
| 67 |
+
>
|
| 68 |
+
numLigComp: H
|
| 69 |
+
numUserDefn: B
|
| 70 |
+
maxCompPerLig: B
|
| 71 |
+
direction: B
|
| 72 |
+
attCollisions: B
|
| 73 |
+
x
|
| 74 |
+
x
|
| 75 |
+
x
|
| 76 |
+
numCritFeatures: B
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
Silf_pseudomap_format = """
|
| 80 |
+
>
|
| 81 |
+
unicode: L
|
| 82 |
+
nPseudo: H
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
Silf_pseudomap_format_h = """
|
| 86 |
+
>
|
| 87 |
+
unicode: H
|
| 88 |
+
nPseudo: H
|
| 89 |
+
"""
|
| 90 |
+
|
| 91 |
+
Silf_classmap_format = """
|
| 92 |
+
>
|
| 93 |
+
numClass: H
|
| 94 |
+
numLinear: H
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
Silf_lookupclass_format = """
|
| 98 |
+
>
|
| 99 |
+
numIDs: H
|
| 100 |
+
searchRange: H
|
| 101 |
+
entrySelector: H
|
| 102 |
+
rangeShift: H
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
Silf_lookuppair_format = """
|
| 106 |
+
>
|
| 107 |
+
glyphId: H
|
| 108 |
+
index: H
|
| 109 |
+
"""
|
| 110 |
+
|
| 111 |
+
Silf_pass_format = """
|
| 112 |
+
>
|
| 113 |
+
flags: B
|
| 114 |
+
maxRuleLoop: B
|
| 115 |
+
maxRuleContext: B
|
| 116 |
+
maxBackup: B
|
| 117 |
+
numRules: H
|
| 118 |
+
fsmOffset: H
|
| 119 |
+
pcCode: L
|
| 120 |
+
rcCode: L
|
| 121 |
+
aCode: L
|
| 122 |
+
oDebug: L
|
| 123 |
+
numRows: H
|
| 124 |
+
numTransitional: H
|
| 125 |
+
numSuccess: H
|
| 126 |
+
numColumns: H
|
| 127 |
+
"""
|
| 128 |
+
|
| 129 |
+
aCode_info = (
|
| 130 |
+
("NOP", 0),
|
| 131 |
+
("PUSH_BYTE", "b"),
|
| 132 |
+
("PUSH_BYTE_U", "B"),
|
| 133 |
+
("PUSH_SHORT", ">h"),
|
| 134 |
+
("PUSH_SHORT_U", ">H"),
|
| 135 |
+
("PUSH_LONG", ">L"),
|
| 136 |
+
("ADD", 0),
|
| 137 |
+
("SUB", 0),
|
| 138 |
+
("MUL", 0),
|
| 139 |
+
("DIV", 0),
|
| 140 |
+
("MIN", 0),
|
| 141 |
+
("MAX", 0),
|
| 142 |
+
("NEG", 0),
|
| 143 |
+
("TRUNC8", 0),
|
| 144 |
+
("TRUNC16", 0),
|
| 145 |
+
("COND", 0),
|
| 146 |
+
("AND", 0), # x10
|
| 147 |
+
("OR", 0),
|
| 148 |
+
("NOT", 0),
|
| 149 |
+
("EQUAL", 0),
|
| 150 |
+
("NOT_EQ", 0),
|
| 151 |
+
("LESS", 0),
|
| 152 |
+
("GTR", 0),
|
| 153 |
+
("LESS_EQ", 0),
|
| 154 |
+
("GTR_EQ", 0),
|
| 155 |
+
("NEXT", 0),
|
| 156 |
+
("NEXT_N", "b"),
|
| 157 |
+
("COPY_NEXT", 0),
|
| 158 |
+
("PUT_GLYPH_8BIT_OBS", "B"),
|
| 159 |
+
("PUT_SUBS_8BIT_OBS", "bBB"),
|
| 160 |
+
("PUT_COPY", "b"),
|
| 161 |
+
("INSERT", 0),
|
| 162 |
+
("DELETE", 0), # x20
|
| 163 |
+
("ASSOC", -1),
|
| 164 |
+
("CNTXT_ITEM", "bB"),
|
| 165 |
+
("ATTR_SET", "B"),
|
| 166 |
+
("ATTR_ADD", "B"),
|
| 167 |
+
("ATTR_SUB", "B"),
|
| 168 |
+
("ATTR_SET_SLOT", "B"),
|
| 169 |
+
("IATTR_SET_SLOT", "BB"),
|
| 170 |
+
("PUSH_SLOT_ATTR", "Bb"),
|
| 171 |
+
("PUSH_GLYPH_ATTR_OBS", "Bb"),
|
| 172 |
+
("PUSH_GLYPH_METRIC", "Bbb"),
|
| 173 |
+
("PUSH_FEAT", "Bb"),
|
| 174 |
+
("PUSH_ATT_TO_GATTR_OBS", "Bb"),
|
| 175 |
+
("PUSH_ATT_TO_GLYPH_METRIC", "Bbb"),
|
| 176 |
+
("PUSH_ISLOT_ATTR", "Bbb"),
|
| 177 |
+
("PUSH_IGLYPH_ATTR", "Bbb"),
|
| 178 |
+
("POP_RET", 0), # x30
|
| 179 |
+
("RET_ZERO", 0),
|
| 180 |
+
("RET_TRUE", 0),
|
| 181 |
+
("IATTR_SET", "BB"),
|
| 182 |
+
("IATTR_ADD", "BB"),
|
| 183 |
+
("IATTR_SUB", "BB"),
|
| 184 |
+
("PUSH_PROC_STATE", "B"),
|
| 185 |
+
("PUSH_VERSION", 0),
|
| 186 |
+
("PUT_SUBS", ">bHH"),
|
| 187 |
+
("PUT_SUBS2", 0),
|
| 188 |
+
("PUT_SUBS3", 0),
|
| 189 |
+
("PUT_GLYPH", ">H"),
|
| 190 |
+
("PUSH_GLYPH_ATTR", ">Hb"),
|
| 191 |
+
("PUSH_ATT_TO_GLYPH_ATTR", ">Hb"),
|
| 192 |
+
("BITOR", 0),
|
| 193 |
+
("BITAND", 0),
|
| 194 |
+
("BITNOT", 0), # x40
|
| 195 |
+
("BITSET", ">HH"),
|
| 196 |
+
("SET_FEAT", "Bb"),
|
| 197 |
+
)
|
| 198 |
+
aCode_map = dict([(x[0], (i, x[1])) for i, x in enumerate(aCode_info)])
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def disassemble(aCode):
|
| 202 |
+
codelen = len(aCode)
|
| 203 |
+
pc = 0
|
| 204 |
+
res = []
|
| 205 |
+
while pc < codelen:
|
| 206 |
+
opcode = byteord(aCode[pc : pc + 1])
|
| 207 |
+
if opcode > len(aCode_info):
|
| 208 |
+
instr = aCode_info[0]
|
| 209 |
+
else:
|
| 210 |
+
instr = aCode_info[opcode]
|
| 211 |
+
pc += 1
|
| 212 |
+
if instr[1] != 0 and pc >= codelen:
|
| 213 |
+
return res
|
| 214 |
+
if instr[1] == -1:
|
| 215 |
+
count = byteord(aCode[pc])
|
| 216 |
+
fmt = "%dB" % count
|
| 217 |
+
pc += 1
|
| 218 |
+
elif instr[1] == 0:
|
| 219 |
+
fmt = ""
|
| 220 |
+
else:
|
| 221 |
+
fmt = instr[1]
|
| 222 |
+
if fmt == "":
|
| 223 |
+
res.append(instr[0])
|
| 224 |
+
continue
|
| 225 |
+
parms = struct.unpack_from(fmt, aCode[pc:])
|
| 226 |
+
res.append(instr[0] + "(" + ", ".join(map(str, parms)) + ")")
|
| 227 |
+
pc += struct.calcsize(fmt)
|
| 228 |
+
return res
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
instre = re.compile(r"^\s*([^(]+)\s*(?:\(([^)]+)\))?")
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def assemble(instrs):
|
| 235 |
+
res = b""
|
| 236 |
+
for inst in instrs:
|
| 237 |
+
m = instre.match(inst)
|
| 238 |
+
if not m or not m.group(1) in aCode_map:
|
| 239 |
+
continue
|
| 240 |
+
opcode, parmfmt = aCode_map[m.group(1)]
|
| 241 |
+
res += struct.pack("B", opcode)
|
| 242 |
+
if m.group(2):
|
| 243 |
+
if parmfmt == 0:
|
| 244 |
+
continue
|
| 245 |
+
parms = [int(x) for x in re.split(r",\s*", m.group(2))]
|
| 246 |
+
if parmfmt == -1:
|
| 247 |
+
l = len(parms)
|
| 248 |
+
res += struct.pack(("%dB" % (l + 1)), l, *parms)
|
| 249 |
+
else:
|
| 250 |
+
res += struct.pack(parmfmt, *parms)
|
| 251 |
+
return res
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def writecode(tag, writer, instrs):
|
| 255 |
+
writer.begintag(tag)
|
| 256 |
+
writer.newline()
|
| 257 |
+
for l in disassemble(instrs):
|
| 258 |
+
writer.write(l)
|
| 259 |
+
writer.newline()
|
| 260 |
+
writer.endtag(tag)
|
| 261 |
+
writer.newline()
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def readcode(content):
|
| 265 |
+
res = []
|
| 266 |
+
for e in content_string(content).split("\n"):
|
| 267 |
+
e = e.strip()
|
| 268 |
+
if not len(e):
|
| 269 |
+
continue
|
| 270 |
+
res.append(e)
|
| 271 |
+
return assemble(res)
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
attrs_info = (
|
| 275 |
+
"flags",
|
| 276 |
+
"extraAscent",
|
| 277 |
+
"extraDescent",
|
| 278 |
+
"maxGlyphID",
|
| 279 |
+
"numLigComp",
|
| 280 |
+
"numUserDefn",
|
| 281 |
+
"maxCompPerLig",
|
| 282 |
+
"direction",
|
| 283 |
+
"lbGID",
|
| 284 |
+
)
|
| 285 |
+
attrs_passindexes = ("iSubst", "iPos", "iJust", "iBidi")
|
| 286 |
+
attrs_contexts = ("maxPreContext", "maxPostContext")
|
| 287 |
+
attrs_attributes = (
|
| 288 |
+
"attrPseudo",
|
| 289 |
+
"attrBreakWeight",
|
| 290 |
+
"attrDirectionality",
|
| 291 |
+
"attrMirroring",
|
| 292 |
+
"attrSkipPasses",
|
| 293 |
+
"attCollisions",
|
| 294 |
+
)
|
| 295 |
+
pass_attrs_info = (
|
| 296 |
+
"flags",
|
| 297 |
+
"maxRuleLoop",
|
| 298 |
+
"maxRuleContext",
|
| 299 |
+
"maxBackup",
|
| 300 |
+
"minRulePreContext",
|
| 301 |
+
"maxRulePreContext",
|
| 302 |
+
"collisionThreshold",
|
| 303 |
+
)
|
| 304 |
+
pass_attrs_fsm = ("numRows", "numTransitional", "numSuccess", "numColumns")
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def writesimple(tag, self, writer, *attrkeys):
|
| 308 |
+
attrs = dict([(k, getattr(self, k)) for k in attrkeys])
|
| 309 |
+
writer.simpletag(tag, **attrs)
|
| 310 |
+
writer.newline()
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def getSimple(self, attrs, *attr_list):
|
| 314 |
+
for k in attr_list:
|
| 315 |
+
if k in attrs:
|
| 316 |
+
setattr(self, k, int(safeEval(attrs[k])))
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def content_string(contents):
|
| 320 |
+
res = ""
|
| 321 |
+
for element in contents:
|
| 322 |
+
if isinstance(element, tuple):
|
| 323 |
+
continue
|
| 324 |
+
res += element
|
| 325 |
+
return res.strip()
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def wrapline(writer, dat, length=80):
|
| 329 |
+
currline = ""
|
| 330 |
+
for d in dat:
|
| 331 |
+
if len(currline) > length:
|
| 332 |
+
writer.write(currline[:-1])
|
| 333 |
+
writer.newline()
|
| 334 |
+
currline = ""
|
| 335 |
+
currline += d + " "
|
| 336 |
+
if len(currline):
|
| 337 |
+
writer.write(currline[:-1])
|
| 338 |
+
writer.newline()
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
class _Object:
|
| 342 |
+
pass
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
class table_S__i_l_f(DefaultTable.DefaultTable):
|
| 346 |
+
"""Silf table support"""
|
| 347 |
+
|
| 348 |
+
def __init__(self, tag=None):
|
| 349 |
+
DefaultTable.DefaultTable.__init__(self, tag)
|
| 350 |
+
self.silfs = []
|
| 351 |
+
|
| 352 |
+
def decompile(self, data, ttFont):
|
| 353 |
+
sstruct.unpack2(Silf_hdr_format, data, self)
|
| 354 |
+
self.version = float(floatToFixedToStr(self.version, precisionBits=16))
|
| 355 |
+
if self.version >= 5.0:
|
| 356 |
+
(data, self.scheme) = grUtils.decompress(data)
|
| 357 |
+
sstruct.unpack2(Silf_hdr_format_3, data, self)
|
| 358 |
+
base = sstruct.calcsize(Silf_hdr_format_3)
|
| 359 |
+
elif self.version < 3.0:
|
| 360 |
+
self.numSilf = struct.unpack(">H", data[4:6])
|
| 361 |
+
self.scheme = 0
|
| 362 |
+
self.compilerVersion = 0
|
| 363 |
+
base = 8
|
| 364 |
+
else:
|
| 365 |
+
self.scheme = 0
|
| 366 |
+
sstruct.unpack2(Silf_hdr_format_3, data, self)
|
| 367 |
+
base = sstruct.calcsize(Silf_hdr_format_3)
|
| 368 |
+
|
| 369 |
+
silfoffsets = struct.unpack_from((">%dL" % self.numSilf), data[base:])
|
| 370 |
+
for offset in silfoffsets:
|
| 371 |
+
s = Silf()
|
| 372 |
+
self.silfs.append(s)
|
| 373 |
+
s.decompile(data[offset:], ttFont, self.version)
|
| 374 |
+
|
| 375 |
+
def compile(self, ttFont):
|
| 376 |
+
self.numSilf = len(self.silfs)
|
| 377 |
+
if self.version < 3.0:
|
| 378 |
+
hdr = sstruct.pack(Silf_hdr_format, self)
|
| 379 |
+
hdr += struct.pack(">HH", self.numSilf, 0)
|
| 380 |
+
else:
|
| 381 |
+
hdr = sstruct.pack(Silf_hdr_format_3, self)
|
| 382 |
+
offset = len(hdr) + 4 * self.numSilf
|
| 383 |
+
data = b""
|
| 384 |
+
for s in self.silfs:
|
| 385 |
+
hdr += struct.pack(">L", offset)
|
| 386 |
+
subdata = s.compile(ttFont, self.version)
|
| 387 |
+
offset += len(subdata)
|
| 388 |
+
data += subdata
|
| 389 |
+
if self.version >= 5.0:
|
| 390 |
+
return grUtils.compress(self.scheme, hdr + data)
|
| 391 |
+
return hdr + data
|
| 392 |
+
|
| 393 |
+
def toXML(self, writer, ttFont):
|
| 394 |
+
writer.comment("Attributes starting with _ are informative only")
|
| 395 |
+
writer.newline()
|
| 396 |
+
writer.simpletag(
|
| 397 |
+
"version",
|
| 398 |
+
version=self.version,
|
| 399 |
+
compilerVersion=self.compilerVersion,
|
| 400 |
+
compressionScheme=self.scheme,
|
| 401 |
+
)
|
| 402 |
+
writer.newline()
|
| 403 |
+
for s in self.silfs:
|
| 404 |
+
writer.begintag("silf")
|
| 405 |
+
writer.newline()
|
| 406 |
+
s.toXML(writer, ttFont, self.version)
|
| 407 |
+
writer.endtag("silf")
|
| 408 |
+
writer.newline()
|
| 409 |
+
|
| 410 |
+
def fromXML(self, name, attrs, content, ttFont):
|
| 411 |
+
if name == "version":
|
| 412 |
+
self.scheme = int(safeEval(attrs["compressionScheme"]))
|
| 413 |
+
self.version = float(safeEval(attrs["version"]))
|
| 414 |
+
self.compilerVersion = int(safeEval(attrs["compilerVersion"]))
|
| 415 |
+
return
|
| 416 |
+
if name == "silf":
|
| 417 |
+
s = Silf()
|
| 418 |
+
self.silfs.append(s)
|
| 419 |
+
for element in content:
|
| 420 |
+
if not isinstance(element, tuple):
|
| 421 |
+
continue
|
| 422 |
+
tag, attrs, subcontent = element
|
| 423 |
+
s.fromXML(tag, attrs, subcontent, ttFont, self.version)
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
class Silf(object):
|
| 427 |
+
"""A particular Silf subtable"""
|
| 428 |
+
|
| 429 |
+
def __init__(self):
|
| 430 |
+
self.passes = []
|
| 431 |
+
self.scriptTags = []
|
| 432 |
+
self.critFeatures = []
|
| 433 |
+
self.jLevels = []
|
| 434 |
+
self.pMap = {}
|
| 435 |
+
|
| 436 |
+
def decompile(self, data, ttFont, version=2.0):
|
| 437 |
+
if version >= 3.0:
|
| 438 |
+
_, data = sstruct.unpack2(Silf_part1_format_v3, data, self)
|
| 439 |
+
self.ruleVersion = float(
|
| 440 |
+
floatToFixedToStr(self.ruleVersion, precisionBits=16)
|
| 441 |
+
)
|
| 442 |
+
_, data = sstruct.unpack2(Silf_part1_format, data, self)
|
| 443 |
+
for jlevel in range(self.numJLevels):
|
| 444 |
+
j, data = sstruct.unpack2(Silf_justify_format, data, _Object())
|
| 445 |
+
self.jLevels.append(j)
|
| 446 |
+
_, data = sstruct.unpack2(Silf_part2_format, data, self)
|
| 447 |
+
if self.numCritFeatures:
|
| 448 |
+
self.critFeatures = struct.unpack_from(
|
| 449 |
+
(">%dH" % self.numCritFeatures), data
|
| 450 |
+
)
|
| 451 |
+
data = data[self.numCritFeatures * 2 + 1 :]
|
| 452 |
+
(numScriptTag,) = struct.unpack_from("B", data)
|
| 453 |
+
if numScriptTag:
|
| 454 |
+
self.scriptTags = [
|
| 455 |
+
struct.unpack("4s", data[x : x + 4])[0].decode("ascii")
|
| 456 |
+
for x in range(1, 1 + 4 * numScriptTag, 4)
|
| 457 |
+
]
|
| 458 |
+
data = data[1 + 4 * numScriptTag :]
|
| 459 |
+
(self.lbGID,) = struct.unpack(">H", data[:2])
|
| 460 |
+
if self.numPasses:
|
| 461 |
+
self.oPasses = struct.unpack(
|
| 462 |
+
(">%dL" % (self.numPasses + 1)), data[2 : 6 + 4 * self.numPasses]
|
| 463 |
+
)
|
| 464 |
+
data = data[6 + 4 * self.numPasses :]
|
| 465 |
+
(numPseudo,) = struct.unpack(">H", data[:2])
|
| 466 |
+
for i in range(numPseudo):
|
| 467 |
+
if version >= 3.0:
|
| 468 |
+
pseudo = sstruct.unpack(
|
| 469 |
+
Silf_pseudomap_format, data[8 + 6 * i : 14 + 6 * i], _Object()
|
| 470 |
+
)
|
| 471 |
+
else:
|
| 472 |
+
pseudo = sstruct.unpack(
|
| 473 |
+
Silf_pseudomap_format_h, data[8 + 4 * i : 12 + 4 * i], _Object()
|
| 474 |
+
)
|
| 475 |
+
self.pMap[pseudo.unicode] = ttFont.getGlyphName(pseudo.nPseudo)
|
| 476 |
+
data = data[8 + 6 * numPseudo :]
|
| 477 |
+
currpos = (
|
| 478 |
+
sstruct.calcsize(Silf_part1_format)
|
| 479 |
+
+ sstruct.calcsize(Silf_justify_format) * self.numJLevels
|
| 480 |
+
+ sstruct.calcsize(Silf_part2_format)
|
| 481 |
+
+ 2 * self.numCritFeatures
|
| 482 |
+
+ 1
|
| 483 |
+
+ 1
|
| 484 |
+
+ 4 * numScriptTag
|
| 485 |
+
+ 6
|
| 486 |
+
+ 4 * self.numPasses
|
| 487 |
+
+ 8
|
| 488 |
+
+ 6 * numPseudo
|
| 489 |
+
)
|
| 490 |
+
if version >= 3.0:
|
| 491 |
+
currpos += sstruct.calcsize(Silf_part1_format_v3)
|
| 492 |
+
self.classes = Classes()
|
| 493 |
+
self.classes.decompile(data, ttFont, version)
|
| 494 |
+
for i in range(self.numPasses):
|
| 495 |
+
p = Pass()
|
| 496 |
+
self.passes.append(p)
|
| 497 |
+
p.decompile(
|
| 498 |
+
data[self.oPasses[i] - currpos : self.oPasses[i + 1] - currpos],
|
| 499 |
+
ttFont,
|
| 500 |
+
version,
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
def compile(self, ttFont, version=2.0):
|
| 504 |
+
self.numPasses = len(self.passes)
|
| 505 |
+
self.numJLevels = len(self.jLevels)
|
| 506 |
+
self.numCritFeatures = len(self.critFeatures)
|
| 507 |
+
numPseudo = len(self.pMap)
|
| 508 |
+
data = b""
|
| 509 |
+
if version >= 3.0:
|
| 510 |
+
hdroffset = sstruct.calcsize(Silf_part1_format_v3)
|
| 511 |
+
else:
|
| 512 |
+
hdroffset = 0
|
| 513 |
+
data += sstruct.pack(Silf_part1_format, self)
|
| 514 |
+
for j in self.jLevels:
|
| 515 |
+
data += sstruct.pack(Silf_justify_format, j)
|
| 516 |
+
data += sstruct.pack(Silf_part2_format, self)
|
| 517 |
+
if self.numCritFeatures:
|
| 518 |
+
data += struct.pack((">%dH" % self.numCritFeaturs), *self.critFeatures)
|
| 519 |
+
data += struct.pack("BB", 0, len(self.scriptTags))
|
| 520 |
+
if len(self.scriptTags):
|
| 521 |
+
tdata = [struct.pack("4s", x.encode("ascii")) for x in self.scriptTags]
|
| 522 |
+
data += b"".join(tdata)
|
| 523 |
+
data += struct.pack(">H", self.lbGID)
|
| 524 |
+
self.passOffset = len(data)
|
| 525 |
+
|
| 526 |
+
data1 = grUtils.bininfo(numPseudo, 6)
|
| 527 |
+
currpos = hdroffset + len(data) + 4 * (self.numPasses + 1)
|
| 528 |
+
self.pseudosOffset = currpos + len(data1)
|
| 529 |
+
for u, p in sorted(self.pMap.items()):
|
| 530 |
+
data1 += struct.pack(
|
| 531 |
+
(">LH" if version >= 3.0 else ">HH"), u, ttFont.getGlyphID(p)
|
| 532 |
+
)
|
| 533 |
+
data1 += self.classes.compile(ttFont, version)
|
| 534 |
+
currpos += len(data1)
|
| 535 |
+
data2 = b""
|
| 536 |
+
datao = b""
|
| 537 |
+
for i, p in enumerate(self.passes):
|
| 538 |
+
base = currpos + len(data2)
|
| 539 |
+
datao += struct.pack(">L", base)
|
| 540 |
+
data2 += p.compile(ttFont, base, version)
|
| 541 |
+
datao += struct.pack(">L", currpos + len(data2))
|
| 542 |
+
|
| 543 |
+
if version >= 3.0:
|
| 544 |
+
data3 = sstruct.pack(Silf_part1_format_v3, self)
|
| 545 |
+
else:
|
| 546 |
+
data3 = b""
|
| 547 |
+
return data3 + data + datao + data1 + data2
|
| 548 |
+
|
| 549 |
+
def toXML(self, writer, ttFont, version=2.0):
|
| 550 |
+
if version >= 3.0:
|
| 551 |
+
writer.simpletag("version", ruleVersion=self.ruleVersion)
|
| 552 |
+
writer.newline()
|
| 553 |
+
writesimple("info", self, writer, *attrs_info)
|
| 554 |
+
writesimple("passindexes", self, writer, *attrs_passindexes)
|
| 555 |
+
writesimple("contexts", self, writer, *attrs_contexts)
|
| 556 |
+
writesimple("attributes", self, writer, *attrs_attributes)
|
| 557 |
+
if len(self.jLevels):
|
| 558 |
+
writer.begintag("justifications")
|
| 559 |
+
writer.newline()
|
| 560 |
+
jformat, jnames, jfixes = sstruct.getformat(Silf_justify_format)
|
| 561 |
+
for i, j in enumerate(self.jLevels):
|
| 562 |
+
attrs = dict([(k, getattr(j, k)) for k in jnames])
|
| 563 |
+
writer.simpletag("justify", **attrs)
|
| 564 |
+
writer.newline()
|
| 565 |
+
writer.endtag("justifications")
|
| 566 |
+
writer.newline()
|
| 567 |
+
if len(self.critFeatures):
|
| 568 |
+
writer.begintag("critFeatures")
|
| 569 |
+
writer.newline()
|
| 570 |
+
writer.write(" ".join(map(str, self.critFeatures)))
|
| 571 |
+
writer.newline()
|
| 572 |
+
writer.endtag("critFeatures")
|
| 573 |
+
writer.newline()
|
| 574 |
+
if len(self.scriptTags):
|
| 575 |
+
writer.begintag("scriptTags")
|
| 576 |
+
writer.newline()
|
| 577 |
+
writer.write(" ".join(self.scriptTags))
|
| 578 |
+
writer.newline()
|
| 579 |
+
writer.endtag("scriptTags")
|
| 580 |
+
writer.newline()
|
| 581 |
+
if self.pMap:
|
| 582 |
+
writer.begintag("pseudoMap")
|
| 583 |
+
writer.newline()
|
| 584 |
+
for k, v in sorted(self.pMap.items()):
|
| 585 |
+
writer.simpletag("pseudo", unicode=hex(k), pseudo=v)
|
| 586 |
+
writer.newline()
|
| 587 |
+
writer.endtag("pseudoMap")
|
| 588 |
+
writer.newline()
|
| 589 |
+
self.classes.toXML(writer, ttFont, version)
|
| 590 |
+
if len(self.passes):
|
| 591 |
+
writer.begintag("passes")
|
| 592 |
+
writer.newline()
|
| 593 |
+
for i, p in enumerate(self.passes):
|
| 594 |
+
writer.begintag("pass", _index=i)
|
| 595 |
+
writer.newline()
|
| 596 |
+
p.toXML(writer, ttFont, version)
|
| 597 |
+
writer.endtag("pass")
|
| 598 |
+
writer.newline()
|
| 599 |
+
writer.endtag("passes")
|
| 600 |
+
writer.newline()
|
| 601 |
+
|
| 602 |
+
def fromXML(self, name, attrs, content, ttFont, version=2.0):
|
| 603 |
+
if name == "version":
|
| 604 |
+
self.ruleVersion = float(safeEval(attrs.get("ruleVersion", "0")))
|
| 605 |
+
if name == "info":
|
| 606 |
+
getSimple(self, attrs, *attrs_info)
|
| 607 |
+
elif name == "passindexes":
|
| 608 |
+
getSimple(self, attrs, *attrs_passindexes)
|
| 609 |
+
elif name == "contexts":
|
| 610 |
+
getSimple(self, attrs, *attrs_contexts)
|
| 611 |
+
elif name == "attributes":
|
| 612 |
+
getSimple(self, attrs, *attrs_attributes)
|
| 613 |
+
elif name == "justifications":
|
| 614 |
+
for element in content:
|
| 615 |
+
if not isinstance(element, tuple):
|
| 616 |
+
continue
|
| 617 |
+
(tag, attrs, subcontent) = element
|
| 618 |
+
if tag == "justify":
|
| 619 |
+
j = _Object()
|
| 620 |
+
for k, v in attrs.items():
|
| 621 |
+
setattr(j, k, int(v))
|
| 622 |
+
self.jLevels.append(j)
|
| 623 |
+
elif name == "critFeatures":
|
| 624 |
+
self.critFeatures = []
|
| 625 |
+
element = content_string(content)
|
| 626 |
+
self.critFeatures.extend(map(int, element.split()))
|
| 627 |
+
elif name == "scriptTags":
|
| 628 |
+
self.scriptTags = []
|
| 629 |
+
element = content_string(content)
|
| 630 |
+
for n in element.split():
|
| 631 |
+
self.scriptTags.append(n)
|
| 632 |
+
elif name == "pseudoMap":
|
| 633 |
+
self.pMap = {}
|
| 634 |
+
for element in content:
|
| 635 |
+
if not isinstance(element, tuple):
|
| 636 |
+
continue
|
| 637 |
+
(tag, attrs, subcontent) = element
|
| 638 |
+
if tag == "pseudo":
|
| 639 |
+
k = int(attrs["unicode"], 16)
|
| 640 |
+
v = attrs["pseudo"]
|
| 641 |
+
self.pMap[k] = v
|
| 642 |
+
elif name == "classes":
|
| 643 |
+
self.classes = Classes()
|
| 644 |
+
for element in content:
|
| 645 |
+
if not isinstance(element, tuple):
|
| 646 |
+
continue
|
| 647 |
+
tag, attrs, subcontent = element
|
| 648 |
+
self.classes.fromXML(tag, attrs, subcontent, ttFont, version)
|
| 649 |
+
elif name == "passes":
|
| 650 |
+
for element in content:
|
| 651 |
+
if not isinstance(element, tuple):
|
| 652 |
+
continue
|
| 653 |
+
tag, attrs, subcontent = element
|
| 654 |
+
if tag == "pass":
|
| 655 |
+
p = Pass()
|
| 656 |
+
for e in subcontent:
|
| 657 |
+
if not isinstance(e, tuple):
|
| 658 |
+
continue
|
| 659 |
+
p.fromXML(e[0], e[1], e[2], ttFont, version)
|
| 660 |
+
self.passes.append(p)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
class Classes(object):
|
| 664 |
+
def __init__(self):
|
| 665 |
+
self.linear = []
|
| 666 |
+
self.nonLinear = []
|
| 667 |
+
|
| 668 |
+
def decompile(self, data, ttFont, version=2.0):
|
| 669 |
+
sstruct.unpack2(Silf_classmap_format, data, self)
|
| 670 |
+
if version >= 4.0:
|
| 671 |
+
oClasses = struct.unpack(
|
| 672 |
+
(">%dL" % (self.numClass + 1)), data[4 : 8 + 4 * self.numClass]
|
| 673 |
+
)
|
| 674 |
+
else:
|
| 675 |
+
oClasses = struct.unpack(
|
| 676 |
+
(">%dH" % (self.numClass + 1)), data[4 : 6 + 2 * self.numClass]
|
| 677 |
+
)
|
| 678 |
+
for s, e in zip(oClasses[: self.numLinear], oClasses[1 : self.numLinear + 1]):
|
| 679 |
+
self.linear.append(
|
| 680 |
+
ttFont.getGlyphName(x)
|
| 681 |
+
for x in struct.unpack((">%dH" % ((e - s) / 2)), data[s:e])
|
| 682 |
+
)
|
| 683 |
+
for s, e in zip(
|
| 684 |
+
oClasses[self.numLinear : self.numClass],
|
| 685 |
+
oClasses[self.numLinear + 1 : self.numClass + 1],
|
| 686 |
+
):
|
| 687 |
+
nonLinids = [
|
| 688 |
+
struct.unpack(">HH", data[x : x + 4]) for x in range(s + 8, e, 4)
|
| 689 |
+
]
|
| 690 |
+
nonLin = dict([(ttFont.getGlyphName(x[0]), x[1]) for x in nonLinids])
|
| 691 |
+
self.nonLinear.append(nonLin)
|
| 692 |
+
|
| 693 |
+
def compile(self, ttFont, version=2.0):
|
| 694 |
+
data = b""
|
| 695 |
+
oClasses = []
|
| 696 |
+
if version >= 4.0:
|
| 697 |
+
offset = 8 + 4 * (len(self.linear) + len(self.nonLinear))
|
| 698 |
+
else:
|
| 699 |
+
offset = 6 + 2 * (len(self.linear) + len(self.nonLinear))
|
| 700 |
+
for l in self.linear:
|
| 701 |
+
oClasses.append(len(data) + offset)
|
| 702 |
+
gs = [ttFont.getGlyphID(x) for x in l]
|
| 703 |
+
data += struct.pack((">%dH" % len(l)), *gs)
|
| 704 |
+
for l in self.nonLinear:
|
| 705 |
+
oClasses.append(len(data) + offset)
|
| 706 |
+
gs = [(ttFont.getGlyphID(x[0]), x[1]) for x in l.items()]
|
| 707 |
+
data += grUtils.bininfo(len(gs))
|
| 708 |
+
data += b"".join([struct.pack(">HH", *x) for x in sorted(gs)])
|
| 709 |
+
oClasses.append(len(data) + offset)
|
| 710 |
+
self.numClass = len(oClasses) - 1
|
| 711 |
+
self.numLinear = len(self.linear)
|
| 712 |
+
return (
|
| 713 |
+
sstruct.pack(Silf_classmap_format, self)
|
| 714 |
+
+ struct.pack(
|
| 715 |
+
((">%dL" if version >= 4.0 else ">%dH") % len(oClasses)), *oClasses
|
| 716 |
+
)
|
| 717 |
+
+ data
|
| 718 |
+
)
|
| 719 |
+
|
| 720 |
+
def toXML(self, writer, ttFont, version=2.0):
|
| 721 |
+
writer.begintag("classes")
|
| 722 |
+
writer.newline()
|
| 723 |
+
writer.begintag("linearClasses")
|
| 724 |
+
writer.newline()
|
| 725 |
+
for i, l in enumerate(self.linear):
|
| 726 |
+
writer.begintag("linear", _index=i)
|
| 727 |
+
writer.newline()
|
| 728 |
+
wrapline(writer, l)
|
| 729 |
+
writer.endtag("linear")
|
| 730 |
+
writer.newline()
|
| 731 |
+
writer.endtag("linearClasses")
|
| 732 |
+
writer.newline()
|
| 733 |
+
writer.begintag("nonLinearClasses")
|
| 734 |
+
writer.newline()
|
| 735 |
+
for i, l in enumerate(self.nonLinear):
|
| 736 |
+
writer.begintag("nonLinear", _index=i + self.numLinear)
|
| 737 |
+
writer.newline()
|
| 738 |
+
for inp, ind in l.items():
|
| 739 |
+
writer.simpletag("map", glyph=inp, index=ind)
|
| 740 |
+
writer.newline()
|
| 741 |
+
writer.endtag("nonLinear")
|
| 742 |
+
writer.newline()
|
| 743 |
+
writer.endtag("nonLinearClasses")
|
| 744 |
+
writer.newline()
|
| 745 |
+
writer.endtag("classes")
|
| 746 |
+
writer.newline()
|
| 747 |
+
|
| 748 |
+
def fromXML(self, name, attrs, content, ttFont, version=2.0):
|
| 749 |
+
if name == "linearClasses":
|
| 750 |
+
for element in content:
|
| 751 |
+
if not isinstance(element, tuple):
|
| 752 |
+
continue
|
| 753 |
+
tag, attrs, subcontent = element
|
| 754 |
+
if tag == "linear":
|
| 755 |
+
l = content_string(subcontent).split()
|
| 756 |
+
self.linear.append(l)
|
| 757 |
+
elif name == "nonLinearClasses":
|
| 758 |
+
for element in content:
|
| 759 |
+
if not isinstance(element, tuple):
|
| 760 |
+
continue
|
| 761 |
+
tag, attrs, subcontent = element
|
| 762 |
+
if tag == "nonLinear":
|
| 763 |
+
l = {}
|
| 764 |
+
for e in subcontent:
|
| 765 |
+
if not isinstance(e, tuple):
|
| 766 |
+
continue
|
| 767 |
+
tag, attrs, subsubcontent = e
|
| 768 |
+
if tag == "map":
|
| 769 |
+
l[attrs["glyph"]] = int(safeEval(attrs["index"]))
|
| 770 |
+
self.nonLinear.append(l)
|
| 771 |
+
|
| 772 |
+
|
| 773 |
+
class Pass(object):
|
| 774 |
+
def __init__(self):
|
| 775 |
+
self.colMap = {}
|
| 776 |
+
self.rules = []
|
| 777 |
+
self.rulePreContexts = []
|
| 778 |
+
self.ruleSortKeys = []
|
| 779 |
+
self.ruleConstraints = []
|
| 780 |
+
self.passConstraints = b""
|
| 781 |
+
self.actions = []
|
| 782 |
+
self.stateTrans = []
|
| 783 |
+
self.startStates = []
|
| 784 |
+
|
| 785 |
+
def decompile(self, data, ttFont, version=2.0):
|
| 786 |
+
_, data = sstruct.unpack2(Silf_pass_format, data, self)
|
| 787 |
+
(numRange, _, _, _) = struct.unpack(">4H", data[:8])
|
| 788 |
+
data = data[8:]
|
| 789 |
+
for i in range(numRange):
|
| 790 |
+
(first, last, col) = struct.unpack(">3H", data[6 * i : 6 * i + 6])
|
| 791 |
+
for g in range(first, last + 1):
|
| 792 |
+
self.colMap[ttFont.getGlyphName(g)] = col
|
| 793 |
+
data = data[6 * numRange :]
|
| 794 |
+
oRuleMap = struct.unpack_from((">%dH" % (self.numSuccess + 1)), data)
|
| 795 |
+
data = data[2 + 2 * self.numSuccess :]
|
| 796 |
+
rules = struct.unpack_from((">%dH" % oRuleMap[-1]), data)
|
| 797 |
+
self.rules = [rules[s:e] for (s, e) in zip(oRuleMap, oRuleMap[1:])]
|
| 798 |
+
data = data[2 * oRuleMap[-1] :]
|
| 799 |
+
(self.minRulePreContext, self.maxRulePreContext) = struct.unpack("BB", data[:2])
|
| 800 |
+
numStartStates = self.maxRulePreContext - self.minRulePreContext + 1
|
| 801 |
+
self.startStates = struct.unpack(
|
| 802 |
+
(">%dH" % numStartStates), data[2 : 2 + numStartStates * 2]
|
| 803 |
+
)
|
| 804 |
+
data = data[2 + numStartStates * 2 :]
|
| 805 |
+
self.ruleSortKeys = struct.unpack(
|
| 806 |
+
(">%dH" % self.numRules), data[: 2 * self.numRules]
|
| 807 |
+
)
|
| 808 |
+
data = data[2 * self.numRules :]
|
| 809 |
+
self.rulePreContexts = struct.unpack(
|
| 810 |
+
("%dB" % self.numRules), data[: self.numRules]
|
| 811 |
+
)
|
| 812 |
+
data = data[self.numRules :]
|
| 813 |
+
(self.collisionThreshold, pConstraint) = struct.unpack(">BH", data[:3])
|
| 814 |
+
oConstraints = list(
|
| 815 |
+
struct.unpack(
|
| 816 |
+
(">%dH" % (self.numRules + 1)), data[3 : 5 + self.numRules * 2]
|
| 817 |
+
)
|
| 818 |
+
)
|
| 819 |
+
data = data[5 + self.numRules * 2 :]
|
| 820 |
+
oActions = list(
|
| 821 |
+
struct.unpack((">%dH" % (self.numRules + 1)), data[: 2 + self.numRules * 2])
|
| 822 |
+
)
|
| 823 |
+
data = data[2 * self.numRules + 2 :]
|
| 824 |
+
for i in range(self.numTransitional):
|
| 825 |
+
a = array(
|
| 826 |
+
"H", data[i * self.numColumns * 2 : (i + 1) * self.numColumns * 2]
|
| 827 |
+
)
|
| 828 |
+
if sys.byteorder != "big":
|
| 829 |
+
a.byteswap()
|
| 830 |
+
self.stateTrans.append(a)
|
| 831 |
+
data = data[self.numTransitional * self.numColumns * 2 + 1 :]
|
| 832 |
+
self.passConstraints = data[:pConstraint]
|
| 833 |
+
data = data[pConstraint:]
|
| 834 |
+
for i in range(len(oConstraints) - 2, -1, -1):
|
| 835 |
+
if oConstraints[i] == 0:
|
| 836 |
+
oConstraints[i] = oConstraints[i + 1]
|
| 837 |
+
self.ruleConstraints = [
|
| 838 |
+
(data[s:e] if (e - s > 1) else b"")
|
| 839 |
+
for (s, e) in zip(oConstraints, oConstraints[1:])
|
| 840 |
+
]
|
| 841 |
+
data = data[oConstraints[-1] :]
|
| 842 |
+
self.actions = [
|
| 843 |
+
(data[s:e] if (e - s > 1) else "") for (s, e) in zip(oActions, oActions[1:])
|
| 844 |
+
]
|
| 845 |
+
data = data[oActions[-1] :]
|
| 846 |
+
# not using debug
|
| 847 |
+
|
| 848 |
+
def compile(self, ttFont, base, version=2.0):
|
| 849 |
+
# build it all up backwards
|
| 850 |
+
oActions = reduce(
|
| 851 |
+
lambda a, x: (a[0] + len(x), a[1] + [a[0]]), self.actions + [b""], (0, [])
|
| 852 |
+
)[1]
|
| 853 |
+
oConstraints = reduce(
|
| 854 |
+
lambda a, x: (a[0] + len(x), a[1] + [a[0]]),
|
| 855 |
+
self.ruleConstraints + [b""],
|
| 856 |
+
(1, []),
|
| 857 |
+
)[1]
|
| 858 |
+
constraintCode = b"\000" + b"".join(self.ruleConstraints)
|
| 859 |
+
transes = []
|
| 860 |
+
for t in self.stateTrans:
|
| 861 |
+
if sys.byteorder != "big":
|
| 862 |
+
t.byteswap()
|
| 863 |
+
transes.append(t.tobytes())
|
| 864 |
+
if sys.byteorder != "big":
|
| 865 |
+
t.byteswap()
|
| 866 |
+
if not len(transes):
|
| 867 |
+
self.startStates = [0]
|
| 868 |
+
oRuleMap = reduce(
|
| 869 |
+
lambda a, x: (a[0] + len(x), a[1] + [a[0]]), self.rules + [[]], (0, [])
|
| 870 |
+
)[1]
|
| 871 |
+
passRanges = []
|
| 872 |
+
gidcolmap = dict([(ttFont.getGlyphID(x[0]), x[1]) for x in self.colMap.items()])
|
| 873 |
+
for e in grUtils.entries(gidcolmap, sameval=True):
|
| 874 |
+
if e[1]:
|
| 875 |
+
passRanges.append((e[0], e[0] + e[1] - 1, e[2][0]))
|
| 876 |
+
self.numRules = len(self.actions)
|
| 877 |
+
self.fsmOffset = (
|
| 878 |
+
sstruct.calcsize(Silf_pass_format)
|
| 879 |
+
+ 8
|
| 880 |
+
+ len(passRanges) * 6
|
| 881 |
+
+ len(oRuleMap) * 2
|
| 882 |
+
+ 2 * oRuleMap[-1]
|
| 883 |
+
+ 2
|
| 884 |
+
+ 2 * len(self.startStates)
|
| 885 |
+
+ 3 * self.numRules
|
| 886 |
+
+ 3
|
| 887 |
+
+ 4 * self.numRules
|
| 888 |
+
+ 4
|
| 889 |
+
)
|
| 890 |
+
self.pcCode = (
|
| 891 |
+
self.fsmOffset + 2 * self.numTransitional * self.numColumns + 1 + base
|
| 892 |
+
)
|
| 893 |
+
self.rcCode = self.pcCode + len(self.passConstraints)
|
| 894 |
+
self.aCode = self.rcCode + len(constraintCode)
|
| 895 |
+
self.oDebug = 0
|
| 896 |
+
# now generate output
|
| 897 |
+
data = sstruct.pack(Silf_pass_format, self)
|
| 898 |
+
data += grUtils.bininfo(len(passRanges), 6)
|
| 899 |
+
data += b"".join(struct.pack(">3H", *p) for p in passRanges)
|
| 900 |
+
data += struct.pack((">%dH" % len(oRuleMap)), *oRuleMap)
|
| 901 |
+
flatrules = reduce(lambda a, x: a + x, self.rules, [])
|
| 902 |
+
data += struct.pack((">%dH" % oRuleMap[-1]), *flatrules)
|
| 903 |
+
data += struct.pack("BB", self.minRulePreContext, self.maxRulePreContext)
|
| 904 |
+
data += struct.pack((">%dH" % len(self.startStates)), *self.startStates)
|
| 905 |
+
data += struct.pack((">%dH" % self.numRules), *self.ruleSortKeys)
|
| 906 |
+
data += struct.pack(("%dB" % self.numRules), *self.rulePreContexts)
|
| 907 |
+
data += struct.pack(">BH", self.collisionThreshold, len(self.passConstraints))
|
| 908 |
+
data += struct.pack((">%dH" % (self.numRules + 1)), *oConstraints)
|
| 909 |
+
data += struct.pack((">%dH" % (self.numRules + 1)), *oActions)
|
| 910 |
+
return (
|
| 911 |
+
data
|
| 912 |
+
+ b"".join(transes)
|
| 913 |
+
+ struct.pack("B", 0)
|
| 914 |
+
+ self.passConstraints
|
| 915 |
+
+ constraintCode
|
| 916 |
+
+ b"".join(self.actions)
|
| 917 |
+
)
|
| 918 |
+
|
| 919 |
+
def toXML(self, writer, ttFont, version=2.0):
|
| 920 |
+
writesimple("info", self, writer, *pass_attrs_info)
|
| 921 |
+
writesimple("fsminfo", self, writer, *pass_attrs_fsm)
|
| 922 |
+
writer.begintag("colmap")
|
| 923 |
+
writer.newline()
|
| 924 |
+
wrapline(
|
| 925 |
+
writer,
|
| 926 |
+
[
|
| 927 |
+
"{}={}".format(*x)
|
| 928 |
+
for x in sorted(
|
| 929 |
+
self.colMap.items(), key=lambda x: ttFont.getGlyphID(x[0])
|
| 930 |
+
)
|
| 931 |
+
],
|
| 932 |
+
)
|
| 933 |
+
writer.endtag("colmap")
|
| 934 |
+
writer.newline()
|
| 935 |
+
writer.begintag("staterulemap")
|
| 936 |
+
writer.newline()
|
| 937 |
+
for i, r in enumerate(self.rules):
|
| 938 |
+
writer.simpletag(
|
| 939 |
+
"state",
|
| 940 |
+
number=self.numRows - self.numSuccess + i,
|
| 941 |
+
rules=" ".join(map(str, r)),
|
| 942 |
+
)
|
| 943 |
+
writer.newline()
|
| 944 |
+
writer.endtag("staterulemap")
|
| 945 |
+
writer.newline()
|
| 946 |
+
writer.begintag("rules")
|
| 947 |
+
writer.newline()
|
| 948 |
+
for i in range(len(self.actions)):
|
| 949 |
+
writer.begintag(
|
| 950 |
+
"rule",
|
| 951 |
+
index=i,
|
| 952 |
+
precontext=self.rulePreContexts[i],
|
| 953 |
+
sortkey=self.ruleSortKeys[i],
|
| 954 |
+
)
|
| 955 |
+
writer.newline()
|
| 956 |
+
if len(self.ruleConstraints[i]):
|
| 957 |
+
writecode("constraint", writer, self.ruleConstraints[i])
|
| 958 |
+
writecode("action", writer, self.actions[i])
|
| 959 |
+
writer.endtag("rule")
|
| 960 |
+
writer.newline()
|
| 961 |
+
writer.endtag("rules")
|
| 962 |
+
writer.newline()
|
| 963 |
+
if len(self.passConstraints):
|
| 964 |
+
writecode("passConstraint", writer, self.passConstraints)
|
| 965 |
+
if len(self.stateTrans):
|
| 966 |
+
writer.begintag("fsm")
|
| 967 |
+
writer.newline()
|
| 968 |
+
writer.begintag("starts")
|
| 969 |
+
writer.write(" ".join(map(str, self.startStates)))
|
| 970 |
+
writer.endtag("starts")
|
| 971 |
+
writer.newline()
|
| 972 |
+
for i, s in enumerate(self.stateTrans):
|
| 973 |
+
writer.begintag("row", _i=i)
|
| 974 |
+
# no newlines here
|
| 975 |
+
writer.write(" ".join(map(str, s)))
|
| 976 |
+
writer.endtag("row")
|
| 977 |
+
writer.newline()
|
| 978 |
+
writer.endtag("fsm")
|
| 979 |
+
writer.newline()
|
| 980 |
+
|
| 981 |
+
def fromXML(self, name, attrs, content, ttFont, version=2.0):
|
| 982 |
+
if name == "info":
|
| 983 |
+
getSimple(self, attrs, *pass_attrs_info)
|
| 984 |
+
elif name == "fsminfo":
|
| 985 |
+
getSimple(self, attrs, *pass_attrs_fsm)
|
| 986 |
+
elif name == "colmap":
|
| 987 |
+
e = content_string(content)
|
| 988 |
+
for w in e.split():
|
| 989 |
+
x = w.split("=")
|
| 990 |
+
if len(x) != 2 or x[0] == "" or x[1] == "":
|
| 991 |
+
continue
|
| 992 |
+
self.colMap[x[0]] = int(x[1])
|
| 993 |
+
elif name == "staterulemap":
|
| 994 |
+
for e in content:
|
| 995 |
+
if not isinstance(e, tuple):
|
| 996 |
+
continue
|
| 997 |
+
tag, a, c = e
|
| 998 |
+
if tag == "state":
|
| 999 |
+
self.rules.append([int(x) for x in a["rules"].split(" ")])
|
| 1000 |
+
elif name == "rules":
|
| 1001 |
+
for element in content:
|
| 1002 |
+
if not isinstance(element, tuple):
|
| 1003 |
+
continue
|
| 1004 |
+
tag, a, c = element
|
| 1005 |
+
if tag != "rule":
|
| 1006 |
+
continue
|
| 1007 |
+
self.rulePreContexts.append(int(a["precontext"]))
|
| 1008 |
+
self.ruleSortKeys.append(int(a["sortkey"]))
|
| 1009 |
+
con = b""
|
| 1010 |
+
act = b""
|
| 1011 |
+
for e in c:
|
| 1012 |
+
if not isinstance(e, tuple):
|
| 1013 |
+
continue
|
| 1014 |
+
tag, a, subc = e
|
| 1015 |
+
if tag == "constraint":
|
| 1016 |
+
con = readcode(subc)
|
| 1017 |
+
elif tag == "action":
|
| 1018 |
+
act = readcode(subc)
|
| 1019 |
+
self.actions.append(act)
|
| 1020 |
+
self.ruleConstraints.append(con)
|
| 1021 |
+
elif name == "passConstraint":
|
| 1022 |
+
self.passConstraints = readcode(content)
|
| 1023 |
+
elif name == "fsm":
|
| 1024 |
+
for element in content:
|
| 1025 |
+
if not isinstance(element, tuple):
|
| 1026 |
+
continue
|
| 1027 |
+
tag, a, c = element
|
| 1028 |
+
if tag == "row":
|
| 1029 |
+
s = array("H")
|
| 1030 |
+
e = content_string(c)
|
| 1031 |
+
s.extend(map(int, e.split()))
|
| 1032 |
+
self.stateTrans.append(s)
|
| 1033 |
+
elif tag == "starts":
|
| 1034 |
+
s = []
|
| 1035 |
+
e = content_string(c)
|
| 1036 |
+
s.extend(map(int, e.split()))
|
| 1037 |
+
self.startStates = s
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_B_D_T_.cpython-310.pyc
ADDED
|
Binary file (3.26 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_B_L_C_.cpython-310.pyc
ADDED
|
Binary file (423 Bytes). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/C_F_F_.cpython-310.pyc
ADDED
|
Binary file (2.12 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/DefaultTable.cpython-310.pyc
ADDED
|
Binary file (2.19 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/E_B_D_T_.cpython-310.pyc
ADDED
|
Binary file (20.6 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/F_F_T_M_.cpython-310.pyc
ADDED
|
Binary file (1.76 kB). View file
|
|
|
evalkit_tf437/lib/python3.10/site-packages/fontTools/ttLib/tables/__pycache__/G_M_A_P_.cpython-310.pyc
ADDED
|
Binary file (4.16 kB). View file
|
|
|