159 Commits

Author SHA1 Message Date
Cosimo Lupo
2c9eea33ee [feaLib.builder] rename 'id' -> 'id_' to avoid shadowing id() built-in function 2017-02-26 10:48:54 +08:00
Cosimo Lupo
1958334158 [feaLib.builder] sort markFilterSets_ items by id to make output deterministic
The items() of self.markFilterSets_ dictionary are not guaranteed to be always
ordered the same (may vary across python implementations or on subsequent runs).
To ensure deterministic order of Coverage subtables in MarkGlyphSetsDef tables,
we sort the mark sets by the order in which 'UseMarkFilteringSet' statements appear
in the feature file.
2017-02-26 10:48:54 +08:00
Cosimo Lupo
a9e0165b93 [feaLib.builder] ignore duplicates in classes used as MarkFilteringSet and MarkAttachmentType
Glyph classes from feaLib parser are tuples of strings, with an order and possibly containing duplicates.
However when building MarkGlyphSetsDef or MarkAttachClassDef we are only interested in the *set* of glyphs they contain, i.e. the unordered collection of unique glyph names.

Also, note how in the tests for otlLib.builder.buildMarkGlyphSetsDef, the input is given as set literals, not tuples:
https://github.com/fonttools/fonttools/blob/78ad48e/Tests/otlLib/builder_test.py#L633
2017-02-26 10:48:54 +08:00
Sascha Brawer
a2e7d96cf4 [feaLib] Merge SinglePos chain targets
Fixes https://github.com/fonttools/fonttools/issues/514.
2017-02-17 12:49:12 +01:00
Sascha Brawer
7c67e4a63d [feaLib] Compile zero values to different formats based on context
If a zero value appears in a SinglePos statement, feaLib continues to
produce ValueRecords of format 0. But if a zero value appears in a
PairPos statement inside a horizontal compilation context, feaLib now
produces ValueRecords of format 4. Likewise, if a zero value appears
in a PairPos statement inside a vertical compilation context, feaLib
now produces ValueRecords of format 8.

The OpenType Feature Syntax specification is completely silent about this,
but the new behavior matches that of makeotf.

https://github.com/fonttools/fonttools/issues/633
2017-02-16 15:37:40 +01:00
Sascha Brawer
706858646a Preserve ordering of glyph alternates when round-tripping through TTX
Also fixes a bug where glyph alternates in MTI feature files were
wrongly sorted by glyph name. After this change, the output is using
the same ordering as in the input MTI feature file.

Fixes https://github.com/fonttools/fonttools/issues/833.
2017-02-11 17:08:56 +01:00
Sascha Brawer
b31ed09421 Support glyph names with dashes
The OpenType Feature File Syntax has been changed to support dashes:
https://github.com/adobe-type-tools/afdko/issues/152

Resolves https://github.com/fonttools/fonttools/issues/559.
Needed for https://github.com/googlei18n/fontmake/issues/249.
2017-02-11 15:57:17 +01:00
Cosimo Lupo
6bacc3e6f8
[feaLib.builder] use hex istead of float for GDEF.Version to avoid fixedToFloat warning 2017-01-02 13:08:36 +01:00
moyogo
004a5b7361 feaLib: hhea tableVersion = 0x00010000 2016-10-18 18:18:09 +02:00
moyogo
f55c60c4df feaLib: add vhea table 2016-10-18 18:18:09 +02:00
moyogo
62894667f6 feaLib: fix code to use hex version instead of float 2016-09-29 20:43:50 +01:00
James Godfrey-Kittle
5c723ebfb0 [feaLib] Don't assume feature has lookups in DFLT
It's possible for all of a feature's lookups to be in specific script
and/or language systems, so this code could crash.
2016-06-22 16:19:45 -07:00
James Godfrey-Kittle
e2186dec53 [feaLib] Don't set language when script is unset
Before, if someone tried to set the language before setting the script
a None/language language system would be created (with actual tag
"None" stored in the feature table). This defaults to tag DFLT and
fails when a non-dflt language is set for DFLT, since that's illegal.
2016-06-22 11:29:42 -07:00
James Godfrey-Kittle
d1af1cfd4a [feaLib] Fix exclude_dflt handling
This is to fix what I think was a misunderstanding of the exclude_dflt
keyword (and the implicit include_dflt option active by default).

Rather than including the following lookups in the default language
systems, I think it is used to include the lookups specific to default
language systems in the system defined by the current language
statement. Thus instead of registering a lookup in all default
systems when include_dflt is true, we should exclude the lookups
registered with default systems from the current system when
include_dflt is false.
2016-06-21 16:39:27 -07:00
moyogo
17c8e582d0 [feaLib] glyph class as list and tuple instead of set and frozenset 2016-04-25 22:36:56 +01:00
Khaled Hosny
cdda278bd4 Use ttLib.newTable when possible
I learnt about it from [1] and seems like a nice thing to use.

1. https://github.com/behdad/fonttools/pull/586#issuecomment-213285350
2016-04-23 02:00:24 +02:00
Sascha Brawer
967cf8bb15 Sort feature records by feature tag
Resolves https://github.com/behdad/fonttools/issues/568
2016-04-12 13:53:25 +02:00
Khaled Hosny
5ceaa43d27 [feaLib] Support hhea table 2016-04-09 18:02:40 +02:00
Behdad Esfahbod
2a0359af4d Always import * from py23
Since py23 modifies some essential builtins, it's safe to import
everything all the time.  At least, that's how it was designed.
It's a bug if importing * breaks some code.
2016-04-06 18:15:43 -07:00
Khaled Hosny
0a1f323835 [feaLib] Support OS/2 table 2016-03-23 15:42:00 +04:00
Cosimo Lupo
9e8113718b [feaLib.builder] decode features string using tounicode before passing it to StringIO (for python2) 2016-03-21 19:39:07 +00:00
Cosimo Lupo
06b9a808ad [feaLib.builder] make addOpenTypeFeatures take only one 'featurefile' argument; add addOpenTypeFeaturesFromString
'featurefile' can be either a path (string) or a file object, like in TTFont or XMLReader and XMLWriter constructors.

If a file object does not have a 'name' attribute, a default "<features>" name is
used and the current working directory is assumed as the root for relative includes.
2016-03-21 18:46:50 +00:00
Cosimo Lupo
83f074aac4 [feaLib] use shorter fea_path and fea_data kwargs in addOpenTypeFeatures
as discussed here: https://github.com/behdad/fonttools/pull/547/files#r56807232
2016-03-21 12:18:32 +00:00
Sascha Brawer
9ec04f0537 Merge pull request #547 from adrientetar/patch-2
feaLib: support string input
2016-03-20 09:09:06 -07:00
Khaled Hosny
1ac37d7d00 [feaLib] Support BASE table
Just the parts documented a currently implemented by Adobe’s
implementation.
2016-03-20 13:36:02 +04:00
Khaled Hosny
40be0e6f3a [feaLib] Support size feature 2016-03-19 21:55:24 +04:00
Khaled Hosny
9feaab13aa [feaLib] Support stylistic set featureNames
Does not handle featureNames for cvXX features, but it shouldn’t be hard
for someone to extend the code to support them if inclined to do so.
2016-03-18 14:08:00 +04:00
Adrien Tétar
5e64857b97 feaLib: support string input 2016-03-15 20:01:29 +01:00
Sascha Brawer
4680701b6e Merge pull request #545 from khaledhosny/fea-lookupflag
Fix handling of default lookupflag
2016-03-15 09:12:44 -07:00
Khaled Hosny
4e316cd337 [feaLib] Support name table 2016-03-15 17:49:02 +04:00
Khaled Hosny
8d1930a27a Fix handling of default lookupflag
According to the spec:
> The lookupflag attribute defaults to 0 at the start of a feature
> block.
>
> The lookupflag attribute stays the same until explicitly changed, until
> a lookup reference statement is encountered that changes it, until the
> script is changed, or until the end of the feature.

This is an attempt to fix this by resetting the lookupflag at the start
and end of feature/lookup blacks. I’m not sure if resetting it in lookup
blocks is correct (my reading of the spec suggests it is not), but one
needs to test this against makeotf and see how it behaves here.
2016-03-13 00:43:10 +04: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
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
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
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
Sascha Brawer
a1fa968576 [feaLib] Use a different approach to synthesizing feature aalt
Resolves https://github.com/behdad/fonttools/issues/502.
2016-02-03 17:38:38 +01:00
Sascha Brawer
edb1ed0fcc [feaLib] Synthesize alternate substitutions for feature aalt
After this change, feaLib synthesizes the same lookups as makeotf v2.0.90
for `feature aalt` in the example of section 8.a of the OpenType Feature
File specification.
2016-02-03 15:17:37 +01:00
Sascha Brawer
bf79ceb2f2 [feaLib] Disallow lookup blocks inside feature aalt
The new behavior matches how makeotf v2.0.90 interprets
the OpenType Feature File Specification.
2016-02-03 11:39:50 +01:00
Sascha Brawer
faeba0c0c0 [feaLib] Support lookups with mixed glyph/class-based kerning
Resolves https://github.com/behdad/fonttools/issues/456
2016-02-02 18:24:48 +01:00
Sascha Brawer
c64019b3c6 [otlLib] Move building of class-based PairPos sutables from feaLib to otlLib 2016-02-02 15:17:01 +01:00
Sascha Brawer
f9e859c213 [otlLib] Move helper for building ClassDef tables from feaLib to otlLib 2016-02-02 10:48:47 +01:00