130 Commits

Author SHA1 Message Date
Simon Cozens
f53a75fb1d Check for overflows in a loop 2021-09-15 11:08:50 +01:00
Simon Cozens
f9b927cdbb Fix chained contextual builder overflow 2021-08-30 10:35:56 +01:00
Jany Belluz
2ff3159a5f Mark the environment variable as experimental 2021-07-05 17:28:44 +01:00
Jany Belluz
527179619b Refactor the Cluster class to be top-level instead of nested the function 2021-07-05 17:28:44 +01:00
Jany Belluz
d1c46f9d10 Clarify comment with the plan vs the actual implementation 2021-07-05 17:28:44 +01:00
Jany Belluz
7860dd5fe8 Add tests that optimize block matrices 2021-07-05 17:28:44 +01:00
Jany Belluz
ef67839fdb Fix typing error 2021-07-05 17:28:44 +01:00
Jany Belluz
3b34b228dd Fix fonttools otlLib.optimize command line 2021-07-05 17:28:43 +01: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
Behdad Esfahbod
1e83650db8 [otlLib] Ensure built SinglePos ValueRecords are padded with 0s
Like when they are decompiled.

Part of https://github.com/fonttools/fonttools/pull/2237
2021-03-24 09:26:26 -07:00
Behdad Esfahbod
d961ef5e52 [otlLib] Ensure built PairPos2 ValueRecords are padded with 0s
Like when they are decompiled.

Part of https://github.com/fonttools/fonttools/pull/2237
2021-03-24 09:26:26 -07:00
Cosimo Lupo
b1ca16738c [otlLib] Ensure built PairPos1 ValueRecords are padded with 0s
Like when decompiled.

See 2089d05126 (r48578120)

Part of https://github.com/fonttools/fonttools/pull/2237
2021-03-24 09:25:42 -07:00
Nikolaus Waxweiler
2089d05126
Merge pull request #2229 from fonttools/varLib-otlLib-noreload
[varLib/otlLib] Allow merging into VariationFont without first saving GPOS PairPos2
2021-03-22 16:42:45 +00:00
Behdad Esfahbod
0faf01d5f1 [otlLib] Generate Value1 / Value2 if respective formats are non-zero
Previously otlLib was generating None if the values themselves were
empty even if the value format was non-empty.  This happened to work
for compiling to binary since the compiler handles Value=None.

But this was confusing varLib.merger module (as in when building
variable fonts from such otlLib-built master GSUB/GPOS tables, without
roundtripping to OTF/TTF binary first), because in varLib.merger,
a None means "this master doesn't provide that info; skip it"; whereas
in a PairPos table a None as generated by otlLib simply meant "all
values are zero", which is different from "this master doesn't
provide this value".

This fixes that, such that ufo2ft can build variable-font without
saving masters to binary.

Part of https://github.com/googlefonts/ufo2ft/pull/486
2021-03-19 13:59:27 -06:00
Simon Cozens
f2f8a6a42a Fix docstring too 2021-03-15 13:47:44 +00:00
Simon Cozens
d0101eff1e Correct otlLib documentation 2021-03-15 11:34:36 +00:00
Cosimo Lupo
9aeb48286d
black 2021-02-25 17:16:02 +00:00
Kamile Demir
29ff42d15f
Reusing otlLib buildStatTable() in feaLib 2021-02-25 17:16:02 +00:00
Tom Archer
be898ec6f9 Change ValueError to OpenTypeLibError 2021-01-20 14:30:49 +00:00
Tom Archer
9712407054 Change TypeError to ValueError 2021-01-20 11:19:43 +00:00
Tom Archer
7c6337facf Add exception and test 2021-01-19 17:57:53 +00:00
Martin Hosken
ee87790326 Refix by removing duplicates from the same glyphset 2020-12-01 23:55:43 +07:00
Martin Hosken
75f314b149 Fix class2defs self overlapping glyphsets 2020-12-01 23:38:12 +07:00
Simon Cozens
fb9d34af1b Try again... 2020-11-17 12:05:52 +00:00
Simon Cozens
df5527bccc Revert "Remove unneeded populateDefaults". removed wrong line...
This reverts commit a043e35f1ca287431bd63aa566d50d7e70634fea.
2020-11-17 12:05:31 +00:00
Simon Cozens
635df38f32 Comment to explain copy 2020-11-17 09:13:30 +00:00
Simon Cozens
8e524e41f5 "if not x in" -> "if x not in" 2020-11-17 09:12:38 +00:00
Simon Cozens
7bbff5d21f Re-case variable names (and clarify) 2020-11-17 09:11:56 +00:00
Simon Cozens
1a6f53dfc9 Explain weird (list(foo))[0] thing 2020-11-17 09:11:37 +00:00
Simon Cozens
a043e35f1c Remove unneeded populateDefaults 2020-11-17 09:08:44 +00:00
Simon Cozens
be7d9a33a3 Raise on unknown format, also reorder to be more sensible 2020-11-17 09:08:20 +00:00
Simon Cozens
07b186a41e Build most compact lookup representation
This builds all possible representations of a contextual lookup and then selects the most copact
2020-11-16 13:42:07 +00:00
Simon Cozens
f6fac3cbbf Helper function to determine compiled size of a lookup 2020-11-16 13:41:19 +00:00
Simon Cozens
ef002fbcc3 Add format 1 subtable builder 2020-11-16 13:41:02 +00:00
Simon Cozens
8b3963a306 Add format 2 subtable builder 2020-11-16 13:40:50 +00:00
Simon Cozens
fe075a4a0e Helper functions for building rulesets and rules for F1/F2 lookups 2020-11-16 13:39:55 +00:00
Simon Cozens
88ed5e2c9e Refactor out part of format3 builder which handles LookupRecords
This will allow the same code to be used by other contextual formats (f1, f2)
2020-11-16 13:39:07 +00:00
Simon Cozens
85edf0e380 Use the ChainContextualRule class instead of bare tuples 2020-07-22 14:20:50 +01:00
Simon Cozens
b9f2482c42 Add a ChainContextualRule class 2020-07-22 14:20:50 +01:00
Simon Cozens
ae5e000e29 Run black on all these too. 2020-07-15 17:16:12 +01:00
Simon Cozens
69a76e9dd8 Reformat with black. 2020-07-15 13:25:33 +01:00
Simon Cozens
c1a885ad55 Missed stylistic fix 2020-07-11 19:58:06 +01:00
Simon Cozens
b6f7b2dc4b Stylistic fixes from feedback 2020-07-11 19:54:52 +01:00
Simon Cozens
8c3dfc4e33 Refactor subtable/lookup record building code
It's a bit gross, but I'm blaming OpenType for that. I'm doing this now because otherwise it would be even more repetitive once we start adding format 1 Rule and Ruleset subtables.
2020-07-07 17:35:16 +01:00
Simon Cozens
bc0f69884e Thinko 2020-07-07 13:28:44 +01:00
Simon Cozens
f04ffe4131 Make non-chaining contextuals where we can. (Fixes #1856) 2020-07-07 13:19:36 +01:00
Simon Cozens
df3e08bb22 Add a function to set coverage for GSUB5/GPOS7 lookups 2020-07-07 13:15:27 +01:00
Simon Cozens
06c270582a Begin to use the new rulesets. Be explicit that we are building Format 3 lookups right now. 2020-07-07 12:48:53 +01:00
Simon Cozens
9f4cc2f1cb Introduce the concept of a ClassContextualRuleSet
Currently unused but will be super helpful for optimizing the formats of contextual lookups.

* Splits the rules of a class contextual lookup based on explicit subtable breaks
* Returns various properties on the ruleset to help determine appropriate layout format.
* (More properties, such as "touched glyphs", planned - will be added when needed.)
2020-07-07 12:44:25 +01:00