149 Commits

Author SHA1 Message Date
Khaled Hosny
cf08265cd5 Black 2024-02-06 15:47:35 +02:00
Behdad Esfahbod
36e2c6dcd3 [varLib.models] Simplify based on review 2023-12-12 04:39:05 -07:00
Behdad Esfahbod
455fc87081 [varLib.merger] Use new API for faster interpolation in Instancer 2023-12-10 18:40:48 -07:00
Simon Cozens
57fb47de3a
Allow for merging of NULL anchors (#3248)
* A failing test for #3247

* Fix up NULL entry/exit records on merge, fixes #3247
2023-08-07 17:12:12 +01:00
Behdad Esfahbod
b14a29c353 [varLib.merger] Support sparse CursivePos
Part of https://github.com/fonttools/fonttools/issues/3168
2023-07-18 07:14:25 -06:00
Behdad Esfahbod
4c24a3e328 [varLib/merger] Fix merging of SinglePos with pos=0
Fixes https://github.com/fonttools/fonttools/issues/3111
2023-05-19 18:37:15 +02:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Behdad Esfahbod
68b0509711 [varLib.AligningMerger] Try harder to make it work as a standalone merger 2022-08-04 13:22:00 -06:00
Behdad Esfahbod
287ac43212 [varLib.AligningMerger] Make it work as a standalone merger 2022-08-04 12:30:44 -06:00
Cosimo Lupo
c6b2ba5286 [varLib.merge] fix NameError: 'NotANone'
Fixes https://github.com/fonttools/fonttools/issues/2712
2022-07-29 13:05:26 +02:00
Just van Rossum
1c8efee98d fix typo in COLR merge 2022-07-07 16:00:43 +02:00
Cosimo Lupo
cdc7cc3cc4 COLR merger be cleverer and only deepcopy effectively reused layers
instead of blindly copying them all like in previous commit.
2022-07-05 20:37:54 +01:00
Cosimo Lupo
8a9f16d129 COLRVariationMerger: copy destination layers to ensure they are unique and can be modified in place 2022-07-05 17:53:39 +01:00
Cosimo Lupo
e5029801d2 support merging COLR masters with 'sparse' glyphsets or different layer count
There is no longer a requirement that all the masters have exactly the same base color glyphs as the default masters. Similarly, it's no longer required that all masters' LayerLists have the same total count of layers. It is sufficient that, for a base color glyph in the default master, a non-default master may (or may not) contain one with the same name and same effective number of layers (which in turn can be laid out differently in the respective LayerLists).
This provides greater flexibility when working with variable font project with sparse glyph sets.
2022-07-05 00:11:12 +01:00
Cosimo Lupo
4b9f35dc2b varLib.merger: subset self.ttfs to non-None (sparse) values in VariationMerger.mergeThings 2022-07-04 18:52:20 +01:00
Cosimo Lupo
d85aa2d119 COLRVariationMerger: further optimize DeltaSetIndexMap
previously we only reused the VarIndexBase of a previously seen variable table when the current's varIdxes were _fully_ equal to one of the previous; now we also try to find a match anywhere in the accummulated list of self.varIdxes, including a partial match at the tail of the list.
2022-06-28 14:11:28 +01:00
Cosimo Lupo
c397764720 COLRVariationMerger: implement reuse of VarIndexBase between tables with same varIdxes
When multiple variable tables refer to the same delta-sets they can now share the same VarIndexBase so the resulting DeltaSetIndexMap is a bit smaller.
For simplicity, we only reuse VarIndexBase when variable tables fully share (ie. same, and same number of) varIdxes; potentially we could reuse subsets of varIdxes (e.g. a VarColoStop.Alpha has a +0.5 delta, and later on elsewhere a PaintVarSolid.Alpha has a similar +0.5 delta; the latter could have a VarIndexBase that reuses an existing DeltaSetIndexMap entry for the former), but for now this I think is good enough.
2022-06-27 17:17:32 +01:00
Cosimo Lupo
99a754a48e varLib/merger.py: (minor) rename self.varTables => self.varTableIds 2022-06-27 15:54:51 +01:00
Cosimo Lupo
f02593cf1a COLRVariationMerger: fix logic in convertSubTablesToVarType
Before we were too greedy in the way we converted subtables to VarType. E.g. If a PaintTransform wrapping a PaintRadialGradient contained variations in the Affine2x3, we would incorrectly convert also the gradient's ColorLine (and ColorStops) to VarColorLine, VarColorStop, etc. (even if the gradient was not variable!). Instead we want skip traversing a given subtable including its children when the predicate doesn't match.
2022-06-24 18:14:58 +01:00
Cosimo Lupo
a53a235302 varLib.merger: set Paint.Format to int(PaintFormat)
for consistency with the way tables are decompiled from binary data
2022-06-24 11:36:58 +01:00
Cosimo Lupo
e58c43d187 varLib.merger: add a COLRVariationMerger to merge multiple master COLRv1 into a variable COLR 2022-06-21 17:27:12 +01:00
Cosimo Lupo
0cbdc8536b [otBase/varLib.merger] don't recurse in ensureDecompiled, merger is already working recursively 2022-06-21 17:27:11 +01:00
Cosimo Lupo
c34ff0d474 [varLib.merger/errors] fix undefined exception name
The exception UnsupportedFormat was defined and then redefined with the same name in varLib.errors, and imported twice from varLib.merger, probably as result of a sweeping find/replace.
Rename it 'InconsistentFormats' as originally intended.
2022-06-17 11:24:56 +01:00
Cosimo Lupo
20de0784c2 send DeprecationWarning if FONTTOOLS_GPOS_COMPACT_MODE env var is set
and factor out shared code to read the env var
2022-04-22 11:32:43 +01:00
Jany Belluz
0bd2834d1e Fix ufo2ft regression by bringing back the env var for now 2022-04-22 10:14:16 +01:00
Jany Belluz
abc0441957 [config] Add new config module and use it for GPOS compression level 2022-04-14 15:23:02 +01:00
Khaled Hosny
47457b14d6
[varLib] Fix instantiating some SinglePos subtables (#2555) 2022-03-22 08:34:18 +00:00
Simon Cozens
4f8c01909a
Handle merging SinglePos with valueformat=0 (#2550) 2022-03-17 13:01:06 +00:00
Jany Belluz
604513a38f Fix a few comments 2021-07-05 17:28:43 +01:00
Jany Belluz
bba5e8b213 Add optional compaction of GPOS PairPos subtables in otlLib.optimize.gpos
See pull request: https://github.com/fonttools/fonttools/pull/2326

The new module `otlLib.optimize.gpos` provides `compact` functions that
can reduce the file size of GPOS PairPos lookups by splitting subtables
in a smart way to avoid storing zero-valued pairs.

The compaction methods are called from `otlLib.builder` and
`varLib.merger` so that static and variable fonts can benefit from the
optimization at compile time.

The new module `otlLib.optimize` is also executable, to allow running
the optimization on existing fonts.

The optimization is a trade-off because on the one hand it can reduce
significantly the byte size of the GPOS table (up to 50% in random
Google Fonts) but on the other hand it adds to the compilation time and
may make fonts very slightly bigger once compressed to WOFF2 (because
WOFF2 doesn't mind about zero values and compresses them very well).

As such, the optimization is off by default, and you can activate it by
providing the environment variable `FONTTOOLS_GPOS_COMPACT_MODE=5` for
example (values from 0 = off to 9 = max file size savings, but many more
subtables).
2021-07-05 17:28:43 +01:00
Cosimo Lupo
b8ce99962c [merger] make getattr(valueRecord, *) default to 0 if it has Device tables but corresponding value is not set
Fixes https://github.com/fonttools/fonttools/pull/2323
2021-05-25 12:36:17 +01:00
Cosimo Lupo
72004fcd7e VarLibMergeError first parameter must be a Merger object
a lot of places instead pass in the 'self' parameter, incorrectly assuming that is a Merger.
This is meant to fix 'AttributeError: 'dict' object has no attribute 'ttfs'' as reported in https://github.com/googlefonts/fontmake/issues/766#issuecomment-836576341
2021-05-13 15:40:44 +01:00
Cosimo Lupo
6b9b23251e VarLibMergeError.stack is a list of str, not a str
Fixes https://github.com/googlefonts/fontmake/issues/766
2021-05-06 11:59:10 +01:00
Behdad Esfahbod
f514a6823d [varLib.merger] Use Value.getEffectiveFormat() instead of .getFormat() 2021-04-22 12:29:16 -06:00
Behdad Esfahbod
3d578dd1de [varLib.merger] Adjust for removal of Coverage / ClassDef .Format 2021-03-23 11:05:00 -07:00
Behdad Esfahbod
69918d2945 Revert "[varLib.merge] Fix tests"
This reverts commit fb0c60cd2ce68df546ea2887946bc7f97bbb6921.
2021-03-23 11:02:41 -07:00
Simon Cozens
bfe4bad37b Use kwargs and explicit stack 2021-03-19 10:38:15 +00:00
Simon Cozens
8ba31b0a43 Improve error message 2021-03-18 21:23:40 +00:00
Simon Cozens
3e0a87a146 Shorten exception names 2021-03-18 20:58:11 +00:00
Simon Cozens
6c547864b6 Use individual exception classes instead of enum 2021-03-18 15:49:49 +00:00
Simon Cozens
b26728d3cb Specifically catch VarLibMergeError 2021-03-17 11:56:02 +00:00
Simon Cozens
5bac84374b Ensure TTF list is correct 2021-03-15 12:50:07 +00:00
Simon Cozens
e2a859d649 Ensure table name is in error message stack 2021-03-15 12:04:36 +00:00
Simon Cozens
1abfbb6cc7 Explain merge errors in designer-friendly terms 2021-03-13 22:30:27 +00:00
Behdad Esfahbod
abc1ba07a4 [misc.roundTools] New module; move otRound() here
Code relying on old place (fixedTools.otRound) still works.
2021-03-04 09:20:43 -07:00
Simon Cozens
46c8f90da8 Use _ to denoted unused loop variable 2020-05-07 21:00:28 +01:00
punchcutter
aeb5149f15 Add variable support for BASE table 1.1 2020-03-20 13:34:02 -07:00
Nikolaus Waxweiler
4320392eb5 merger: Convert input checking asserts into proper exceptions 2020-02-13 15:02:31 +00:00
justvanrossum
51ff4a5d69 Move ensureDecompiled() calls to mergeObjects(). This makes more sense, but still needs the hasattr checks. 2020-01-29 11:05:01 +01:00
justvanrossum
033145adf6 this fixes #1808, but I'm not sure this is the most elegant solution 2020-01-29 10:10:55 +01:00