googlefonts / fez

Font Engineering made eaZy
BSD 3-Clause "New" or "Revised" License
14 stars 3 forks source link

[Feature request] Multiple contiguous Unicode ranges as a glyph selector #14

Closed kalapi closed 1 year ago

kalapi commented 1 year ago

Hello!

In several Indic (and probably other scripts) the Unicode ranges for a group such as 'all consonants' may not be contiguous.

Would it be possible to introduce multiple Unicode ranges as a single class definition?

Example:

# Bengali Unicode consonant ranges are non-contiguous
# The following example includes a mix of range and single Unicode point selector

DefineClass @consonants = [U+0995=>U+09A8 U+09AA=>U+09B0 U+09B2 U+09B6=>U+09B9];

Or is there another way to do this?

ctrlcctrlv commented 1 year ago

I think I have a patch for this.

simoncozens commented 1 year ago

I'm kind of surprised it doesn't work already. It should.

ctrlcctrlv commented 1 year ago

it's because of how inlineclass is defined

kalapi commented 1 year ago

Sorry for commenting on this issues but i'm getting the following tracebacks for simple Unicode range glyph selector:

Traceback (most recent call last):
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 414, in parseString
    rv = self.expand_statements(rv)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 433, in expand_statements
    returned = callback()
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 496, in <lambda>
    verb_ret = (verb, [transformer._THUNK, lambda : transformer.transform(tree) ])
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 161, in transform
    return self._transform_tree(tree)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 156, in _transform_tree
    children = list(self._transform_children(tree.children))
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 146, in _transform_children
    res = self._transform_tree(c)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 156, in _transform_tree
    children = list(self._transform_children(tree.children))
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 146, in _transform_children
    res = self._transform_tree(c)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 156, in _transform_tree
    children = list(self._transform_children(tree.children))
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 146, in _transform_children
    res = self._transform_tree(c)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 156, in _transform_tree
    children = list(self._transform_children(tree.children))
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 146, in _transform_children
    res = self._transform_tree(c)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 157, in _transform_tree
    return self._call_userfunc(tree, children)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 128, in _call_userfunc
    raise VisitError(tree.data, tree, e)
lark.exceptions.VisitError: Error trying to process rule "unicoderange":

'Token' object has no attribute 'pos_in_stream'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/bin/fez2fea", line 42, in <module>
    p.parseFile(args.fee)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 403, in parseFile
    return self.parseString(data)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 416, in parseString
    raise e.orig_exc
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/lark/visitors.py", line 124, in _call_userfunc
    return f(children)
  File "/Users/UT-development/Documents/_Programming/testing_environments/FEZzing/lib/python3.8/site-packages/fez/__init__.py", line 571, in unicoderange
    return lark.Token("UNICODERANGE", range(_UNICODEGLYPH(args[0].value), _UNICODEGLYPH(args[1].value)+1), args[0].pos_in_stream)
AttributeError: 'Token' object has no attribute 'pos_in_stream'

My input is almost the same as your example in the docs:

DefineClass @defaultNumbers = U+0030=>U+0039;
simoncozens commented 1 year ago

Looks like you have an old fez; update from this repo? Try pip3 install -U git+https://github.com/googlefonts/fez.git