49 Commits

Author SHA1 Message Date
NFSL2001
80db8cd6f7
Allow UTF-8 with BOM for features.fea 2024-05-01 22:41:03 +08:00
NFSL2001
cc02ada3c4
Allow UTF-8 with BOM for features.fea 2024-05-01 22:29:43 +08:00
Khaled Hosny
2616ab959c feaLib: Drop glyph and class names length limit
These were implemented to follow FEA spec, but makeotf does not seem to
have a name length limit any more (or it has a very large one, I tested
a 600-character name and it was accepted).

Fixes https://github.com/googlefonts/ufo2ft/issues/588
See also https://github.com/googlefonts/ufo2ft/pull/811#discussion_r1461667058
2024-01-22 16:38:54 +02:00
Nikolaus Waxweiler
d584daa8fd Blacken code 2022-12-13 11:26:36 +00:00
Simon Cozens
17feda4608
Cythonize lexer (#2799) 2022-09-05 12:58:00 +01:00
Just van Rossum
5fc65d7168
Misc py23 cleanups (#2243)
* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
2021-03-29 11:45:58 +02:00
Simon Cozens
ae5e000e29 Run black on all these too. 2020-07-15 17:16:12 +01:00
Simon Cozens
ebfa4ba1fe
Move feature builders to otlLib
Refactors feaLib, moving code which builds OpenType lookups into otlLib. Note that this changes feaLib's concept of `location` from a tuple to an object.
2020-07-02 14:09:10 +01: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
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
Khaled Hosny
ae239722d4 [feaLib] Correctly handle octal numbers
From https://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#9.e:
> Decimal numbers must begin with a non-0 digit, octal numbers with a 0
> digit, and hexadecimal numbers with a 0x prefix to numbers and
> hexadecimal letters a-f or A-F.

Fixes https://github.com/fonttools/fonttools/issues/1541
2019-08-17 13:43:18 +02:00
Nikolaus Waxweiler
01328213c7 Remove __future__ imports 2019-08-09 12:20:13 +01:00
Khaled Hosny
c3f3606c59 [feaLib] Allow hyphen in glyph class names
Matches AFDKO’s makeotf behaviour.
2019-02-10 14:31:37 +02:00
Cosimo Lupo
b30704114b
[feaLib.lexer] pass included filename token to IncludedFeaNotFound ...
In the IncludedFeaNotFound error, pass on the filename token as
it was included in the include statement, so that a client can do their
thing (e.g. issue a warning to suggest the user to write the path
relative to the UFO itself, instead of relative to the feautures.fea
which is inside a UFO).

Also. resolve includes relative to current working directory when the
IncludingLexer' filename is None because it originates from an in-memory stream.
2018-02-28 18:44:17 +00:00
Cosimo Lupo
7d7212b01f
feaLib: add IncludedFeaNotFound error
subclass of FeatureLibError, only raised if IOError.errno == ENOENT (i.e. FileNotFoundError)

https://github.com/googlei18n/fontmake/issues/157#issuecomment-367380471

Will be useful in ufo2ft to detect when an included feature file doesn't exist and print a nicer error message
explaining that includes must be relative to the UFO itself, and not relative to the embedded features.fea file.

https://github.com/unified-font-object/ufo-spec/issues/55
2018-02-21 16:41:11 +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
Jens Kutilek
f36c7ec39f Make "unexpected character" exception ASCII-safe 2017-08-08 13:46:05 +02: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
450d2b939e Add support for comments to parser 2017-03-08 13:50:06 +00:00
Miguel Sousa
75133fc4d1 [feaLib] Make include() work like makeotf 2017-02-13 08:42:03 +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
Sascha Brawer
f76792c0eb Parse anonymous data blocks
http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#10

For example, @mhosken is interested in experimenting with inlining
custom syntax (such as Python snippets) into feature files. After this
change, such experiments can be done on top of feaLib because the
Abstract Syntax Tree now contains the tag and content of `anonymous`
blocks.
2016-09-16 18:57:40 +02:00
Cosimo Lupo
cd8457f091 feaLib.lexer: strip newlines embedded within a string
Fixes #578
2016-04-17 22:21:24 +01: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
fdcba0e130 [feaLib] Allow “/” in name tokens
For “OS/2” table.
2016-03-23 03:10:05 +04:00
Cosimo Lupo
0f8f71d5ec [feaLib.lexer] modify make_lexer_ factory to take a 'file_or_path' argument
if 'file_or_path' is a file object keep it open, otherwise read the data from
the path and then close it.
2016-03-21 18:53:25 +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
7eed24725f Allow include statements not terminated by a semicolon
The lexer passes the semicolon to the parser, which will read over it.
Resolves https://github.com/behdad/fonttools/issues/552.
2016-03-20 17:26:20 +01:00
Sascha Brawer
9ec04f0537 Merge pull request #547 from adrientetar/patch-2
feaLib: support string input
2016-03-20 09:09:06 -07:00
Adrien Tétar
492df7359b feaLib: fix tests 2016-03-20 15:01:33 +01:00
Khaled Hosny
6e291cf705 [feaLib] Fix parsing float numbers
Numbers with integral parts >= 10 were incorrectly parsed as integers as
next_char always pointed to the second number not the decimal point.
2016-03-18 18:42:59 +04:00
Adrien Tétar
5e64857b97 feaLib: support string input 2016-03-15 20:01:29 +01:00
Cosimo Lupo
ac56990aad replace all uses of codecs.open with py23.open 2016-01-26 15:45:27 +00:00
Sascha Brawer
cc749c9c73 [feaLib] Allow 63 chars in names of glyphs and glyph classes
Resolves https://github.com/behdad/fonttools/issues/460.
See https://github.com/adobe-type-tools/afdko/pull/99 for
the change to the OpenType Feature File format specification.
2016-01-13 16:31:05 +01:00
Sascha Brawer
38f4ee7908 [feaLib] Implement table head with FontRevision statement 2016-01-11 18:01:47 +01:00
Sascha Brawer
5644da31d2 [feaLib] Parse device tables 2015-12-04 17:10:20 +01:00
Sascha Brawer
459eabf2e4 [feaLib] Allow +*:~^! in glyph names but not in glyph class names
Matches the behavior of Adobe's `makeotf` tool v2.0.84 of 2015-09-03.
Resolves https://github.com/behdad/fonttools/issues/370.
2015-09-14 10:53:37 +02:00
Sascha Brawer
9ddd313577 [feaLib] Merged LexerError and ParserError
This simplifies the public API to the library.  For clients, it does
not matter which exact component was detecting an error.  And we will
soon have more components; there would be little point in declaring
CompilerError, TableBuilderError, and so forth.
2015-09-07 11:39:09 +02:00
Sascha Brawer
5270a978a9 [feaLib] Support hexadecimal numbers
The OpenType Feature File specification does not specify hex numbers
as explicit token type, but they appear several times in the examples
given by the spec.
2015-08-10 11:17:52 +02:00
Sascha Brawer
d72aac035e [feaLib] Restrict length of glyph class names to 30 characters
This is required by the OpenType Feature File specification,
section 2.g.ii "Named glyph classes".
2015-08-10 11:17:52 +02:00
Sascha Brawer
ba238344b1 [feaLib] Implement top-level glyph class definitions 2015-08-10 11:17:52 +02:00
Sascha Brawer
f4ed6b5a85 Make pretty error messages for LexerError 2015-08-10 11:17:52 +02:00
Sascha Brawer
efbcba79a4 Handle inclusion of OpenType feature files 2015-08-10 11:17:52 +02:00
Sascha Brawer
ac700b0af5 Support FILENAME tokens when lexing OpenType feature files
When the lexer encounters the "include" keyword, it now enters
a special mode for scanning file names.  After having scanned over
the file name, the lexer goes back to normal.  The exact format
of file name strings is not defined by the OpenType feature file
specification, so we accept any character that is not a closing
parenthesis.
2015-08-10 11:17:52 +02:00
Sascha Brawer
612d2122ad Store file path in Lexer
This simplifies the implementation of the parser for
OpenType feature files, since it can now just keep
token locations returned by the lexer.  Before this
change, the parser had to un-pack the location tuples
and build new tuples that included the file path.
2015-08-10 11:17:52 +02:00
Sascha Brawer
da29d22748 Add lexer for OpenType feature files 2015-08-10 11:17:52 +02:00