From 7ab01f730c22ba1616e6c4f815d166d92b54ef92 Mon Sep 17 00:00:00 2001 From: moyogo Date: Wed, 30 Sep 2015 21:10:04 +0100 Subject: [PATCH] [voltLib] Add ranges to GroupDefinition --- Lib/fontTools/voltLib/parser.py | 6 +++++- Lib/fontTools/voltLib/parser_test.py | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/voltLib/parser.py b/Lib/fontTools/voltLib/parser.py index a7f9484b6..4f0ded476 100644 --- a/Lib/fontTools/voltLib/parser.py +++ b/Lib/fontTools/voltLib/parser.py @@ -93,7 +93,7 @@ class Parser(object): def parse_enum_(self): assert self.is_cur_keyword_("ENUM") location = self.cur_token_location_ - enum = {'glyphs': [], 'groups': []} + enum = {'glyphs': [], 'groups': [], 'ranges': []} while self.next_token_ != "END_ENUM": if self.next_token_ == "GLYPH": self.expect_keyword_("GLYPH") @@ -103,6 +103,10 @@ class Parser(object): self.expect_keyword_("GROUP") name = self.expect_string_() enum['groups'].append(name) + elif self.next_token_ == "RANGE": + self.expect_keyword_("RANGE") + start, end = self.expect_string_(), self.expect_string_() + enum['ranges'].append((start, end)) self.expect_keyword_("END_ENUM") return enum diff --git a/Lib/fontTools/voltLib/parser_test.py b/Lib/fontTools/voltLib/parser_test.py index d6aa5b501..7081904d3 100644 --- a/Lib/fontTools/voltLib/parser_test.py +++ b/Lib/fontTools/voltLib/parser_test.py @@ -63,7 +63,8 @@ class ParserTest(unittest.TestCase): {"glyphs": ["a", "aacute", "abreve", "acircumflex", "adieresis", "ae", "agrave", "amacron", "aogonek", "aring", "atilde"], - "groups": []})) + "groups": [], + "ranges": []})) [def_group] = self.parse( 'DEF_GROUP "KERN_lc_a_2ND"\n' 'ENUM GLYPH "a" GROUP "aaccented" END_ENUM\n' @@ -72,7 +73,20 @@ class ParserTest(unittest.TestCase): self.assertEqual((def_group.name, def_group.enum), ("KERN_lc_a_2ND", {"glyphs": ["a"], - "groups": ["aaccented"]})) + "groups": ["aaccented"], + "ranges": []})) + [def_group] = self.parse( + 'DEF_GROUP "KERN_lc_a_2ND"\n' + 'ENUM RANGE "a" "atilde" GLYPH "b" RANGE "c" "cdotaccent" ' + 'END_ENUM\n' + 'END_GROUP' + ).statements + self.assertEqual((def_group.name, def_group.enum), + ("KERN_lc_a_2ND", + {"glyphs": ["b"], + "groups": [], + "ranges": [("a", "atilde"), + ("c", "cdotaccent")]})) def test_group_duplicate(self): self.assertRaisesRegex(