In OT kern subtable header, the format is the high byte of 'coverage'
bit mask (bits 8-15), and the low byte (bits 0-7) is the actual coverage
bits.
In AAT kern, it's the opposite: the coverage flags are the high byte,
whereas the subtable format is the low byte.
Also adjusted the test data, and set coverage to 1 for OT kern subtable
(which means the usual horizontal kerning).
- When compiling kern subtables for version=1.0 kern tables (AAT)
the subtable header was written incorrectly: there is no version,
the length is a uint32 and there's an additional uint16 for
tupleIndex
- Use the 'coverage' low byte to select subtable "format", instead
of the 'version' field, only present in OT kern subtable header.
The getkern method was failing with AttributeError on 'unknown'
subtable formats, as their class only has 'format' instead of
'version' attribute. The 'version' attribute is renamed to
'format' also to avoid confusion, but the old one is kept for
backward compatiblity. In the only implemeted subtable class,
'format' becomes a class attribute rather than instance's
(it must always be 0).
- KernTable_format_0 now takes an 'apple=False' argument, used to
know the different headers and whether to read/write tupleIndex.
- minor pep8 whitespace and indentation fixes
- A new 'tupleIndex' attribute is written out to TTX for apple
kern subtables. Old ttx files which lack that attribute will
still be read (with a warning) and will default to tupleIndex=0
when recompiled or dumped with current fonttools.
Fixes#1089
Beyond composing ligatures, AAT finite-state transducers can also
execute insertion actions without rewriting existing glyphs. The
corresponding actions have almost the same structure as ligature
actions, so we can share a lot of the plumbing within fonttools.
This renaming is in preparation of a larger change to support `morx`
ables with insertions.
Before this change, we were emitting XML with numeric values for `morx`
coverage flags. Now, we emit XML that makes more sense to human readers.
XML files from previous versions of fonttools can still be parsed.
Since the AAT ligature subtable does not encode the number of ligature
glyphs, we need to infer this from the total structure length. We pass
this around by creating a custom sub-reader that only has the substruct
as its data. There might have been easier ways to accomplish this, but
we should anyway change the XML output for MorxSubtables to use custom
flag names, similar to what we're already doing for flags of morph actions.
Having a custom converter for MorxSubtables is in preparation for that
later XML format change.
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.
Before Python version 2.7.7, the struct.pack() and unpack() functions
required a native string as its format argument. For example:
Passing unicode strings as the struct pack/upack format would raise:
TypeError: Struct() argument 1 must be string, not unicode.
This error occurs when we use `from __future__ import unicode_literals`.
This problem was fixed in Python 2.7.7. Since then, struct now also
accepts unicode format strings.
Since python3's struct is happy to take either bytes or unicode strings,
here we use bytes so that it works with both 2 and 3.
Also see http://pythen-future.erg/stdlib_incompatibilities.html#struct-pack
Fixes https://github.com/fonttools/fonttools/issues/993
it might be deprecated or ignored in some rasterizers, but I don't
see why we should discard it, if it's present in the input font.
This also allows to set the flag, which may turn out to be useful
in some circumstances.
cf. https://github.com/googlei18n/fontmake/issues/253#issuecomment-335600887