56 Commits

Author SHA1 Message Date
Khaled Hosny
cf08265cd5 Black 2024-02-06 15:47:35 +02:00
خالد حسني (Khaled Hosny)
1c25210360
[featureVars] Re-use FeatureVariationRecord's when possible
If a FeatureVariationRecord with the same ConditionTable exists re-use
it and append FeatureTableSubstitutionRecord’s.

Without this, in the following feature code only the first lookup will
be applied since there will be two FeatureVariationRecord with the same
ConditionTable, so the first will be matched and the other will be
skipped:

    conditionset test {
        wght 600 1000;
        wdth 150 200;
    } test;

    variation ccmp test {
        sub e by a;
    } ccmp;

    variation rlig test {
        sub b by c;
    } rlig;

With this change only one FeatureVariationRecord will be created with
two FeatureTableSubstitutionRecord’s.
2024-01-10 19:06:26 +02:00
Cosimo Lupo
6358b47682
[featureVars] don't overwrite FeatureVariations, append new records
Currently, addFeatureVariationsRaw always deletes existing GSUB.FeatureVariations and overwrites them with the newly built records.
It doesn't have to, though. If the features for which we are adding feature variations are not already "variable", we can simply append the DS-rules-generated records to the FeatureVariations.
We raise an error if the existing FeatureVariations already reference the same feature tags used for the DS rules, as that could generate ambiguity/undefined logic.
2023-12-02 10:10:41 +00:00
Cosimo Lupo
a2f6f2ffed
[featureVars] allow to assign same subst lookup to several feature tags
this can be useful to maximise layout engine compatibility or simply to have same feature variations substitutions be accessible via mutliple feature tags for whatever reason.

Fixes https://github.com/fonttools/fonttools/issues/2050
Fixes https://github.com/fonttools/fonttools/issues/3004
2023-12-01 16:53:31 +00:00
Behdad Esfahbod
832f2f766f [varStore.optimize] Use faster intTools.bit_count as popcount 2023-05-25 08:19:15 -06:00
Behdad Esfahbod
6a13bdc2e6 [featureVars] Remove unused argument 2023-05-02 10:57:43 -06:00
Behdad Esfahbod
5b96fff9ce [featureVars] Process lookups for features other than rvrn last
Fixes https://github.com/fonttools/fonttools/issues/3097
2023-05-02 10:57:43 -06:00
Behdad Esfahbod
b7b4a3b090 [varLib.featureVars] Fix bug in overlayBox
See added test. Previously we were cutting remainder box
even if the intersection had dimensions not present in the
remainder box. Ouch!

Fixes https://github.com/fonttools/fonttools/issues/3003
2023-02-24 07:51:00 -07:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Behdad Esfahbod
0f48f0a5ea [varLib/featureVars] Insert rvrn lookups at beginning
Fixes https://github.com/fonttools/fonttools/issues/2140
Fixes https://github.com/googlefonts/fontmake/issues/950
2022-10-28 15:45:40 -06:00
Cosimo Lupo
c41cda33c1
featureVars: set FeatureCount/LangSysCount, even if 0 2022-10-20 16:45:44 +01:00
Jens Kutilek
d0020b2536
Add check for missing glyphs to featureVars (#2654)
* Add check for missing glyphs to featureVars
2022-06-17 15:24:54 +02:00
Simon Cozens
0f03e6529a
[docs] Fix sphinx warnings (#2453)
* Add default auto doc options

* Ensure all references are unique

* Use anonymous links to avoid duplicate references

* Remove default options, fix wrong module name

* Don’t index repeated class

* Remove repeated classes included through automodule

* Fix warnings

* We don’t use our own static directory

* Correctly format XML in docs

* Fix indentation

* Fix overline

* Bring TOC to top

* Fix definition list

* Offset definition lists and examples

* Fix erroneous markup

* Fix markup

* Already included in automodule

* Fix args markup

* Correct markup for example

* Don’t reindex repeated module

* Correct XML code block markup

* Fix markup errors, change example to doctest

* Correct list markup

* Make ttx docstring both valid RST and valid help output

* Various other boring markup fixes

* Fix example indenting

* Make docstring valid RST and valid help output

* Mock import for reportlab

* It’s ok if manual links don’t appear in toctrees

* Oops typo, I guess doctests are useful
2021-12-02 15:31:49 +00:00
Simon Cozens
563730f8ce
Support variable feature syntax (#2432) 2021-10-28 11:58:54 +01:00
Nikolaus Waxweiler
6023bab627 Raise legible error message when script is missing a dflt langsys 2021-01-19 16:42:40 +00:00
Nikolaus Waxweiler
45a8fcefc2
[varLib] Allow feature variations to be active across the entire space (#1957)
* Allow feature variations to be active across the entire space

* Add test with empty condition set

* Skip initial box instead of removing it

* Correct comment
2020-05-15 09:27:15 -07:00
Nikolaus Waxweiler
af0567f847 featureVars: Use new exceptions 2020-02-13 15:02:31 +00:00
justvanrossum
db04262bed support multiple <featureTag> features 2019-10-17 20:46:59 +02:00
justvanrossum
d2ea72cbec addFeatureVariations(): allow the feature tag to be specified (default to 'rvrn'); allow said feature to already exist, in which case we append new lookup indices to the existing feature 2019-10-17 20:01:05 +02:00
Nikolaus Waxweiler
68a5ceac6d varLib: Remove py23 imports 2019-08-10 15:39:02 +01:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Cosimo Lupo
5455517689
Merge remote-tracking branch 'origin/master' into partial-instancer 2019-07-31 15:22:48 +01:00
Behdad Esfahbod
84b9e9c387 [varLib.featureVars] Fix region-merging code on Py3
We should clean up all the various "convert dict to tuple" duplicated
code, but this fixes it for now.  doctest updated.

Fixes https://github.com/fonttools/fonttools/issues/1659
2019-07-09 16:14:01 -07:00
Cosimo Lupo
afc194db19
featureVars: populate counts on OT tables
this is done automatically upon compiling; however it's good to do it here
as well, in case one wants to pass the updated font directly to other modules
like 'subset' which requires these fields to be present -- without having
to first compile and decompile.
2019-05-30 12:29:23 +01:00
Cosimo Lupo
aa8a5bc616
featureVars: avoid duplicate refs to 'rvrn' feature in default langsys
the buildGSUB function creates an empty GSUB with no FeatureRecords, so the
FeatureIndex list should be empty initially; the index of the newly created
rvrn feature record will be appended later on by addFeatureVariationsRaw
function.
2019-05-29 13:40:57 +01:00
Behdad Esfahbod
37366b563e [varLib.featureVars] Fix overlap remainder logic
Fixes https://github.com/fonttools/fonttools/issues/1400
2018-12-05 10:33:35 -08:00
Behdad Esfahbod
f530e3e398
Merge pull request #1372 from fonttools/varLib-faster-featureVars
[varLib] Far faster featureVars
2018-11-15 14:59:48 -08:00
Behdad Esfahbod
2295e27dca [varLib.featureVars] Remove unused intersectBoxes() 2018-11-10 15:19:10 -05:00
Behdad Esfahbod
f1a9c6c036 Move popCount() into new fontTools.misc.intTools 2018-11-10 15:16:52 -05:00
Behdad Esfahbod
7111b253b1 Move hashdict into new fontTools.misc.dictTools 2018-11-10 15:14:36 -05:00
Behdad Esfahbod
0adc304c7b [varLib.featureVars] Add TODO for moving things to fontTools.misc 2018-11-10 15:09:35 -05:00
justvanrossum
49b7333cf5 According to the spec, this number should be 0x00010000. 2018-11-10 15:07:18 -05:00
Behdad Esfahbod
e85a9755ef [varLib.featureVars] Merge same-subsitutions rules as well 2018-11-09 23:59:33 -05:00
Behdad Esfahbod
34241a819b [varLib.featureVars] Drop fully-occluded remainder boxes
Re-land the correct version.
2018-11-09 16:13:21 -05:00
Behdad Esfahbod
95e13008e1 Revert "[varLib.featureVars] Drop fully-occluded remainder boxes"
This reverts commit edecdce0a576b2e15e21711bcc73ae9beba0c527.

Was wrong.  Will figure out the correct version.
2018-11-09 16:08:01 -05:00
Behdad Esfahbod
edecdce0a5 [varLib.featureVars] Drop fully-occluded remainder boxes 2018-11-09 15:52:18 -05:00
Behdad Esfahbod
7d5fbe1605 [varLib.featureVars] Improve new algorithm to its full potential
See 0283b1f.

By finishing overlayBox() to cull remainder box when possible, we generate
far fewer spurious boxes, if any.

For the featureVars_test.py test case, this now generates optimal output,
that is, 2*n - 1 boxes.

Running time for n=20 stays at 0.06s, which is probably Python startup
time.

Running time for n=100 is down from 2.5s with unoptimized new algorithm,
to 0.17s for this and number of output boxes from 5050 to the optimal 199.

Fixes #1372 again
2018-11-09 15:35:58 -05:00
Behdad Esfahbod
f2b26304ff [varLib.featureVars] Py3 2018-11-09 14:54:13 -05:00
Behdad Esfahbod
0be1636176 [varLib.featureVars] Optimize popCount()
While might look like unjustified micro-optimizing, for featureVars_test.py with
n=100, speeds up 10%.  From 2.5s to 2.2s.
2018-11-09 14:34:15 -05:00
Behdad Esfahbod
0283b1fd1d [varLib.featureVars] Rewrite algorithm
Whereas previous algorithm had exponential running time and return
value size, new one has quadratic.

For featureVars_test.py test case, for example, which is a pathological
test case of n sliding intervals, the number of output intervals of
various algorithms are:

- Previous algorithm: 2**n - 1
- New algorithm: n*(n-1)/2
- Optimal algorithm: 2*n - 1

Ie, we go from exponential to quadratic, whereas in this case the optimal
solution is linear.

Running time of said test, for n=20, goes from over 20s, to 0.06s.

The algorithm can be improved.  The overlayBox() function currently does
not try to shrink the remainder box.  Doing that will probably bring us
to optimal solution for this test case.

Fixes https://github.com/fonttools/fonttools/pull/1372

One test is failing.  Needs to be investigated that new output is correct,
and test expectations updated.
2018-11-09 14:30:46 -05:00
Behdad Esfahbod
de2179caee [varLib.featureVars] Update comment to match actual function output format 2018-11-09 12:15:37 -05:00
Behdad Esfahbod
c7e5a35515 [varLib.featureVars] Space 2018-11-09 12:11:48 -05:00
Behdad Esfahbod
60db91646c [varLib.featureVars] Add overlayFeatureVariations() 2018-11-09 11:17:17 -05:00
Behdad Esfahbod
a37dab4b74 [varLib.featureVars] Return exploded space from main entry point
Also, make font optional
2018-11-09 10:56:47 -05:00
Behdad Esfahbod
5560b26a5d [varLib] Avoid combinatorial explosion in featureVars
By merging duplicate regions.

Fixes https://github.com/fonttools/fonttools/issues/1370
2018-11-09 10:39:19 -05:00
justvanrossum
e45117aa02 Fixed bug that tried to get an attr off a LangSysRecord rather than a LangSys. Fixes #1365 2018-11-08 10:04:25 +01:00
Cosimo Lupo
6e9a24b45b
featureVars: mark module as experimental/subject-to-change 2018-06-14 15:25:09 +01:00
Cosimo Lupo
04dc7339fd
[featureVars] remove unused fvar code; normalized default space is always (-1.0, 1.0) 2018-04-18 12:07:06 +01:00
justvanrossum
978967983c removing normalization step: min/max values are now expected to be given in normalized coordinates 2018-04-18 08:51:45 +02:00
Cosimo Lupo
0f1c6b3cf4
[featureVars] add doctests for non intersecting spaces or regions 2018-04-17 16:53:33 +02:00