110 Commits

Author SHA1 Message Date
Behdad Esfahbod
4650b8d293 [cff] Store varStore in CharStrings 2022-08-26 21:00:37 -06:00
Behdad Esfahbod
d4d8c4ac5b [scaleUpem] Support CFF/CFF2 2022-08-19 11:03:23 -06: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
Behdad Esfahbod
2963fa503a [cffLib.widths] Fix off-by-one in values
Was wrong; didn't match the code block above it.
2022-08-09 21:44:08 -06:00
Khaled Hosny
4bb0e776a7
Merge pull request #2570 from fonttools/cff-TopDictIndex
[cffLib] Fix calls to TopDictIndex()
2022-04-01 00:24:17 +02:00
Behdad Esfahbod
c7781ec423 [cffLib] Remove leftover GlobalState
Fixes https://github.com/fonttools/fonttools/issues/1848
2022-03-31 15:34:11 -06:00
Behdad Esfahbod
64fc028eee [cffLib] Fix calls to TopDictIndex()
Fixes https://github.com/fonttools/fonttools/issues/1847
2022-03-31 15:33:05 -06: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
Khaled Hosny
232b2ccbc4 Move the rest of py23 module to textTools
Change all imports to use textTools module, except the test_py23.py test
which is kept until we decide to remove the module (if ever).
2021-08-20 01:29:45 +02:00
Zachary Scheuren
41da60f130 Add missing dict operators to CFF2 2021-03-30 21:24:14 +09: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
Simon Cozens
089f24da6b
Ensure all fonttools CLI tools have help documentation (#1948)
Note UI change : `fonttools varLib.models` now takes prefixed options `-d` or `-l` instead of guessing the intended feature from the number of arguments.

We have a number of command line tools which are somewhat opaque. (varLib.models in particular was very confusing.) This ensures that they all use argparse to have a consistent interface, and all have --help documentation which at least details their parameters, and hopefully therefore gives more of a clue about what they do. Those which use logging have had a command-line logging parameter added.
2020-05-12 15:11:30 +01:00
Simon Cozens
2cef07af80
[doc] Add help options to fonttools CLI (#1920)
This adds a `help` verb (and `--help` option) to the `fonttools` command line tool. Submodules will be listed in the help text if they have an importable `main` function with a docstring, and `main`'s docstring will be used as the one-line description for the help text.
2020-05-12 06:31:13 +01:00
Khaled Hosny
6cb0a56020 [cffLib] Make sure glyph names are unique
Similar to what we do with “post” table names. I’d have said the font is
broken, but all applications I tried it with loaded it just fine, though
they differed in which glyph to pick from the duplicate ones.

Fixes https://github.com/fonttools/fonttools/issues/1602
2019-08-17 12:51:31 +02:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Khaled Hosny
71ea0cbe07
Merge pull request #1677 from fonttools/fdselct-format-4
[cffLib] Support FDSselect format 4
2019-08-02 01:05:27 +02:00
Khaled Hosny
ad4bb343fc [cffLib] Support FDSselect format 4
Introduced in CFF2 table, but code does not limit it to CFF2 table. If
FDSelect format is set to 4, it will be read/written regardless of the
table version.
2019-08-01 21:28:46 +02: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
ReadRoberts
77f72bc62b Convert OTF font files in test data to ttx files.
This required a fix to fontTools/cffLib. When reading a CFF2 variable font (VF) from XML, the VF state in FontDict and PrivateDict does not get set. I made a temporary fix by adding a loop to set PrivateDict.vstore for all the PrivateDict objects after the XML file has been read. This should not be necessary, and in the near future I will revisit both this issue, and the related use of isCFF2 when compiling/decompiling.
2019-05-01 16:01:43 -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
Cosimo Lupo
8e8da97a4c [cffLib]: add clear() method to Index class to empty in-place 2019-02-07 01:58:22 +01:00
Nikolaus Waxweiler
a8d4bfc42d Replace PrivateDict.__getattr__ with property
The dunder method doesn't seem to be doing anything other than providing
an `in_cff2` attribute. Do that with a property instead of bending
__getattr__.

This one confused me when I was working on
https://github.com/fonttools/fonttools/pull/1488.
2019-02-06 10:15:38 +00:00
Cosimo Lupo
649dc49dba [cffLib] Fix RecursionError in BaseDict.__getattr__ when unpickling
We need to raise AttributeError for non-existing dunder methods like
'__deepcopy__' or '__getstate__', because deepcopy() and pickle.load()
test for these on the instance using getattr() and treat the resulting
AttributeError as a signal that the object doesn't implement these custom
hooks. If we don't do that, we enter an infinite recursion as we attempt
to look up the missing dunder methods in the 'rawDict' dictionary,
because 'rawDict' is set inside __init__, but __init__ is not invoked
while unpickling (only __new__ is); thus self.rawDict is also missing
and __getattr__ is invoked with argument 'rawDict' again and again until
it crashes with RecursionError. Phew.

Fixes https://github.com/fonttools/fonttools/pull/1488
2019-02-06 01:05:11 +01:00
justvanrossum
612992f266 fixing #1426 2019-01-02 17:29:48 +01:00
ReadRoberts
0586c06199 [varLib subset CFF2] Set PrivateDict nominal and default WidthX to None
@bedhad
Address issues raised in #1403

I do think setting the dummy CFF2 PrivateDict nominalWidthX and defaultWidthX to None, which leads to the charstring.width also being None,  is a good idea. I originally set them to 0, which produces a charstring width of 0, in order to avoid problems with logic that assumes that the field is good for math. However, I now think that it is better to find errors around charstring type assumptions earlier than later.

 "drop_hints()" is actually not wrong - I did look at this when making the changes. For CFF2 charstrings, self.width is always equal to self.private.defaultWidthX, so the width is never inserted. This is because in psCharstrings.py::T2WidthExtractor.popallWidth(), the test "evenOdd ^ (len(args) % 2)" is alway False.  Left to myself, I would not change this code. If the CFF2 charstring is correct, there is not a problem. if the CFF2 charstring is not correct, then both in drop_hints() and in T2WidthExtractor.popallWidth(), the logic will stack dump. I did add asserts, but am not totally sure it is worth the extra calls.
2018-12-06 11:55:48 -08:00
Behdad Esfahbod
93633a85ef [CFF] Move variations-specific CFF code to varLib.cff module 2018-12-04 19:22:02 -08:00
ReadRoberts
1f2600ff65 [cff2] Add subset.cff functions for CFF/CFF2 class:
desubroutinize
remove_hints
remove_unused_subroutines

Fix issue in cff2mergePen.py because of  removing CFFS2Subrs class in prior commit.
2018-12-04 18:34:22 -08:00
ReadRoberts
61c213d0ff [cffLib] clean up isCFF2 in psCharStrings
Removed check_program functions. Supporting these requires knowledge of CFF vs CFF2 state, whci is leads to wide-spread diffuse changes. Also, not needed - the endchar/return opcodes are removed when compiling for CFF2.

Removed CFF2Subr class. This was used for CFF2 CharStrings, and allowed avoiding referencing the width fields. I worked around this by providing dummy values for the Private.nominalWidthX and defaultWidthX.

Added a public method PrivateDict.in_cff2.
2018-12-04 15:31:55 -08:00
Behdad Esfahbod
31019eac8e [CFF] Whitespace 2018-11-30 21:46:16 -05:00
ReadRoberts
ad8130e1a4 [varlib] Remove path compatiblization logic from CFF2CharStringMergePen
Agreed that paths glyphs form source fonts shoudl be fully compatible before varLib.build is called.

Updated test files
2018-11-29 15:07:08 -08:00
ReadRoberts
c5def97cd8 varLib. replace slower pointsDiffer() with models.AllEqual() 2018-11-19 17:38:52 -08: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
9626cfe15b varLib. Add support for building CFF2 variable font with a call to varLib.build().
Add support functions for merging CFF tables into a CFF2 table.
2018-11-12 11:37:47 -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
ReadRoberts
c239d1a03d
[cffLib] Fix bug in cffLib.py.CFFFontSet.convertCFFToCFF2() that broke converting name-keyed fonts.
Also clean up setting FontDict to support CFF2.
2018-06-11 12:09:00 +01:00
ReadRoberts
528bc8ff17
[cffLib] Use std operator delattr() instead of exec ("del ...") 2018-06-11 12:09:00 +01:00
ReadRoberts
942a7610fd
[cffLib] Fix bugs in converting CFF to CFF2 when the font has an FDArray.
The FontDict as well as the PrivateDict needs to have fields removed when these are deprecated in CFF2.
2018-06-11 12:09:00 +01:00
ReadRoberts
21bbb15cd0
[cffLib] Fix bugs in compiling a CFF2 font with an FDArray.
A FontDict in CFF2 is permitted only a subset of the fields supported by CFF 1.0.
2018-06-11 12:09:00 +01:00
derwind
66be456e62 [cffLib] restore try... finally... block 2018-02-23 02:22:57 +09:00
derwind
e5985ab63e [cffLib] reimplement SimpleConverter which is ready for lazy-loads and now all Converters are derived from it. 2018-02-23 02:01:35 +09:00
derwind
b9eb1b235f [cffLib] another implementation: prevent *Converter.read from changing file positions 2018-02-23 01:03:37 +09:00
derwind
91fc3c5c41 [cffLib] prevent *Converter.read from changing file positions 2018-02-22 22:46:46 +09:00
derwind
d0b4c4b360 [cffLib] save file position against lazy-load of charset 2018-02-22 02:00:09 +09:00