56 Commits

Author SHA1 Message Date
Khaled Hosny
88885ba9fc feaLib: handle singleton class as a single glyph in multiple subst
This how GlyphsApp handles it and how it is handled in single
substitution.
2023-05-09 17:33:36 +03:00
Khaled Hosny
f642a2aac4 feaLib: support multiple substitution with classes
This is a GlyphsApp extension, (partially) documented [here][1], but it is a
useful one as it allows concise glyph insertion using decomposition
without having to maintain the list of glyphs in two places. E.g.

```fea
@upper = [A-Z];

lookup insert {
  sub @upper by @upper connector;
} insert;

feature ccmp {
  sub @upper' lookup insert x;
} ccmp;
```

As apposed to:

```fea
@upper = [A-Z];

lookup insert {
  sub A by A connector;
  sub B by B connector;
  sub C by C connector;
  sub D by D connector;
  sub E by E connector;
  sub F by F connector;
  sub G by G connector;
  sub H by H connector;
  sub I by I connector;
  sub J by J connector;
  sub K by K connector;
  sub L by L connector;
  sub M by M connector;
  sub N by N connector;
  sub O by O connector;
  sub P by P connector;
  sub R by R connector;
  sub S by S connector;
  sub T by T connector;
  sub U by U connector;
  sub V by V connector;
  sub W by W connector;
  sub X by X connector;
  sub Y by Y connector;
  sub Z by Z connector;
} insert;

feature ccmp {
  sub @upper' lookup insert x;
} ccmp;
```

1. http://handbook.glyphsapp.com/en/layout/multiple-substitution-with-classes/
2023-05-09 14:06:12 +03:00
Khaled Hosny
eb93b7688e [feaLib] Fix handled of "ignore" with unmarked glyphs
Fixes https://github.com/fonttools/fonttools/issues/2949

- If there are no marked glyphs in an "ignore" statement, issue a
  warning. The spec disallows this but makeotf allows it. It is most
likely a typo, so a warning is warranted.
- Mark the first glyph not all the glyphs, this matches makeotf.
- In asFea() always mark the input glyph.
- Udpate the tests.
2023-01-10 16:26:12 +02:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Simon Cozens
d224e1f73d
[feaLib] show all missing glyphs at once (#2665) 2022-06-23 15:04:59 +01:00
Simon Cozens
563730f8ce
Support variable feature syntax (#2432) 2021-10-28 11:58:54 +01:00
Just van Rossum
9825ab0977
Fix for #2293: allow more than one lookahead glyph/class in contextual positioning with "value at end" (#2294)
* add test that fails for #2293

* fixing #2293: rewrite of contextual positioning logic, ensure len(suffix) > 1 yields the correct result; checking more edge cases and raising errors inspired by makeotf

* test error cases

* only check when we actually have a value

* catch one more case that makeotf errors on and we didn't
2021-05-08 09:22:30 +02:00
Kamile Demir
29ff42d15f
Reusing otlLib buildStatTable() in feaLib 2021-02-25 17:16:02 +00:00
Zachary Scheuren
0434b1a917
Add feaLib support for STAT table 2021-02-25 17:16:01 +00:00
Khaled Hosny
7db9ba6ef6 [feaLib] Allow anonymous glyphclass in LookupFlags
Almost everywhere else when a glyph class name is accepted, anonymous
glyph classes are also accepted. This is rather inconsistent and
inconvenient.
2020-08-07 19:57:31 +02:00
Nikolaus Waxweiler
0e7a4460f3
[feaLib] Introduce includeDir on Parser and IncludingLexer (#1973)
This makes the directory to search for included files explicit.

Also use Python 3's FileNotFoundError to catch non-existant files instead of a workaround for Python 2.
2020-05-28 17:43:19 +01:00
Simon Cozens
b299bfb389
[feaLib] Support multiple lookups per glyph position (#1905)
This allows for more than one "lookup ..." chaining statements at each glyph position in a chaining contextual substitution or positioning rule: e.g.

    sub a b c' lookup lookup1 lookup lookup2 d;

The corresponding change in the Adobe OpenType Feature File Specification (and implementation in makeotf) happened in adobe-type-tools/afdko#1132.
2020-05-12 06:28:25 +01:00
Cosimo Lupo
1cbb28acd8
Merge pull request #1870 from anthrotype/fealib-parser-no-glyphnames
feaLib: without glyphNames, warn but don't parse hyphens as ranges
2020-04-16 16:16:29 +01:00
Tom
c70395fbdb
[feaLib] Raise exception when GSUB statement doesn't match a rule. (#1876)
* [feaLib] Raise exception when substitute statement doesnt match any of the rules. Add tests that trigger said exception.
2020-04-16 16:10:03 +01:00
Cosimo Lupo
c1af75b803
feaLib.parser: check that glyph name is actually ambiguous
https://github.com/fonttools/fonttools/pull/1870#discussion_r403259450
2020-04-03 21:17:02 +01:00
Cosimo Lupo
a913431ecd
feaLib.parser: if no glyphNames, treat dash as names, not ranges
But print a warning about the possible ambiguity.

Fixes https://github.com/fonttools/fonttools/issues/1768
2020-04-03 12:42:22 +01:00
Cosimo Lupo
be77f3eeab
feaLib/parser_test: rename {Unicode,String}IO, remove misc.py23 2020-04-03 11:46:36 +01:00
Nikolaus Waxweiler
5cda8381f9
[feaLib] Check that glyph names referenced in the feature file are part of the glyph set (#1828)
This checks that glyph names that appear in a feature file are actually
in the glyph set provided in glyphNames. If the set is empty, no check
is done. This preempts a KeyError later during saving of a TTFont object
and makes this case much more easily catchable.

Closes #1723.
2020-02-13 14:47:29 +00:00
Khaled Hosny
22bfc305ee [feaLib] fix mixed single/multiple substitutions
If the single substitution involved a glyph class, we were incorrectly
using only the first glyph in the class.

Broken since ec6ff821f0e72022d7aec8794b6bb589d8f81808, apparently no one
else uses this feature!
2020-01-29 22:36:54 +02:00
Khaled Hosny
197b36fef4 [feaLib] Don’t accept hex/octal numbers everywhere
Only in name, nameid, sizemenuname and Character.
2019-08-17 13:43:18 +02:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Miguel Sousa
ddff29cb5d Fix DeprecationWarning: invalid escape sequence 2019-04-01 14:04:14 -07:00
Khaled Hosny
45861a15ca [feaLib] Reject invalid lookupflag without a value
Fixes https://github.com/fonttools/fonttools/issues/1538
2019-03-15 14:13:46 +02:00
Khaled Hosny
250eac4cae [feaLib] Correctly handle lookupflag 0 in asFea()
Part of https://github.com/fonttools/fonttools/issues/1538
2019-03-15 14:13:46 +02:00
justvanrossum
e22453c933 followup to #1531 2019-03-06 16:47:16 +01:00
Khaled Hosny
1a0aec4c56 [feaLib] Add forceChain to MultipleSubstStatement
For consistency with other substitution statements.
2019-02-19 18:59:58 +02:00
punchcutter
da5b1500b9 Read special case of contextual positioning. 2019-02-12 12:35:34 -08:00
Khaled Hosny
354b89c068 [feaLib] Implement ValueRecord.asFea()
ValueRecord had a makeString() method that takes an optional “vertical”
argument, but no code outside the tests sets this argument. Renamed it
to asFea() and dropped the “vertical”, so that it consistent with the
rest of feaLib.ast classes.
2019-01-28 11:52:36 +02:00
Khaled Hosny
e974ea3871 [feaLib] Add tests for ValueRecordDefinition.asFea()
Currently fail as it calls ValueRecord.asFea() which is not implemented.
2019-01-28 11:52:36 +02:00
Khaled Hosny
f48f4cc6b4 [feaLib] Round-trip useExtension keyword 2019-01-27 12:16:35 +02:00
Cosimo Lupo
091b05296d
[feaLib] distinguish missing value and explicit '<NULL>' for PairPos2 format A
Fixes #1459
2019-01-19 11:46:05 +00:00
Martin Hosken
17de50c172 Add DFLT script languagesystem test 2018-07-09 20:11:57 +01:00
Martin Hosken
6d6b9c69d4 Fix tests 2018-07-09 17:02:48 +01:00
Miguel Sousa
a4c055c18a
[feaLib] Generalize FeatureNamesBlock 2018-03-01 10:22:09 +00:00
Cosimo Lupo
596ad14526
Merge pull request #1157 from moyogo/feaLib-multiple_by_multiple_error
feaLib.parser: raise meaningful error for substitution of multiple glyphs by multiple glyphs
2018-01-25 00:09:07 +01:00
Denis Moyogo Jacquerye
94b51e7344 feaLib.parser: raise meaningful error for substitution of multiple glyphs by multiple glyphs 2018-01-24 11:40:07 +00:00
Jany Belluz
89979dea04 [feaLib.parser] Add option to not follow includes
Currently, the feature file parser always resolves included files,
parses their content and inserts it in the resulting AST. The original
`include` statement is lost.

This commit introduces an option to not follow inclusions. Instead, the
output AST will contain an `include` statement. This allows to process a
feature file on its own, and allows to round-trip it.

For example in glyphsLib, when going from a UFO to a .glyphs file, a
UFO feature file will be sliced up into Glyphs.app classes (e.g. a
GSFeaturePrefix with code `include(../family.fea);`) and when going back
from .glyphs to UFO, the feature file will be patched back together.
2018-01-23 11:07:16 +00:00
Jany Belluz
d6a5a489c0 [feaLib.parser] Parse a feature file with only comments 2018-01-22 17:07:28 +00:00
Khaled Hosny
5e23b0545b [feaLib] Test mixed single/multiple substitutions 2017-12-22 16:30:34 +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
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
ac2762f0f3 [feaLib] Add more tests for parsing comments
https://github.com/fonttools/fonttools/issues/829
2017-03-09 14:13:46 +01: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
45a4a1f249 Add tests, rename _OMITs 2017-03-08 15:19:09 +00: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