256 Commits

Author SHA1 Message Date
Cosimo Lupo
315705a58f [subset] fix subsetting OT-SVG when glyph id attribute is on the root <svg> element
Fixes https://github.com/fonttools/fonttools/issues/2548
2022-03-18 13:18:53 +00:00
aschmitz
d9f9466d63 subset: speed up subsetting of large fonts
Two small changes that significantly speed up subsetting of large fonts
such as Noto Sans CJK:

1. When emptying a charstring, simply empty its program rather than
attempting to decompile it first. (Only relevant when retaining GIDs.)

2. When reindexing charstrings, swap an accidentally-quadratic
implementation for one that is linear in the number of retained glyphs.
2021-12-09 23:44:57 -06:00
Cosimo Lupo
9b613b67c2
Merge pull request #2462 from fonttools/fix-subset-colr
subset/COLR: fix struct.error while subsetting Bungee COLR
2021-12-03 11:33:37 +00:00
Cosimo Lupo
780f2428b6 subset: when subsetting COLR only include glyphs after COLR closure, excluding glyf closure
Fixes #2461
2021-12-02 18:12:04 +00: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
Khaled Hosny
8e9ab24c11 [cffLib] Move desubroutinize from subset module to CFFFontSet
This way we can use it from both subset and merge modules.
2021-11-17 21:03:49 +02:00
Cosimo Lupo
247fa84b98 only rename glyph element ids when clash actually occurs 2021-11-16 14:28:14 +00:00
Cosimo Lupo
155ff60797 use any([<list comprehension>]) to avoid short-circuit function with side effect 2021-11-16 14:06:24 +00:00
Cosimo Lupo
07455790b1 simplify ranges() generator 2021-11-16 14:06:24 +00:00
Cosimo Lupo
66ec30c073 subset/svg: decorate xpath with lru_cache 2021-11-16 14:06:24 +00:00
Cosimo Lupo
d45da5df4c factor out method to resolve href targets as per review 2021-11-16 12:27:12 +00:00
Cosimo Lupo
27e4052380 encode bytes before fromstring; decode to str after tostring
when decompiled from binary, the SVG.docList contains (unicode) strings, decoded as UTF-8. lxml fromstring accepts either bytes or str, but when given str with the xml header declaring an explicit encoding, it rejects them (since the header is lying). So we encode to bytes before calling fromstring in case the SVG contains an explicit encoding (UTF-8 is the only one allowed anyway). When serializing to XML with tostring, we similarly decode to str as UTF-8. Not only to match SVG decompile (which gives us str), but if we didn't do that, then attempting to dump to XML would fail, because XMLWriter.writecdata expects str, not bytes.
2021-11-15 19:06:38 +00:00
Cosimo Lupo
1d19cc6e23 add comment for reason not to short-circuit with any() 2021-11-15 18:17:19 +00:00
Cosimo Lupo
12ed8b752c simplify and do el.attrib.get('id') as per review 2021-11-15 17:46:42 +00:00
Cosimo Lupo
92470ea361 rename parmeter ids => retained_ids for clarity as per review 2021-11-15 17:41:42 +00:00
Cosimo Lupo
a7216ae766 subset: drop svg doc if subsetted to empty 2021-11-15 17:08:55 +00:00
Cosimo Lupo
d1f2481fa0 fix invalid escape sequence in GID_RE pattern 2021-11-15 17:08:55 +00:00
Cosimo Lupo
a4df567718 subset/svg: support resolving cross-references and pruning elements
With this I can finally follow xlink:href and url(#...) sort of
references within the SVG doc and subset the elements accordingly so
that only those that are reachable from the initial set of glyph
elements are kept.
2021-11-15 16:07:18 +00:00
Cosimo Lupo
05e6d577cd subset: add --pretty-svg option to enable lxml pretty_print
False (more compact) by default
2021-11-15 16:07:18 +00:00
Cosimo Lupo
0dc2be3e78 require lxml to subset SVG
support for namespaces and xpath is insufficient in built-in ElementTree; supporting both lxml and ElementTree is too complicated, let's simply require lxml to be able to subset SVG for now
2021-11-15 16:07:18 +00:00
Cosimo Lupo
d44af9f2d7 basic subset.svg impl that simply remaps id='glyphXXX'
this drops svg document records when they no longer intersect the subset. It keeps them in their entirety (for now) when they still intersect the subset, only renaming all the id='glyphXXX' to point to the new glyph indices after subsetting. Unused, unreferenced elements are not pruned yet.
2021-11-15 16:07:18 +00:00
Cosimo Lupo
16249d1fb8 subset: store original glyphOrder and map from old to new indexes in Subsetter instance
so that SVG tables' subset_glyphs method can use it to get glyph names from GISs and to remap from old to new GIDs
2021-11-15 16:07:18 +00:00
Cosimo Lupo
bd47bdae97 subset: don't drop SVG table, add WIP subset/svg.py stub
simply  pass-through for now
2021-11-15 16:07:18 +00:00
Cosimo Lupo
425e1afd36 subset: move _add_method and _uniq_sort to subset/util submodule 2021-11-15 16:07:18 +00:00
Cosimo Lupo
5c54f4e666 subset: don't try subsetting ClipList if None 2021-10-11 16:48:00 +02:00
Behdad Esfahbod
76ac638c43 [subset] Add a couple None checks
Exercised by Simon's Gulzar
2021-10-01 11:42:58 -06:00
Behdad Esfahbod
d867397532 Remove residual allowVID stuff
Part of https://github.com/fonttools/fonttools/pull/2398
2021-08-25 15:55:17 -06:00
Behdad Esfahbod
d5de11d805 [ttFont] Make setGlyphOrder() clear reverseGlyphOrderMap
Part of https://github.com/fonttools/fonttools/pull/2398
2021-08-23 14:01:26 -06:00
Cosimo Lupo
99743c14df subset: explicitly subset ClipList, avoids warning when lazy-loading
relying on ClipList.compile to drop unused clips based on updated glyphOrder won't work when font is loaded lazily (default for subsetter), because ClipList gets decompiled too late (after glyphOrder has already been modified) and this produces warnings about missing glyphIDs.
Better to make the subsetter explicilty prune unused clips.
2021-08-18 09:42:10 +02:00
Cosimo Lupo
11871673ff [subset] fixed CPAL pruning after removal of ColorIndex 2021-07-23 17:27:57 +01:00
Cosimo Lupo
1cb7e36bbd COLRv1: rename otData structs to remove 'V1' to match updated draft spec
This is a breaking change (but the COLRv1 API was already marked as unstable and subject to change)

The changes in this PR are meant to match the changes from the COLRv1 draft spec at:
https://github.com/googlefonts/colr-gradients-spec/pull/302
2021-06-28 16:13:47 +01:00
Cosimo Lupo
1df4f1eac1 subset: drop empty features unless 'size' with FeatureParams table
Fixes #2324
2021-05-27 09:33:29 -06:00
Cosimo Lupo
926f721832 return True from SinglePos.prune_post_subset to not change semantics
the useless subtable might have been there to stop the next subtable from applying...
https://github.com/fonttools/fonttools/pull/2313#issuecomment-844497422
2021-05-20 10:01:58 +01:00
Cosimo Lupo
defe0f997a subset: don't prune_post_subset if no SinglePos Value
Fixes https://github.com/fonttools/fonttools/issues/2312
2021-05-19 20:16:14 +01:00
Cosimo Lupo
6e23150507 subset: prune v0 base glyphs and layers when none are left after subsetting COLRv1 table
Thanks Qunxin for reporting the bug!
2021-05-14 10:47:20 +01:00
Behdad Esfahbod
3a6ebb8dc7 [subset] Fix drop-hints implementation in Device tables
Fixes https://github.com/fonttools/fonttools/issues/2272
2021-04-22 12:29:16 -06:00
Behdad Esfahbod
33d9e3d6de [subset] Use bytearray() instead of array.array('B') 2021-04-08 09:41:45 -06:00
Behdad Esfahbod
492118c7b5 [subset] Set glyph.data to b'' instead of ''
Fixes tests after 7adbe44154c1bd8a99668512e88facbcb034f05f
2021-04-08 09:41:45 -06:00
Cosimo Lupo
2136aac0f0 subset: fix pruning unused CPAL palettes when 0xFFFF is present
FIxes https://github.com/fonttools/fonttools/issues/2257
2021-04-06 19:43:45 +01:00
Behdad Esfahbod
8c59d4be0c [subset] Improve PairPosFormat2 subsetting
This does two things:

1. Intersect subsetter glyphset with the table's Coverage before
   passing to ClassDef1 for subsetting.  Anything that doesn't
   get past Coverage wouldn't ever get to ClassDef1,

2. Never reuse class0 of ClassDef2.  There's unspoken assumption
   that ClassDef2's class0 is never used for actual kerning, since
   that's the unbounded "every other glyph" class.  Previously our
   ClassDef subsetter was reusing class0 if "every other glyph"
   happened to become empty because of the subset glyphset.  Don't
   do that for PairPos's ClassDef2.  As a result of this assumption,
   don't keep a PairPosClass2 subtable if only ClassDef2's class0
   survived subsetting.

Would be good to add tests for both.

Related to https://github.com/harfbuzz/harfbuzz/issues/2703
2021-03-29 16:17:27 +01: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
Behdad Esfahbod
c321fbe3fa [subset] Call VariationStore.subset_varidxes() as method 2021-03-11 14:12:03 -07: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
Cosimo Lupo
09af39ab53
subset: donwgrade COLRv1 to v0 if all v1 glyphs are dropped 2021-02-15 11:58:56 +00:00
Cosimo Lupo
55c9a0a1ef
update subset_test.py using new COLRv1 dict format 2021-02-15 11:15:42 +00:00
Cosimo Lupo
056aba8e4a
prune unused CPAL palette entries after subsetting COLR glyphs
Fixes https://github.com/fonttools/fonttools/issues/2174
2021-02-15 11:15:42 +00:00
Cosimo Lupo
109c07d16c
subset: support subsetting COLRv1 base glyphs
In COLR.closure_glyphs augment the subset with the glyphs rechable from the COLRv1 base glyphs already in the subset.
In COLR.subset_glyphs, subset and rebuild LayerV1List and BaseGlyphV1List with the base glyphs to keep. Drop COLR if emptied
2021-02-15 11:15:42 +00:00
Nikolaus Waxweiler
06913cc715 Implement format 12 cmap pruning 2021-01-13 16:30:46 +00:00
Khaled Hosny
d8e546df5f [subset] Allow LangSys tags in --layout-scripts
Allow specifying which LangSys tags to accept for each script, using
script.lang form. For example:

    --layout-scripts=arab.dflt,arab.URD,latn

To keep DefaultLangSys and “URD” language for “arab” script, and all
languages for “latn” script.
2020-11-20 23:38:29 +02:00
Caleb Maclennan
7e3c4acfde
Use 0 not False to disable checkChecksums as documented and used
While False does get the job done, the value is not always treated as
a boolean. It is overloaded so that 1 or greater is True, but more than
1 has a different meaning than 1. Hence usage should always be as an
integer as documented so that it's clear(er) this isn't just an on/off
toggle.
2020-09-10 16:41:30 +03:00