79 Commits

Author SHA1 Message Date
Behdad Esfahbod
cc09d5f381 [TupleVariation] Slightly speed up compileCoords
Small but measurable speedup.
2023-10-14 12:57:32 -04:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Behdad Esfahbod
6aca5be9b7 [gvar] Don't expand glyph for unused pointCount
Keep it in the API though.
2022-12-09 11:39:07 -07:00
Behdad Esfahbod
5ff9546531 [TupleVariation] Add __imul__ 2022-10-13 10:35:02 -06:00
Cosimo Lupo
a0bd872f0e TupleVariation: make shared tuples order deterministic
most frequent first (like before https://github.com/fonttools/fonttools/pull/2351), only sort ties alphabetically
2021-07-02 12:52:54 +01:00
Garret Rieger
7f9e2c3808 sort shared tuples produced by Counter.most_common()
In python 3.7 and earlier most_common() sorts first by the item count and then arbitrarily in the event of ties. This can result in two identical instancing operations producing different binary results.
2021-06-30 17:00:59 -07:00
Behdad Esfahbod
dc0600c764 [TupleVariation] Fold call to hasImpact() into getUsedPoints()
Related:
https://github.com/fonttools/fonttools/issues/2263

Part of:
https://github.com/fonttools/fonttools/pull/2261
2021-04-09 13:36:29 -06:00
Behdad Esfahbod
bcd4a62f10 [TupleVariation] Use b'' instead of NotImplemented for "use shared points" 2021-04-09 12:16:15 -06:00
Behdad Esfahbod
ef0d695de9 [TupleVariation] Remove unused usesSharedPoints return from tv.compile() 2021-04-09 12:13:49 -06:00
Behdad Esfahbod
85c9102d47 [TupleVariation] Use Counter() instead of defaultdict() for sharedCoords 2021-04-09 09:23:34 -06:00
Behdad Esfahbod
f3f1628571 [TupleVariation] Comment 2021-04-08 19:47:28 -06:00
Behdad Esfahbod
1650c15b55 [TupleVariation] Minor shift more code into getUsedPoints() 2021-04-08 19:32:54 -06:00
Behdad Esfahbod
050b07d336 [TupleVariation] Optimize compileDeltas() 2021-04-08 18:24:13 -06:00
Behdad Esfahbod
78e9bc7b49 [TupleVariation] Optimize compilePoints()
Special-case "all points used" representation in the internal API.
2021-04-08 18:24:13 -06:00
Behdad Esfahbod
e0513cfee3 [TupleVariation] Avoid recompiling pointData
Pass them down to tv.compile().

Tests need to be updated for changed new internal tv.compile() API.
2021-04-08 18:22:00 -06:00
Behdad Esfahbod
7051829f75 [TupleVariation] Compile point set counts outside of key() 2021-04-08 17:42:10 -06:00
Behdad Esfahbod
683e898768 [TupleVariation] Optimize point-sharing 2021-04-08 17:36:58 -06:00
Behdad Esfahbod
f40e522ce9 [TupleVariation] Speed up case of useSharedPoints=False 2021-04-08 15:57:53 -06:00
Behdad Esfahbod
92bf782ef3 [TupleVariatin] Minor optimization of sharedPoints 2021-04-08 15:53:48 -06:00
Behdad Esfahbod
8dae627d3f [TupleVariation] Rewrite getUsedPoints() as list comprehension 2021-04-08 15:50:52 -06:00
Behdad Esfahbod
12c88cc3a4 [TupleVariation] Remove use of byteord() 2021-04-08 15:50:52 -06:00
Behdad Esfahbod
c88aab1544 [TupleVariation] Minor optimization in compileDeltaValues_() 2021-04-08 15:50:52 -06:00
Behdad Esfahbod
997b976e9a [TupleVariation] Rewrite assertion faster 2021-04-08 15:50:52 -06:00
Behdad Esfahbod
67794827ff [TupleVariation] Use defaultdict in compileSharedTuples 2021-04-08 11:56:36 -06:00
Behdad Esfahbod
9b379bbb87 [TupleVariation] Further optimize compileCoord() 2021-04-08 11:51:15 -06:00
Behdad Esfahbod
48e827aa21 [TupleVariation] Minor optimization in compileCoord() 2021-04-08 11:46:32 -06:00
Behdad Esfahbod
416ff89171 [TupleVariation] Minor optimize in using sharedCoordinates 2021-04-08 11:40:44 -06:00
Behdad Esfahbod
ec80f24315 [TupleVariation] Remove use of bytesjoin() 2021-04-08 11:11:50 -06:00
Behdad Esfahbod
f8d54b1ebb [TupleVariation] Minor rewrite bound checks 2021-04-08 11:01:20 -06:00
Behdad Esfahbod
5c815a6def [TupleVariation] Do away with another bytesjoin() 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
a715f57130 [TupleVariation] Optimize compilePoints() 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
6abf8680b4 [TupleVariation] More bytes optimization 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
250e59886f [TupleVariation] Micro-optimize away a lambda 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
62a89bc3d5 [TupleVariations] Optimize serialization loops 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
b1b672e17e [TupleVariation] Remove a few hot asserts
We verify the code instead.
2021-04-08 09:41:45 -06:00
Behdad Esfahbod
4cbf6ae1c4 [TupleVariation] Minor 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
d5d771b2bf [TupleVariation] Use array.array to serialize multiple deltas 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
1e6b20cc2c [TupleVariation] Don't round deltas (again!)
Remove tests that passed float in.
2021-04-08 09:41:45 -06:00
Behdad Esfahbod
9405244617 [TupleVariation] Use bytearray() instead of io.Bytes() 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
8284af6b61 [TupleVariation] Use list(coordinates) instead of coordinates[:]
The latter is more expensive in GlyphCoordinates().
2021-04-08 09:41:45 -06:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
Cosimo Lupo
79d654eaf2
TupleVariation: use floatToFixedToStr and strToFixedToFloat in toXML/fromXML methods 2019-10-08 13:40:04 +01:00
Chris Simpkins
12814aa7b1 refactor array.fromstring to array.frombytes
fromstring is a deprecated array method
2019-08-29 22:58:42 -04:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Cosimo Lupo
7ffd6a3d0f
instancer: minor changes following Evan's review 2019-07-31 16:31:38 +01:00
Cosimo Lupo
d21aa29824
instancer: fixes addressing Evan's comments
- changed getCoordWidth method to use all if-stmt, ordered by ret value (0, 1, 2).
- added more info to TypeError message in getCoordWidth method.
- in round/scaleDeltas, chained if statements in one line to avoid writing the loop twice.
2019-06-17 15:18:54 +01:00
Cosimo Lupo
18efee2c7b
TupleVariation: rename get{DeltaType,CoordWidth}; do not special-case scalar=0
we still need to branch between the case where coordinates are wrapped in (x, y) tuples or naked floats.
2019-06-14 11:03:38 +01:00
Cosimo Lupo
125bd5186a
TupleVariation: rename {check,get}DeltaType; refactor __iadd__ 2019-04-12 17:01:39 +01:00
Cosimo Lupo
dc99925bee
instancer: always calculate inferred deltas upfront to simplify code
and instead of sumDeltas method, use in-place add operator.
2019-04-04 18:05:11 +01:00
Cosimo Lupo
f220d36df1
instancer: merge TupleVariations left with same axes after pinning
The instantiateTupleVariationStore function now groups TupleVariation
tables that have the same axes 'tents', then merges them into a single
TupleVariation by summing their deltas. The rounding to integer happens
after summing the scaled deltas as floats, to reduce off-by-one errors.

To be able to sum gvar TupleVariation, it needs to calculate the inferred
deltas so it now takes two optional lists (origCoords and endPts) that
are passed on to iup_delta function. These only make sense for gvar
type of TupleVariation, of course, and are unused for cvar tuples.

It also run iup_delta_optimize on the gvar deltas that are left after
partial instancing and whose inferred deltas had to be interpolated.
This can be disabled with --no-optimize CLI option.

Also added calcInferredDeltas and optimize methods to TupleVariation
class, which use functions from varLib.iup module, plus tests
that exercise them.
2019-04-04 15:11:23 +01:00