334 Commits

Author SHA1 Message Date
Khaled Hosny
f0e0954afc [feaLib] Micro optimization
Infer glyph classes only when we are going to use them.
2017-12-05 13:06:05 +02:00
Cosimo Lupo
4dfea00356 [feaLib] report error with multiple runs of marked ' glyphs
As Martin Hosken reported in https://github.com/fonttools/fonttools/pull/1096,
feaLib currently incorrectly handles the case where a marked input
glyph sequence in a contextual chaining sub/pos rule is split into
multiple runs, rather than being a single continuous run of ' marked
glyphs.

The consensus there was to raise a syntax error like makeotf instead of
second-guessing and silently fixing it like fontforge does.
2017-11-21 11:42:28 +01:00
Cosimo Lupo
fdab63f0b6 [feaLib.ast] add __str__ to all AST elements
which calls the asFea() method,
so one can e.g. print(doc.statements[0])
2017-11-16 15:40:52 +00:00
Cosimo Lupo
99aa8b0c66 [feaLib.parser] keep supporting (deprecated) glyphMap argument
so we don't break backward compatibility if user code has Parser(path, glyphMap=...)
2017-11-16 14:25:43 +00:00
Cosimo Lupo
e8535f2280 [feaLib.parser] make Parser accept glyphNames iterable...
... instead of a glyphMap dict.

The parser does not actually need a reverse glyph order mapping as
it is not interested in knowing the glyphID from the glyph name,
but only whether a glyph is in the font or not.

This makes it easier for client code (e.g. ufo2ft feature compiler)
to use the feaLib Parser, without having to first construct and pass
it a glyphMap argument.
2017-11-16 13:46:27 +00:00
Khaled Hosny
534326bd1d [feaLib] Fix writing back nested glyph classes
Before this change, the following glyph class:

  @Vowels = [@Vowels.lc @Vowels.uc y Y];

Would be written back as:

  @Vowels = [@Vowels.lc = [a e i o u]; @Vowels.uc = [A E I O U]; y Y];

Which is clearly invalid. It seems for GlyphClass.asFea() to work
correctly here we should be using GlyphClassName not GlyphClass
for the nested classes (similar to the code at the beginning of
parse_glyphclass_()).
2017-10-27 23:27:07 +03:00
Jens Kutilek
f36c7ec39f Make "unexpected character" exception ASCII-safe 2017-08-08 13:46:05 +02:00
Miguel Sousa
12b7c60a68 [feaLib] Cap nameID value to the maximum defined by OT spec
a9d260bfa2 (commitcomment-23115168)
2017-07-15 16:44:17 -07:00
Miguel Sousa
a9d260bfa2 [feaLib] Enable setting nameIDs greater than 255
Fixes #1003
2017-07-15 08:21:09 -07:00
Cosimo Lupo
12b90f073e [feaLib] don't de-duplicate lookups
keep original lookup order and preserve the feature file's semantics

Fixes https://github.com/fonttools/fonttools/issues/448
2017-05-30 11:45:03 +02:00
Khaled Hosny
0f1de0873f [feaLib] Unused class member
ClassPairPosSubtableBuilder.coverage_ is unused since
c64019b3c6b27a5b7f649171d87fd65762651f88.
2017-05-28 17:27:26 +02:00
Adrien Tétar
3e3ff0051e builder: throw when a mark is defined in multiple mark classes
(within the same lookup)

See #453.
2017-05-01 13:14:38 +02:00
Sascha Brawer
189c722626 [feaLib] Clean up syntax tree for FeatureNames
The syntax tree representation now reflects the syntax of feature files.
Before this change, FeatureNames did not have their own `ast.Block`,
which had made the code quite messy.
2017-03-10 02:48:32 +08:00
Sascha Brawer
bc0670f53f [feaLib] Simplify parser API by removing the ignore_comments option
https://github.com/fonttools/fonttools/pull/879#discussion_r104947968
https://github.com/fonttools/fonttools/issues/829
2017-03-09 22:17:58 +08:00
Sascha Brawer
04b1e8ada6 [feaLib] Recognize empty statements in all table blocks
Before this change, some table statements would allow empty statements
(just a semicolon) while others would not allow them. After this change,
we're more consistent.
2017-03-09 13:58:17 +01:00
Martin Hosken
5906b5358a Final changes to follow vagueries 2017-03-08 16:54:11 +00:00
Martin Hosken
2972d81d82 More pop8erry and try to minimise redundancy in the patch 2017-03-08 16:49:08 +00:00
Martin Hosken
c870cde47e Refactor to remove option in Lexer. Lexer always returns comments now 2017-03-08 16:29:55 +00:00
Martin Hosken
45a4a1f249 Add tests, rename _OMITs 2017-03-08 15:19:09 +00:00
Martin Hosken
90b57d2dec Fix bad colon 2017-03-08 14:15:34 +00:00
Martin Hosken
d5d4ea4ddc Tidy up space colon to colon in python statements 2017-03-08 14:05:00 +00:00
Martin Hosken
450d2b939e Add support for comments to parser 2017-03-08 13:50:06 +00:00
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
40474f1aab Distinguish value records format A from format B with zero values
Fixes https://github.com/fonttools/fonttools/issues/848.
2017-02-16 13:53:55 +01:00
Sascha Brawer
eac7ef89c0 [feaLib] Make nameid parsing more robust
We now correctly handle nameid statements with surrogate pairs and
old-style macOS-encoded names (provided that fonttools supports the
specified encoding).

Resolves https://github.com/fonttools/fonttools/issues/842.
2017-02-14 14:28:10 +01:00
Sascha Brawer
b22df7ff48 [feaLib]Escape nameid strings when writing feature files
https://github.com/fonttools/fonttools/issues/780
2017-02-14 11:02:12 +01:00
Miguel Sousa
75133fc4d1 [feaLib] Make include() work like makeotf 2017-02-13 08:42:03 +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
78ad48eaf3
Move all *_test.py modules and test data to external Tests/ folder 2017-01-16 09:14:12 +00:00
Cosimo Lupo
48c12bda63
[feaLib] add __main__.py so one can call fonttools feaLib
This is the same as Snippets/apply-feature-file.py

Fixes #569
2017-01-13 11:26:26 +00:00
Cosimo Lupo
cb94d6c4cd [feaLib] fix check for redefined glyph between multiple markClass definitions (#803)
* [feaLib.ast] fix checking multiple markClass definitions don't redefine same glyphs

As pointed out by @mhosken, we are looking in the wrong list for glyphs
that have already been defined in a previous markClass definition.

With this patch, the current markClass.fea test case fails becuase it defines 'acute'
twice for the same @TOP_MARKS class:

fontTools.feaLib.error.FeatureLibError: Lib/fontTools/feaLib/testdata/markClass.fea:6:5: Glyph acute already defined at Lib/fontTools/feaLib/testdata/markClass.fea:3:1

Also see conversation at:
3b79d51755 (r94622074)

* feaLib/testdat/markClass.fea: remove duplicate 'acute' in @TOP_MARKS

Now the test pass, after 45c77b7

* [feaLib.builder_test] test case for redefined glyph in multiple markClass definitions
2017-01-12 15:39:21 +01:00
Cosimo Lupo
ea8608c168
[minor] whitespace 2017-01-12 13:36:06 +00:00
Cosimo Lupo
3dd31c8689
[feaLib.builder_test] minor refactoring in check_fea2fea_file 2017-01-12 13:21:20 +00:00
Cosimo Lupo
3bd0788a37
[feaLib] use generator expressions with "".join(), instead of list comprehensions
This should be a bit more efficient as we don't need to create a temporary list
object before passing it to "".join() method of str; the latter accepts any
Iterable
2017-01-12 11:49:54 +00:00
Martin Hosken
7387f0eebf
Put back buggy code that we don't want to deal with yet 2017-01-12 11:34:44 +00:00
Martin Hosken
7d01f365ea
Tidy up spacing, make generic fea2fea checker 2017-01-12 11:34:44 +00:00
Martin Hosken
15f4cfa2d3
whitespace reallignment for self.ast in fealib parser 2017-01-12 11:34:43 +00:00
Martin Hosken
a23da5384b
Add ast subclassing, extension commands and an example test 2017-01-12 11:34:43 +00:00
Cosimo Lupo
49bcbb916b
consistently do sys.exit(unittest.main()) in all test modules
So that when run as scrips they report test failures with exit code

Follow up on b7bb391033ef3255c90134da3d7aef50d2d5326d
2017-01-11 13:05:35 +00:00
Cosimo Lupo
26679a9d73
feaLib.builder: fix order of {from,to}file arguments of difflib.unified_diff 2017-01-04 22:01:40 +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
Behdad Esfahbod
3eacc23868 Update tests for previous commit
The following sed command can be used to update TTX sources for the LookupType
change:

$ sed -i'~' 's/<!-- LookupType=\(.\) -->/<LookupType value="\1"\/>/g' *.ttx
2016-12-28 20:29:43 -05:00
Behdad Esfahbod
2034cef52f Write test diffs to stderr, not stdout 2016-12-26 20:30:00 -05:00
Cosimo Lupo
be6afae761
builder_test: add test for omitted class definitions 2016-12-20 13:27:03 +00:00
Cosimo Lupo
f147398554
ast: write commas for empty glyph classes in GlyphClassDef statement 2016-12-20 13:26:48 +00:00