113 Commits

Author SHA1 Message Date
Behdad Esfahbod
bcd637bd1a [ttGlyphSet-cff] Remove rounding 2022-08-27 12:20:15 -06:00
Behdad Esfahbod
a949380b4a [psCharStrings] Internal var rename 2022-08-26 21:23:04 -06:00
Behdad Esfahbod
a7cda37fbb [ttVarGlyphSet] Support CFF 2022-08-26 20:52:18 -06:00
Skef Iterum
520ee0236d Handle implicit CFF2 closePath within T2OutlineExtractor 2022-04-14 07:19:44 -07:00
Just van Rossum
169731c7f5
[CFF/T2] Ensure that pen.closePath() gets called for CFF2 charstrings (#2577)
* [CFF/T2] Make sure to call pen.closePath() at the end of a CFF2/T2 charstring. Fixes #2455

* Add test case to verify pen.closePath() behavior
2022-04-09 14:50:59 +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
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
b69052de47 [misc.psCharStrings] Use inheritance to avoid repeated code in initializer 2020-05-07 21:21:40 +01:00
schriftgestalt
a0f39128d4 remove unused variable 2020-03-12 13:46:42 +01:00
Cosimo Lupo
86793f2617
psCharStrings: use floatToFixedToStr and strToFixedToFloat in T2CharString.toXML and fromXML
Also, toXML signature must contain ttFont=None keyword argument, like
the rest of toXML methods elsewhere.
2019-10-08 13:40:03 +01:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01: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
Cosimo Lupo
1fd11a3a0a psCharStrings: replace sys.stderr.write with log.warning 2019-03-12 11:43:10 +00:00
Just van Rossum
176f2e8244
[cffLib] Fix for #1451 (#1456)
* a charstring is not guaranteed to end in an operator, so the final bytecodes 11 and 14 can be part of an encoded numeric value; so remove 'return' or 'endchar' at the program level instead of bytescode
* move non-CFF2 test+error to elif clause of earlier isCFF2 test
Fixes the remaining issue from #1451
2019-01-17 16:01:15 +01:00
Cosimo Lupo
1702536150
psCharStrings: only assert no extra args on stack upon compile, not in toXML
Fixes #1451
2019-01-17 11:59:51 +00:00
Rasmus Andersson
4208683c3d fix 2SP -> TAB indentation 2019-01-05 11:18:45 -08:00
Rasmus Andersson
4c72b8f781 Change precision to 8 digits to match AFDKO 2019-01-05 11:06:59 -08:00
Rasmus Andersson
49609c8394 fixes incorrect reduction of input list 2019-01-04 15:58:59 -08:00
Rasmus Andersson
768f8ec171 Fixes bug in misc.psCharStrings.encodeFloat and adds test 2019-01-04 15:48:14 -08:00
Behdad Esfahbod
03ad219493
Merge pull request #1402 from fonttools/clean-cff2vf-2
cff2 vf fixes. Make calc_bounds work, fix subsetting bug.
2018-12-11 20:31:11 -05:00
ReadRoberts
3a04a73b0c [cff2 varlib subset] Clean up syntax
x != None -> x is not None.
2018-12-11 17:07:51 -08:00
ReadRoberts
ebc1b0b779 [cff2 varlib subset] Add message to assert for when a CFF2 charstring has an initial width. 2018-12-10 10:44:59 -08: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
ReadRoberts
c13855bdd6 cff2 vf fixes. Make calc_bounds work, fix subsetting bug.
Fixed psCharstrings so that calc_bounds will run. I would guess no-one has tried to use a BoundsPen on a CFF2 VF before - thanks to Chris Chapman. It now returns a result only for the default instance.

Fixed bug in subsetting: removed assert that a Subr is not empty after subsetting or de-hinting. CFF2 Charstrings do not have terminal "return' op.
2018-12-05 15:50:10 -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
85bc8fec07 [CFF] Remove unused code 2018-11-29 13:45:52 -05:00
ReadRoberts
6cb84deccf varLib. Add support for building CFF2 variable font with a call to varLib.build().
Fix bug in psCharStrings, to allow the CFF2Subr calls draw function to work
2018-11-20 12:20:46 -08:00
ReadRoberts
617b8c6396 [varLib.mutator] Interpolating CFF2 tables. Make more fixes per recommendations
varStore.py. Commit the correct function references.
psCharstrings.py. Add decompiler class specifically for flattening subroutinized charstrings.
mutator.py. Flatten the subroutinized charstrings, delete the Subrs.
TestCFF2VF.otf, Updated to version with subroutinization. Updated expected ttx output.
2018-11-19 20:08:00 -08:00
Behdad Esfahbod
5856740486 Improve error message 2018-11-15 01:26:57 -05:00
Miguel Sousa
8d7774a3e8 [pscharstrings] Optimize the charstring's bytecode
by encoding as integers all float values that have no decimal portion.

This optimization is expected to reduce the file size of CFF2 fonts that have intermediate masters.

Related to https://github.com/adobe-type-tools/afdko/issues/444

Many thanks to @cjchapman for the help on the fixed point math
2018-06-29 09:54:00 -07:00
Cosimo Lupo
d570fc038a
use otRound when rounding visual coordinates or deltas
So we now round towards +Infinity in:

- floatToFixed (which fully examplify that quotes from OT spec)
- psCharStrings: when packing floats as fixed 16.16
- t2CharStringPen: when rounding coordinates and advance widths
- subset: when rounding advance widths to compute average
- TupleVariation: rounding gvar deltas
- _g_l_y_f: when rounding coordinates: both in GlyphComponent.{x,y}
  and for GlyphCoordinates.toInt()
- _h_m_t_x: for rounding horiz/vert metrics
- varLib: rounding horiz metrics and deltas
2018-06-14 17:40:11 +01:00
Behdad Esfahbod
4fec016862 [cff] Fix calcBound when seac-like components happen in endchar
I'm also unimpressed by the copy-pasted bounds logic in hhea and vhea,
and the fact that that's coded in there instead of calling a function
on CFF / glyf tables respectively.
2018-01-26 17:41:53 -08:00
ReadRoberts
508e0e3770 [psCharstring] Simpler version of test for CFF2Charstring vs T2Charstring. 2017-11-05 19:36:41 -08:00
ReadRoberts
4d8f1546d2 [psCharstrings] Whoops. Debug code that escaped review. 2017-11-05 19:34:17 -08:00
ReadRoberts
83379be568 CFF2 Subr items can have values on the stack after the last operator. These were not getting written to XML. Added new class CFFSubr so that we can make an assertion error in this case if the item is not a CFF2 Subr, and otherwise write the last values on the stack to the XML file 2017-11-02 11:36:10 -07:00
ReadRoberts
8b02b5a294 Fixed issue with reading/writing PrivateDict BlueValues to ttx file. To date, BlueValue arguments have been written as absolute coordinate values, reflecting the history of the CFF ttx table format. However, Behdad Esfahbod pointed out that it is not always possible to roundtrip between the absolute values in the ttx file and the CFF2 default font value and the delta list. This update changes the ttx format so that in PrivateDict BlueValues, the default font values are written as absolute coordinates, preserving continuity with how CFF tables are written, but the region values are written as the deltas from the VariationStore delta list.
This also fixes fonttools/fonttools/issues/1030.

Although the roundtrip is generally possible when a VariationStore is built from source font data using the Superpolator model, it is possible to  build  region definitions that do not follow this model. Behdad cited the Skia "Q" example, where the tail of the Q is affected by two regions defined as:
min=0 peak=0.5 max=0.51 delta=+10
min=0.49 peak=0.5 max=0.51 delta=-10
2017-11-02 11:31:47 -07:00
Cosimo Lupo
28bb992c1f replace int(round(...)) with round(...)
We don't need to cast to int when using the round function from py23,
as this is a backport of python3's built-in round and thus it returns
an int when called with a single argument.
2017-10-22 12:03:52 +01:00
Masaya Nakamura
3708f2c8d3 Don't cache charString bounds
https://github.com/fonttools/fonttools/pull/970#discussion_r117903692
2017-08-01 10:54:47 +09:00
Masaya Nakamura
a68bfc2458 [psCharStrings] Add recalcBounds() to T2CharString 2017-08-01 10:51:47 +09:00
Cosimo Lupo
72baa5a7d5 [cffLib/psCharStrings] remove cffCtx, pass down isCFF2
* Removed `CFFContext`
* Added `isCFF2` argument to CFFFontSet.decompile/compile, used from
  respective ttLib classes
* Index classes get a `isCFF2` argument in constructor (used for
  decompiling); must be True/False if `file` argument is not None;
  it is stored as self._isCFF2 to support lazy loading
* Removed `TopDictData` class; reuse same `TopDictIndexCompiler` for
  both CFF and CFF2
* `CFFWriter` and all `*Compiler` classes get an `isCFF2` argument;
  defaults to the parent compiler's `isCFF2` attribute
* Removed `size` argument from `produceItem` method as unused and
  useless (`len(data)` is the same)
* psCharStrings: removed useless ByteCodeBase class
* A reference to the TopDict's VarStoreData is passed down to all
  the FontDicts' PrivateDict, so it can be used to get the number of
  regions while decompiling blend and vsindex operators

See dicussion:
https://github.com/fonttools/fonttools/pull/968#issuecomment-309920007
2017-07-19 18:18:58 +01:00
Miguel Sousa
dbf78fe930 [psCharStrings] Fix assert 2017-07-12 22:50:06 -07:00
ReadRoberts
386f16a233 Fix formatting for init function. 2017-06-20 16:23:52 -07:00
ReadRoberts
38cde93a1c psCharStrings.py. Fix bug: allow T1 charstrings to not have private attribute. 2017-06-20 16:23:52 -07:00
ReadRoberts
7acfe1f6a8 Fix bug in changing class API’s while doing work to remove global state. Needed to make ‘private’ argument to SimpleT2Decompiler __init__() be optional. It is not needed by CFF decompilation. 2017-06-20 16:23:52 -07:00
ReadRoberts
af23a781e4 Removed global state from cffLib.py; introduced instance-specific context class instead. Also deprecated maxstack operator, per OpenType spec update 1.8.1, as this simplified some of the context passing logic. Still not thoroughly tested; convertCFFToCFF2() function has not yet been updated to work with new logic. 2017-06-20 16:23:52 -07:00
ReadRoberts
1c53437e39 Folded CFF2 classes into CFF classes. Removed:
TopDict2Decompiler
PrivateDict2Decompiler
PrivateDict2Compiler
Working towards using one set of classes for both CFF2 and CFF data.
2017-06-20 16:23:52 -07:00
ReadRoberts
c33ae5c96a Folded CFF2 classes into CFF classes. Removed:
SimpleCFF2DEcompiler
CFF2CharString
GlobalSubrsIndex2
SubrsIndex2
CharstringIndex2
Working towards using one set of classes for both CFF2 and CFF data.
2017-06-20 16:23:52 -07:00
ReadRoberts
5fb2688567 psCharstring.py. Added CFF2 specific operators to t2Operators list, removed cff2Operators list. Working towards using one set of classes for both CFF2 and CFF data. 2017-06-20 16:23:52 -07:00
ReadRoberts
88e72e2c56 psCharstrings.py. Fold CFF2CharString() logic into T2Charstring(). Working towards using one set of classes for both CFF2 and CFF data. 2017-06-20 16:23:52 -07:00