445 Commits

Author SHA1 Message Date
Cosimo Lupo
160a9cb238
fix doctest calling configLogger causing flakiness of other tests
since we use pytest-randomly to randomize the test execution, depending on when
this specific test is executed, it may have the side effect of configuring
the global logging configuration, causing other tests that capture logging
messages to fail.

E.g. see https://travis-ci.org/fonttools/fonttools/jobs/545680550
2019-06-14 11:50:07 +01:00
Cosimo Lupo
1fc1d2f529
[loggingTools] remove unused backport of LastResortLogger
we are not in the business of logging.
2019-06-11 13:39:59 +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
80306037b7
arrayTools: calcIntBounds should use otRound, not round3
Somehow we forgot to replace round -> otRound in arrayTools.calcIntBounds.
This function is used by glyf table to compute the glyphs' bounding boxes.
We already use otRound (aka 'int(math.floor(v + .5))') to round glyph
coordinates upon compiling glyf table. So the use of python3's round
in calcIntBounds was producing inconsistent roundings between the glyph
coordinates and the glyph bbox (sometimes, i.e. only when the glyf table
contains float coordinates, e.g. after instantiating with varLib.mutator).
2019-04-04 12:38:54 +01:00
Miguel Sousa
ddff29cb5d Fix DeprecationWarning: invalid escape sequence 2019-04-01 14:04:14 -07:00
justvanrossum
20c93b9fdb use RecursionError, and provide an alias for RuntimeError for Py2 2019-03-17 18:18:10 +01:00
Cosimo Lupo
1fd11a3a0a psCharStrings: replace sys.stderr.write with log.warning 2019-03-12 11:43:10 +00:00
justvanrossum
d897a08fc8 more updated issue URLs 2019-03-06 16:52:35 +01:00
justvanrossum
723e7a1d3c updated inline github issue URLs 2019-03-06 16:01:28 +01:00
Cosimo Lupo
2150ef875f
py23: add backport for math.isfinite (python >= 3.2) 2019-01-22 15:42:54 +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
Just van Rossum
327b05d8c0
[designspaceLib] [t1Lib] [misc.macRes] fix some cases where pathlib.Path objects were not accepted (#1421)
* fix two cases where pathlib.Path objects were not accepted

* make macRes reader accept os.PathLike objects

* use __fspath__ explicitly to support os.PathLike paths

* use __fspath__ explicitly to support os.PathLike paths

* convert tmpdir to str

* only test pathlib.Path on Python 3.6 and up
2018-12-30 12:07:05 +01:00
Nikolaus Waxweiler
3b2bfcf29a Treat Mapping objects as dicts 2018-12-13 15:44:25 +00: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
f530e3e398
Merge pull request #1372 from fonttools/varLib-faster-featureVars
[varLib] Far faster featureVars
2018-11-15 14:59:48 -08:00
Behdad Esfahbod
5856740486 Improve error message 2018-11-15 01:26:57 -05:00
Behdad Esfahbod
f1a9c6c036 Move popCount() into new fontTools.misc.intTools 2018-11-10 15:16:52 -05:00
Behdad Esfahbod
7111b253b1 Move hashdict into new fontTools.misc.dictTools 2018-11-10 15:14:36 -05:00
Cosimo Lupo
1ac4d2a427
Revert "Merge pull request #1351 from anthrotype/transform-properties"
This reverts commit 70b0fbf9cfb3e2e1e2fc25fd75ddb71814cd62fb, reversing
changes made to 6a5a4c742219d0590f77d1a35163760e5c98a5a9.
2018-10-26 18:10:33 +01:00
Cosimo Lupo
a9f0c89585
transform: add getters for xScale, xyScale, yxScale, yScale, xOffset and yOffset
UFO images have a transformation matrix with those names.
This makes the Transform look more like a namedtuple, in that it can be accessed both by
index and by property name.
2018-10-26 17:10:40 +01:00
Cosimo Lupo
8081bf57fa
etree/plistlib/glifLib: using (default) single quotes in XML_DECLARATION
https://github.com/fonttools/fonttools/pull/1335#issuecomment-431118568
2018-10-18 19:49:52 +01:00
Cosimo Lupo
9557c6a229
fix deprecation warnings when using ABC from collections module 2018-10-18 18:12:43 +01:00
Cosimo Lupo
8ba98afb92
etree: remove 'XMLTreeBuilder' from __all__
only present in py27 elementtree:
6e57382464/Lib/xml/etree/ElementTree.py (L1676-L1677)
2018-10-18 15:40:32 +01:00
Cosimo Lupo
081b0fc090
keep fontTools.ufoLib.plistlib compatibility shim
the old readPlist, writePlist are only kept in fontTools.ufoLib.plistlib,
not in fontTools.misc.plistlib
2018-10-18 11:11:34 +01:00
Cosimo Lupo
176b5f763d
change 'import ufoLib' to 'import fontTools.ufoLib' 2018-10-17 17:43:28 +01:00
Cosimo Lupo
7ee7ccd568
move ufoLib.etree to fontTools.misc.etree
we can use this ElementTree-like XML API for ttx or designspaceLib, not
just ufoLib
2018-10-17 17:30:39 +01:00
Cosimo Lupo
e42bfd65f4
move ufoLib.plistlib to fontTools.misc.plistlib
As PLIST are not only UFOs (e.g. DesignSpace documents)
2018-10-17 17:29:34 +01:00
Cosimo Lupo
0245f2c55a
loggingTools: add msg=None argument to CapturingLogHandler.assertRegex
like all the rest of unittest.TestCase assertSomething
2018-09-28 19:10:50 +01:00
Cosimo Lupo
248ae41e9d
loggingTools: fix CapturingLogHandler to work with py37
we can't set the logger.level directly because in py37 the logger has a _cache
attribute and that needs to be invalidated by calling setLevel method.

also, I noticed we weren't restoring the original 'disabled' attribute value...

And we need to also set/restore the 'propagate' attribute.
2018-07-24 12:17:59 +01:00
Miguel Sousa
523c31dd0b Add context manager to XMLWriter
93103c08ca (r29633076)
2018-07-08 22:12:44 -07: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
d9d30c819a
loggingTools: move here the LastResortLogger from py23
and add a small test
2018-06-19 16:54:50 +01:00
Cosimo Lupo
e6a5db543d
py23: don't automatically set logging.lastResort handler on py27
To avoid the 'No handlers could be fonud' message, from now on, one should always
configure logging in one's scripts or applications.

logging.basicConfig, or fontTools.configLogger (with some predefined defaults
useful for fonttools scripts) can be used to quickly configure logging.
Read the python docs for more advanced logging usage.
2018-06-19 15:35:28 +01: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
Cosimo Lupo
585b87023f
fixedTools: add otRound to round floats to nearest int towards +Infinity
https://github.com/fonttools/fonttools/issues/1248
2018-06-14 17:15:47 +01:00
Cosimo Lupo
c4950ecc8b
py23: add 'zip' (alias to izip in py2) to __all__ 2018-06-12 17:29:10 +01:00
Cosimo Lupo
fbab1227ce
loggingTools: memoize 'log' property of LogMixin
the logger name is constant (based on the user class's name and module)
so we can cache it.

(this means the LogMixin will only work on regular dict-based classes,
not on 'slotted' classes. But that's ok
2018-06-07 11:40:33 +01:00