278 Commits

Author SHA1 Message Date
Jack McCabe
eeba234ee0 [subset] PR feedback implementation 2022-09-30 15:59:11 +01:00
Jack McCabe
14ce08bd75 [subset] extend CPALv1 test 2022-09-30 15:41:14 +01:00
Jack McCabe
70112b947d [subset] prevent CPAL nameIDs from being dropped 2022-09-30 12:36:28 +01:00
Jack McCabe
b945fd6305 [subset] Fix enumeration of palette entry labels 2022-09-30 11:40:39 +01:00
Cosimo Lupo
276f6aaf44 [subset] keep and don't prune CPAL if OT-SVG table is present
Fixes #2814

or at least is a workaround until a proper 'fix'
2022-09-14 12:55:40 -06:00
Cosimo Lupo
25a05c72ab subset: add --no-lazy option to load font eagerly as TTFont(lazy=False) 2022-09-08 15:42:34 +01:00
Behdad Esfahbod
27965842eb [subset] Fix subsetting of variable fonts
Fixes https://github.com/fonttools/fonttools/issues/2769
2022-08-24 10:12:32 -06:00
Behdad Esfahbod
3eed84da01
Merge pull request #2756 from fonttools/makeOutputFileName-fragment
[cliTools.makeOutputFileName] Add fragment argument
2022-08-22 06:29:19 -06:00
Behdad Esfahbod
24c9fb6ffa [cliTools] Rename fragment to suffix 2022-08-22 06:26:30 -06:00
Behdad Esfahbod
68f31b580c
Merge pull request #2755 from fonttools/scaleUpem-cff
[scaleUpem] Support CFF/CFF2
2022-08-22 06:23:54 -06:00
Behdad Esfahbod
82a523cc17 [subset/CFF] Remove FDSelect workaround from 2014
Fixes https://github.com/fonttools/fonttools/issues/139
2022-08-20 02:41:24 +02:00
Behdad Esfahbod
e146ddfd86 [cliTools.makeOutputFileName] Add fragment argument
And use it from subsetter and instancer.

Related to https://github.com/fonttools/fonttools/issues/1156
2022-08-19 12:20:21 -06:00
Behdad Esfahbod
d4d8c4ac5b [scaleUpem] Support CFF/CFF2 2022-08-19 11:03:23 -06:00
Cosimo Lupo
dbe60eae80 [subset/svg] use broader ImportError instead of ModuleNotFoundError
Fixes https://github.com/fonttools/fonttools/issues/2696
2022-07-18 11:32:44 +02:00
Cosimo Lupo
be623e257f Clean up svgDoc compression
This is based on bungeman's https://github.com/fonttools/fonttools/pull/2627

Previously, an entire `SVG ` table would be marked as compressed if any
of the decoded SVG documents in it were compressed. Then on encoding all
SVG documents would be considered for compression. The XML format had no
means to indicate if compression was desired.

Instead, mark each svgDoc with its compression status. When decoding
mark the svgDoc as compressed if the data was compressed. When encoding
try to compress the svgDoc if it is marked as compressed. In the XML
format the data itself is always uncompressed, but allow an optional
`compressed` boolean attribute (defaults to false) to indicate the
svgDoc should be compressed when encoded.

We also try to make sure that older code that relies on docList containing
sequences of three items (doc, startGID, endGID) will continue to work
without modification.
2022-06-09 15:15:05 +01:00
Behdad Esfahbod
5295ebe966
Update Lib/fontTools/subset/__init__.py
Co-authored-by: Jany Belluz <jany.belluz@daltonmaag.com>
2022-06-03 05:48:03 -06:00
Behdad Esfahbod
a1fabd0fcb [subset] Update default feature tags
Corresponding to HarfBuzz commits:
40193adbfc
40d7d56e53
2022-06-03 05:41:31 -06:00
Cosimo Lupo
0e43b0e2c3 [subset] Fix subsetting SinglePosFormat2 when ValueFormat=0
If a font has SinglePosFormat2 subtable with ValueFormat=0, then it contains a Value list with all None values.
Even though we don't build such inefficient tables, they do exist in the wild, as #2602 demostrates so we should handle those nicely, by downgrading them to Format1 with a single None value
2022-04-27 16:03:23 +01:00
Cosimo Lupo
bb1dbf4198 drop the 'X' from recalcAvgCharWidth method name 2022-04-21 19:02:39 +01:00
Cosimo Lupo
12942feb6b [subset] use recalcXAvgCharWidth method 2022-04-21 18:46:11 +01:00
Cosimo Lupo
af6804bed5 make USE_HARFBUZZ_REPACKER a 3-state option, defaults to auto
if explicitly enabled, it will raise ImportError if uharfbuzz is not found, and will propagate the uharfbuzz error instead of silently falling back to the pure-python serializer
2022-04-21 18:11:20 +01:00
Cosimo Lupo
1bb9607b72 [subset] add --no-harfbuzz-repacker CLI flag 2022-04-21 15:46:12 +01:00
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