1854 Commits

Author SHA1 Message Date
Behdad Esfahbod
c02ced3393 [otBase] Minor
Part of fixing https://github.com/behdad/fonttools/issues/537
2016-03-12 20:42:08 -08:00
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
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
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
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
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
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
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
Sascha Brawer
d03ce3c119 [feaLib] Add unit test for the ignore pos statement
There are no examples for `ignore pos` in the OpenType Feature File
Syntax specification, therefore using a made-up example for the test.
The output from feaLib is identical to what makeotf generates.

Resolves https://github.com/behdad/fonttools/issues/503.
2016-02-06 12:13:03 +01:00
Sascha Brawer
b5d1124f43 [feaLib] Handle the ignore pos statement
https://github.com/behdad/fonttools/issues/503
2016-02-06 11:14:27 +01:00
Sascha Brawer
4a23f8eb85 [feaLib] Add unit test with spec section 5.f.ii, example 4
This is another test case for the `ignore sub` statement.
After the recent changes to feaLib, the output is now identical
to the output generated by makeotf.

https://github.com/behdad/fonttools/issues/503
2016-02-05 15:55:53 +01:00
Sascha Brawer
ec9077a566 [feaLib] Merge SingleSubst chain targets
This makes the output of feaLib more compact, using a similar technique
as seems to be used by makeotf.

After this change, feaLib generates output that more similar to makeotf:

* For the test cases in `bug512.fea` and `bug463.fea`, feaLib now
  generates the exact same output as makeotf v2.0.90.

* For the test cases in `GSUB_6.fea`, it is hard to say because makeotf
  crashes on the test file; our test contains language constructs that
  are valid according to the spec, but didn't yet get implemented by makeotf.
  When commenting out those constructs, feaLib generates the exact same
  output as makeotf v2.0.90.

* For the test cases in `feature_aalt.fea`, the output of feaLib is now
  structually the same as the output of makeotf v2.0.90.  However, two
  lookups are in different order. feaLib's ordering reflects the order
  of statements in the compiled input source; no idea why makeotf would
  want to reverse the ordering. Since this ordering difference only
  affects the _targets_ of chain substitutions, there is no semantic
  difference.

Resolves https://github.com/behdad/fonttools/issues/512.
2016-02-05 15:12:07 +01:00
Sascha Brawer
1ddfe24338 [feaLib] Support multiple chain contexts after ignore sub
Although this construct is in violation of the `ignore sub` grammar
given by the current OpenType Feature File syntax specification,
the very same specification document illustrates (in example 3
of section 5.f.ii) the `ignore sub` statement with a comma-separated
list of backgrack/input/lookahead triples.

See https://github.com/adobe-type-tools/afdko/issues/105 for a request
to amend the OpenType Feature File syntax specification.

After this code change, feaLib can now parse testdata/spec5f_ii_3.fea;
the output is identical to what is generated by Adobe's makeotf tool.

https://github.com/behdad/fonttools/issues/503
2016-02-05 11:02:29 +01:00
Sascha Brawer
a862f70880 [feaLib] Add unit test for spec section 5.f.ii, example 2
Output is identical to makeotf.
2016-02-05 08:35:18 +01:00
Sascha Brawer
27e23f9a95 [feaLib] Emit context-free chains to single substitutions
Resolves https://github.com/behdad/fonttools/issues/509
2016-02-04 16:45:05 +01:00
Sascha Brawer
dba1d6666b [feaLib] Emit chains to LigatureSubst even without backtrack or lookahead
https://github.com/behdad/fonttools/issues/506
2016-02-04 15:31:29 +01:00
Sascha Brawer
ea4a4e34b3 [feaLib] Reverse lookup order for chained single substitutions
This makes feaLib's output more similar to output from makeotf.
Resolves https://github.com/behdad/fonttools/issues/507.
2016-02-04 15:07:47 +01:00
Sascha Brawer
3d6cf0d8e6 [feaLib] Reverse lookup order for chained multiple substitutions
https://github.com/behdad/fonttools/issues/507
2016-02-04 14:46:22 +01:00
Sascha Brawer
7574260bed [feaLib] Reverse lookup order for chained alternate substitutions
For this construct, makeotf throws an error: "Contextual alternate
rule not yet supported". If it had been implemented, we speculate
that the ordering would likely be the same as with other contextual
substitutions (the chain comes before, not after, the dependent lookup).

https://github.com/behdad/fonttools/issues/507
2016-02-04 14:34:45 +01:00
Sascha Brawer
e8a4b341f3 [feaLib] Reverse lookup order for chained ligature substitutions
https://github.com/behdad/fonttools/issues/507
2016-02-04 14:24:48 +01:00
Cosimo Lupo
f6b8445515 [subset] catch OptionError exception, print usage + error and throw exit code 2 2016-02-04 12:17:01 +00:00
Sascha Brawer
ab7b86005e [feaLib] Implement the ignore substitution statement
https://github.com/behdad/fonttools/issues/503
2016-02-04 11:39:03 +01:00
Sascha Brawer
aae350c84a [feaLib] Change semantics of script statement
Before this change, the `script` statement had inherited global
defaults. After this change, it overrides them. The new behavior
matches the behavior of makeotf v2.0.90.

Resolves https://github.com/behdad/fonttools/issues/505.

For the test case of https://github.com/behdad/fonttools/issues/501,
which was about an unrelated problem, feaLib now produces the exact
same output as makeotf v2.0.90.
2016-02-04 10:31:33 +01:00
Sascha Brawer
f9a236f54e [feaLib] Allow script and language statements in named lookup blocks
Although the specification writes the exact opposite, makeotf does
accept script and language statements inside named lookup blocks.
Since Glyphs.app (and possibly other tools, too) produce feature files
that make use of this syntax, enforcing the spec would break existing
files.

Resolves https://github.com/behdad/fonttools/issues/501.
2016-02-04 09:52:20 +01:00