57 Commits

Author SHA1 Message Date
Behdad Esfahbod
a8462a65c5 [specializer] Use "is None" 2024-11-12 20:17:50 -07:00
Behdad Esfahbod
751d1383af [specializer] Reuse list len()'s 2024-11-12 20:15:38 -07:00
Behdad Esfahbod
cfba1f995f [cffLib.specializer] Make command-merging linear again
The consideration for blends had made it into O(n^2).
Make it linear again.

Speeds up Tests/cffLib/specializer_test.py::CFFSpecializeProgramTest::test_maxstack_blends
3x for me.
2024-11-12 18:43:03 -07:00
Behdad Esfahbod
7e6d31569f [cffLib.specializer] Adjust stack use calculation
See comment.
2024-11-12 17:47:52 -07:00
Behdad Esfahbod
bb7a29e81a [cffLib.specializer] Fix more stack-overflow opportunity
I think it's solid now.
2024-11-06 19:13:35 -05:00
Behdad Esfahbod
776e1ce132 [cffLib.specializer] Fix CFF argument stack overflow
The code was always merging at least two blends, which was causing
stack-overflow with a test font of ours. Move the overflow check
earlier to catch that.

Fixes https://github.com/fonttools/fonttools/issues/3676
2024-11-05 10:38:00 -05:00
Behdad Esfahbod
614d9ebf6b [cffLib.specializer] Minor refactor 2024-11-04 13:52:28 -05:00
Behdad Esfahbod
7a0062a718 [cffLib.specializer] Add cmdline to specialize a CFF2 font 2024-10-29 08:25:20 -06:00
Behdad Esfahbod
c22f7d5af4 [cffLib.specializer] Simplify vsindex protocol 2024-05-14 18:13:51 -06:00
Behdad Esfahbod
ce78d2c88f Typo 2024-05-13 17:17:30 -06:00
Cosimo Lupo
53e71f9eb7
Merge pull request #3309 from fonttools/pyup-scheduled-update-2023-10-23
Scheduled weekly dependency update for week 43
2023-11-03 10:33:00 +00:00
Cosimo Lupo
335a1e56ec re-run black v23.10 on all .py files 2023-11-03 10:25:15 +00:00
Khaled Hosny
48da520472 Fix SyntaxWarning in Python 3.12
Fixes https://github.com/fonttools/fonttools/issues/3311
2023-10-25 14:34:27 +03:00
Cosimo Lupo
4b73a17e0c
[cff.specializer] Fix SyntaxWarning: invalid escape sequence
Fixes #3322
2023-10-25 10:33:31 +01:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Behdad Esfahbod
61160fe5db [cffLib.specializer] Fix generalizer blend
Fixes https://github.com/fonttools/fonttools/issues/1975
2022-08-17 11:13:42 -06: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
Chris Simpkins
7abf2e4c75
transition basestring to str
https://github.com/fonttools/fonttools/issues/2232
2021-03-27 10:23:29 -04:00
Simon Cozens
8d32a24710
[docs] Source documentation for cffLib (#1935)
* [docs] Source documentation for cffLib

* Address feedback
2020-05-14 17:04:34 +01:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Read Roberts
4ee5e6da16 [cffLib specializer] Fix bug in programToCommands with CFF2 charstrings
When checking if there was an initial width argument, old logic did not correctly sum the number of blend and non-blend arguments before the first hint or moveto operator.

Added test case. Old logic dropped the arguments for the hmoveto in the last glyph.
2019-07-30 20:25:38 -07:00
Read Roberts
5b3db36670
Sparse cff2vf support (#1591)
* Added getter (in the form of a property decorator) for T2Charstring.vsindex. Fixes endless compile loop in some circumstances.

Fixed bug in mutator: need to remove vsindex from snapshotted charstrings, plus formatting clean up

* Fix for subsetting HVAR tables that have an AdvanceWidthMap when the --retain-gid option is used. Needed to make subset_test.py::test_retain_gids_cff2 tests pass.

* in varLib/cffLib.py, add support for sparse sources, and sources with more than one model, and hence more than one VarData element in the VarStore.

CFF2 source fonts with multiple FontDicts in the FDArray need some extra work. With sparse fonts, some of the source fonts may have a fewer FontDicts than the default font. The getfd_map function() builds a map from the FontDict indices in the default font to those in each region font. This is needed when building up the blend value lists in the master font FontDict PrivateDicts, in order to fetch PrivateDict values from the correct FontDict in each region font.

In specializer.py, add support for CFF2 CharStrings with blend operators. 1) In generalizeCommands, convert a blend op to a list of args that are blend lists for the following regular operator. A blend list as a default font value, followed by the delta tuple. 2) In specializeCommands(), convert these back to blend ops, combining as many successive blend lists as allowed by the stack limit.

Add test case for sparse CFF2 sources.
The test font has 55 glyphs. 2 glyphs use only 2 sources (weight = 0 and 100). The rest use 4 source fonts: the two end points of the weight axis, and two intermediate masters. The intermediate masters are only 1 design space unit apart, and are used to change glyph design at the point in design space. For the rest, at most 2 glyphs use the same set of source fonts. There are 12 source fonts.

Add test case for specializer programToCommands() and commandsToProgram by converting each CharString.program in the font to a command list, and back again, and comparing original and final versions.
2019-04-26 09:33:52 -07:00
Miguel Sousa
ddff29cb5d Fix DeprecationWarning: invalid escape sequence 2019-04-01 14:04:14 -07:00
Behdad Esfahbod
31019eac8e [CFF] Whitespace 2018-11-30 21:46:16 -05:00
ReadRoberts
c118bd205e varLib. Move CFF2CharStringMergePen-specific logic out of specializer.py
- restore specializer.py:commandsToProgram to original simple code
- handle blend arguments in command list with CFF2CharStringMergePen method.
2018-11-19 17:30:53 -08:00
ReadRoberts
a460eee80b varLib. Add support for building CFF2 variable font
Fix syntax error reported by build system: can't mix string string types when doing literal concatenation

Fix local import reference - doesn't work in Python3.

Addressed issues raised by @msousa for PR 1345 yesterday.

Will change cff2_merge_funcs.py and cff2mergePen.py from tab to space indentations after the current comments are resolved.

Add various improvements from comments:
- do not edit the post table under varLib.build(). Setting post table format 2 or 3 is now expected to be managed by whatever calls varLib.build().
- In the t2CharStringPen module, rename closure _round() nested in makeRoundFunc to an exportable function, and use it in cff2mergePen.
- remove TypeSupply copyright from cff2mergePen.
- use modulo function to convert float to int when it is meant to be 0 in cff2mergePen.

cff2_merge_funcs.py:merge_PrivateDicts() should only be blending the hint related fields in the PrivateDict. This oversight that was surfaced by @madig reporting an error building his Cantrell font. The bug appeared when the font was subroutinized, as the pen draw method then has to interpret the Subr field in order to access T2Charstring subroutines.

Fix expected ttx output file. When I removed the logic to add glyph names to the post table, glyph names in the ttx file changed.

Miguel prefers a simple list for readability in cff2_merge_funs.py:138.
2018-11-12 11:38:18 -08:00
ReadRoberts
5a32da5ee6 varLib. Add support for building CFF2 variable font with a call to varLib.build().
Fix specializer.py:commandToProgram(); I had made the required args incompatible with the prior version.
2018-11-12 11:38:04 -08:00
ReadRoberts
08aef71458 varLib. Add support for building CFF2 variable font with a call to varLib.build().
Add support for the blend operator and arguments in commandsToProgram, and specializeCommands().
2018-11-12 11:37:40 -08:00
Cosimo Lupo
3734b6c036
cffLib/specializer: minor; use < instead of <= maxstack - 1 2018-07-25 11:56:32 +01:00
Kunihiko Sakamoto
41a21cce27 [cffLib.specializer] Leave 1 stack free area for subroutinizer use 2018-07-25 17:29:27 +09:00
Behdad Esfahbod
a07a6f85f7 [cffLib.specializer] Try keeping type of args
41445b8449 (commitcomment-22260340)
2018-02-18 11:48:22 -08:00
Behdad Esfahbod
462b7f8683 [cffLib.specializer] When copying iterables, cast to list specifically
See 41445b8449
2017-05-20 18:34:20 -07:00
Behdad Esfahbod
4fd719159a [cffLib.specializer] Enforce minimum number of arguments in all ops 2017-05-08 14:09:02 -06:00
Behdad Esfahbod
0cbe43483d [cffLib.specializer] Fix width-extraction code when stack is empty 2017-05-08 14:06:26 -06:00
Behdad Esfahbod
a3743828ce [cffLib.specializer] Default ignoreErrors to False
Ouch.  I meant False.  I think I changed it to True for testing and accidentally committed it.
2017-05-08 14:05:10 -06:00
Behdad Esfahbod
a71639f8b6 [cffLib.specializer] Add minor TODO items 2017-05-08 13:01:43 -06:00
Behdad Esfahbod
30b804003e [cffLib.specializer] Add programToString and stringToProgram from _test.py 2017-05-07 22:12:19 -06:00
Behdad Esfahbod
3720c6e020 [cffLib.specializer] Fix combining of more ops into rlinecurve / rcurveline
Fixes failing tests.
2017-05-07 12:54:31 -06:00
Miguel Sousa
3f9eeec58d [cffLib.specializer] Fix DeprecationWarnings in py3 2017-05-06 23:20:11 -07:00
Behdad Esfahbod
8432c04bb1 [cffLib.specializer] Remove -3 hack that was to match AFDKO 2017-05-06 17:54:05 -06:00
Behdad Esfahbod
2fd2e4a7cf [cffLib.specializer] Add TODO item 2017-05-06 14:14:54 -06:00
Behdad Esfahbod
0bf5044d12 [cffLib.specializer] Implement width extraction in programToCommands()
Test:

./fonttools cffLib.specializer 7 0 8 rmoveto 1 2 3 4 5 0 rrcurvet
2017-05-06 13:12:58 -06:00
Behdad Esfahbod
bef46993f6 [cffLib.specializer] Use bool() cast instead of comparison to 0
Makes it work on custom types better.
2017-05-06 05:02:22 -06:00
Behdad Esfahbod
d1d36ce66b [cffLib.specializer] Minor 2017-05-06 04:58:59 -06:00
Behdad Esfahbod
d3947b86d2 [cffLib.specializer] Fix bug introduced in c9653e98c6da7770a13faebd4a218f5d1d362536
Test case (which apparently is not covered by our current tests!):

./fonttools cffLib.specializer 1 2 3 4 5 0 rrcurveto
2017-05-06 04:28:45 -06:00
Behdad Esfahbod
050bcc0c8a [cffLib.specializer] Minor adjustments to previous commit 2017-05-06 03:49:06 -06:00
Behdad Esfahbod
c9653e98c6 [cffLib.specializer] Fix curve merging logic!
Found that elegant model I've been looking for, yay!  My previous modeling
was overly complicating the problem, and failing at solving all corner cases.
New one should fix them all!
2017-05-06 03:23:00 -06:00
Behdad Esfahbod
e35976900a [cffLib.specializer] Fix typo in peephole optimization 2017-05-06 03:00:39 -06:00
Behdad Esfahbod
d8fcb3a12a [cffLib.specializer] Fix orientation propagation through a pizza spline 2017-05-06 02:06:58 -06:00
Behdad Esfahbod
a5ca6c49f2 [cffLib.specializer] Fix hvcurveto/vhcurveto argument swapping logic
Fixes remaining 2 failing tests.
2017-05-06 01:44:19 -06:00