2567 Commits

Author SHA1 Message Date
Behdad Esfahbod
6b46d8e553 [otBase] Move code around
Part of fixing https://github.com/behdad/fonttools/issues/537
2016-03-12 20:42:05 -08:00
Behdad Esfahbod
4b94fd55cb Simplify overflow handling code
The code that is being removed is untested and does not seem to make
fixing an overflow any easier.  The fixer code just needs to know
which subtable caused the overflow and does not care about the item
within.  As such, no point in trying to find a "right" item.

In fact, leaving item as is, is more useful in debugging overflows
as it reflects which item's offset actually overflowed.

Part of fixing https://github.com/behdad/fonttools/issues/537
2016-03-12 20:11:34 -08:00
Behdad Esfahbod
c1080d9796 Implement splitting PairPosFormat2 in case of overflow
Part of fixing https://github.com/behdad/fonttools/issues/537
2016-03-12 18:17:37 -08:00
Behdad Esfahbod
7319cd0afc Minor 2016-03-12 02:21:07 -08:00
Cosimo Lupo
8bf333facb Merge pull request #544 from anthrotype/ttProgram-eq
test for NotImplemented in __ne__; add __eq__ and __ne__ to ttProgram.Program
2016-03-11 16:22:59 +00:00
Cosimo Lupo
d82a31dd57 return NotImplemented from __ne__ if __eq__ returns NotImplemented
otherwise `not NotImplemented` (always False) is returned from __ne__ when `type(self) != type(other)`, leading to illogic results like:

>>> from fontTools.ttLib.tables.DefaultTable import DefaultTable
>>> t = DefaultTable('test')
>>> t == 0
False
>>> t != 0
False

The latter of course should return True.
2016-03-11 15:10:50 +00:00
Cosimo Lupo
d4b9a2bec3 [ttGlyphPen_test] ttProgram has __eq__ now, remove unnecessary assignments
previously assertEqual would fail, despite the `program` attributes where both empty, as the object have different id(). The Program.__eq__ method now compares self.__dict__ == other.__dict__, hence the test pass.
2016-03-11 15:10:50 +00:00
Cosimo Lupo
35c46aa0e2 [ttProgram] add __eq__ and __ne__ methods to Program class 2016-03-11 15:10:50 +00:00
Cosimo Lupo
bc51241ca9 Merge pull request #542 from anthrotype/haveInstructions
[ttGlyphPen] only add empty ttProgram to simple glyphs, not to composites
2016-03-11 11:23:52 +00:00
Cosimo Lupo
9b83c377c2 [ttGlyphPen] only add empty ttProgram to simple glyphs, not to composites
Unlike simple glyphs (with contours) which must always have `instructionLength`, the field is optional in composite glyphs and depends on whether `WE_HAVE_INSTR` flag is set:
https://www.microsoft.com/typography/otspec/glyf.htm

In the previous code, the TTGlyphPen was adding an empty `program` attribute to any new glyph, including composite glyphs. It should only do it for simple glyphs.

For example, if you take Roboto-Regular.ttf from here:
https://github.com/google/roboto/releases/tag/v2.129

The font (unhinted) was compiled using the ttGlyphPen. It has 1434 composite glyphs. For each of them, a USHORT value for the number of instructions (0) is written, so the binary ttf is 2.868 KB greater than
what it should be.
2016-03-11 10:53:41 +00:00
Behdad Esfahbod
b01c41bcea [Snippets] Add symfont.py, for symbolic font statistics analysis 2016-03-10 06:13:18 -08:00
Cosimo Lupo
87d13888ce [ttGlyphPen] check last point in qCurveTo is not None
otherwise, if points[-1] == 0, the on-curve point won't be added.
2016-03-09 17:58:48 +00:00
Sascha Brawer
c3e2d37299 Snippet for applying a feature file to a font
It would be nice to also handle MTI feature files, and to process
TTX in addition to binary fonts, and and and... but it's a start.
https://github.com/behdad/fonttools/issues/527
2016-03-09 17:19:10 +01:00
Behdad Esfahbod
5794f9f6a2 Merge pull request #538 from jamesgk/master
[TTGlyphPen] Add component flags argument
2016-03-07 17:42:28 -08:00
James Godfrey-Kittle
fd5b6de3ba [TTGlyphPen] Add component flags argument 2016-03-07 14:48:46 -08:00
Behdad Esfahbod
a0d6ab6a07 [ttLib] Fix bug in OTLOffsetOverflowError generation
Part of fixing https://github.com/behdad/fonttools/issues/537

Now on to fixing the actualy overflow.
2016-03-04 06:06:33 -08:00
Behdad Esfahbod
bf28ca10d7 [EBLC] Decompile and release copies of data early
Apparently string slices are not as smart as I was hoping for.
Slicing a looong (say, 1MB) string and holding onto it is not a
good idea if done thousands of times.  So, do fewer slicings and
decompile subtables immediately instead of holding onto data.

This makes me want to rethink the kind of data structures we use
for lazy processing.

Fixes https://github.com/behdad/fonttools/issues/317
2016-03-02 11:31:20 +09:00
Behdad Esfahbod
7aed5c3ca9 GlyphCoordinates: add test for non-integer transform() 2016-02-24 13:01:09 +09:00
Behdad Esfahbod
87b1c0f403 GlyphCoordinates: Fix translating by non-integer 2016-02-24 12:58:32 +09:00
Behdad Esfahbod
d0552c994c GlyphCoordinates: add failing test for translating non-integer 2016-02-24 12:57:18 +09:00
Behdad Esfahbod
26621d548f GlyphCoordinates: return early from _checkFloat(), if already float 2016-02-24 12:52:38 +09:00
Behdad Esfahbod
cfd46b43f1 Merge pull request #526 from jamesgk/master
[TTGlyphPen] Don't cast values to int
2016-02-17 13:53:31 +07:00
James Godfrey-Kittle
f02e771527 [TTGlyphPen] Don't cast values to int
The glyf table will handle rounding when compiling, so this is
unnecessary.
2016-02-16 17:17:14 -08:00
Sascha Brawer
655fb4a856 Skip names whose offset+length points outside the string table
Resolves https://github.com/behdad/fonttools/issues/525
2016-02-16 14:39:44 +01:00
Cosimo Lupo
83e91d3af1 Merge pull request #521 from jamesgk/master
Replace one last call to debug() in mtiLib
2016-02-11 07:55:59 +00:00
James Godfrey-Kittle
c4dd050d8d Replace one last call to debug() in mtiLib
I think this was mistakenly left out of
b62f5509524a49101ab6f211f1c3b63458f52f5e
2016-02-10 14:18:38 -08:00
Behdad Esfahbod
d87d6aa39e [ot] Make sure GSUB/GPOS top arrays don't share bytes
Fixes https://github.com/behdad/fonttools/issues/518
Fixes https://github.com/behdad/fonttools/issues/372
2016-02-10 18:00:48 +07:00
Behdad Esfahbod
1085d8973d [ot] Minor 2016-02-10 17:28:56 +07:00
Behdad Esfahbod
0baeb5921b [otBase] Shuffle 2016-02-10 17:26:53 +07:00
Behdad Esfahbod
f65fc6f872 [otBase] Simplify _doneWriting() slightly
Should have NO functional change.
2016-02-10 17:03:46 +07:00
Behdad Esfahbod
74e629e600 [subset] Retain GSUB ScriptRecords, even if they are empty
This slightly bloats subset fonts, but fixes:
https://bugzilla.mozilla.org/show_bug.cgi?id=1080739#c15
https://github.com/behdad/fonttools/issues/518

At some point we might want to do something smarter based
on Unicode script of retained characters.
2016-02-10 16:22:24 +07:00
Sascha Brawer
809698611e [feaLib] Fix SequenceIndex in ChainContextPos
In the long term, we might want to make a different low-level API
for building ChainContextPos lookups; for now, this should fix the
current bug with SequenceIndex.

Resolves https://github.com/behdad/fonttools/issues/517.
2016-02-09 15:38:18 +01:00
Sascha Brawer
873f3570af [feaLib] Emit ChainContextPos before dependent SinglePos
There should be no semantic difference from this change,
since dependent lookups (the chain targets) are never directly
invoked by a feature. But the output of feaLib becomes more
similar to the output of makeotf, which helps debugging.
2016-02-09 09:25:54 +01:00
Sascha Brawer
5ab852277d [feaLib] Emit context-free contextual chains to SinglePos
Before this change, we had only emitted a SinglePos (GPOS type 1) lookup
for a statement like `pos A' B' 20`; after this change, we always emit a
chain rule even if there is no context. There is a semantic difference if
the rule is preceded by a `ignore pos` statement. Omitting context-free
contextual chains was actually not a (premature) optimization, but an
artifact that came from the representation of glyph patterns.

https://github.com/behdad/fonttools/issues/516
2016-02-09 09:00:06 +01:00
Sascha Brawer
bd6bea0f7f [feaLib] Allow non-disjoint markClasses
After this change, feaLib generates the exact same output as makeotf
for the test case in `bug453.fea`. Before this change, feaLib had
rejected the input as malformed.

Our new behavior is in blatant violation of the OpenType Feature File
Syntax specification, which writes: "NOTE! If a GDEF table is not
explicitly defined in the feature file, [...] all mark glyph classes
must be disjoint". However:

1. makeotf does not enforce this constraint;
2. existing feature files happily define non-disjoint markClasses;
3. existing tools such as the Glyphs font editor generate feature files
   with non-disjoint markClasses;
4. it is not obvious what the intention of this constraint would be.

Therefore, fewLib now follows the makeotf implementation, intentionally
ignoring what is mandated by the specification. I've proposed a spec change
at https://github.com/adobe-type-tools/afdko/issues/106.

Resolves https://github.com/behdad/fonttools/issues/453.
2016-02-08 10:27:31 +01:00
Cosimo Lupo
464057a4db [tox.ini] set *Test pattern for pytest's python_classes
The glob pattern determines which classes are considered for test collection by pytest.
We already follow this pattern for the unittest.TestCase derived subclasses
(which are collected regardless of this option).
2016-02-07 17:42:55 +00:00
Cosimo Lupo
3d68c07830 [.appveyor.yml] no need to upload sdist to 'artifacts'
this should save us a few extra seconds
2016-02-07 02:17:20 +00:00
Cosimo Lupo
ecf721fa7b Merge pull request #515 from anthrotype/pytest
use pytest to collect and run unittests and doctests
2016-02-07 02:12:05 +00:00
Cosimo Lupo
16f29ffd6d [loggingTools] use ellipsis for doctests when printing time
appveyor can be *very* slow

https://ci.appveyor.com/project/anthrotype/fonttools/build/job/pdrl7o5ggan7qlej
2016-02-07 01:19:45 +00:00
Cosimo Lupo
e30ad7e8a7 [woff2_test] import sstruct from fontTool.misc
oops.
2016-02-07 01:19:45 +00:00
Cosimo Lupo
7c6744e639 [py23_test] pass os.environ copy instead of empty dict to avoid issue on Windows
Otherwise I get this:
Fatal Python error: Failed to initialize Windows random API (CryptoGen)

https://ci.appveyor.com/project/anthrotype/fonttools/build/job/qhf8d89or4d5hiyd

see: http://bugs.python.org/issue20614
2016-02-07 01:19:45 +00:00
Cosimo Lupo
4a783326b8 [py23_test] need to use os.pathsep as Windows uses ";", not ":" 2016-02-07 01:19:45 +00:00
Cosimo Lupo
4874264dd9 [py23_test] pass the sys.path as PYTHONPATH to python subprocess
Apparently I need to do that, or the child python process does not see fontTools in the path.

Another workaround woud be to ensure that fontTools is installed, at least in editable or develop mode (via `pip install -e .`). But the way we temporarily extend the PYTHONPATH in run-test.sh is less intrusive.
2016-02-07 01:19:45 +00:00
Cosimo Lupo
3495029726 [.travis/install.sh] pip install from dev-requirements.txt 2016-02-07 01:19:45 +00:00
Cosimo Lupo
93d9356439 [.appveyor.yml] use tox to run pytest in a virtual environment; remove extra scripts
It seems like Appveyor no longer needs the batch script to configure the MSVC compiler variables.
Also, since appveyor already comes with all the python versions we need, we don't need the install.ps1 script any more.

Brotli is now installed by tox from requirements.txt inside the test virtualenv.
2016-02-07 01:18:30 +00:00
Cosimo Lupo
627a54d76f [requirements.txt] install Brotli from v0.3.0 tagged release 2016-02-07 01:04:20 +00:00
Cosimo Lupo
258cb84c52 [dev-requirements.txt] add pytest and tox to dev-requirements.txt
In theory only pytest would be required for devs to run the tests locally, but we also use tox for setting up the test virtualenvs on the CI.
2016-02-07 01:04:20 +00:00
Cosimo Lupo
41dff8456e [run-test.sh] use pytest to collect tests
This way test discovery will work not only with the current unittest and doctest modules, but also with pytest's own kind of tests.

When run with no argument, the shell script will call the py.test command, which will scan the whole Lib/fontTools directory for all relevant tests.

If args are provided, tests are filtered if any of the substrings specified
match. The filtering works not only on the modules' file names (as the previous grep approach), but also on the names of the test functions, classes and methods. Pretty cool, huh?

We can still specify whether to run pytest with python -2 or -3 (provided pytest is installed on both Python versions).
And we don't need to print the python version any more as pytest does it for us.
Finally, there's no need to export PYTHONPATH -- pytest takes care of that too!
2016-02-07 01:03:39 +00:00
Cosimo Lupo
118045abf0 [tox.ini] tell pytest to only collect tests from *_test.py modules; set pytest 'minversion' to 2.8
the glob pattern will restricts the search only for pytest's kind of tests; it has no effect on methods of unittest.TestCase derived class, since pytest still uses unittest's own collection framework to collect those.

The 'minversion' is required to support some of the latest advanced features.
The current py.test is 2.8.7. You can update it with `pip install --upgrade pytest`.
2016-02-06 20:59:00 +00:00
Cosimo Lupo
568b4e9129 [tox.ini] use 'testpaths' to tell py.test where to look for tests
this to avoid picking up undesired tests by accident when running `py.test` command without specific dirs or files
2016-02-06 17:12:01 +00:00