diff options
author | Roozbeh Pournader <roozbeh@google.com> | 2015-04-24 18:30:04 -0700 |
---|---|---|
committer | Roozbeh Pournader <roozbeh@google.com> | 2015-04-24 18:31:58 -0700 |
commit | a72e363911890d861842aae75f9e9efb1ada1fc1 (patch) | |
tree | c18f4cfc90bc7d0e5e7f93bd44fc6f2318cbc0ba /scripts | |
parent | c79cb0093a44b0f21d0c71319c028e3a308e1d35 (diff) |
Refactor some common code in layout.py.
No functionality change.
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/layout.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/layout.py b/scripts/layout.py index 0568ea7..91cf8e8 100644 --- a/scripts/layout.py +++ b/scripts/layout.py @@ -18,6 +18,12 @@ import json from nototools import render +def _run_harfbuzz(text, font, language): + """Run harfbuzz on some text and return the shaped list.""" + hb_output = render.run_harfbuzz_on_text(text, font, language) + return json.loads(hb_output) + + _advance_cache = {} def get_advances(text, font): """Get a list of horizontal advances for text rendered in a font.""" @@ -26,12 +32,12 @@ def get_advances(text, font): except KeyError: pass - hb_output = render.run_harfbuzz_on_text(text, font, None) - hb_output = json.loads(hb_output) + hb_output = _run_harfbuzz(text, font, None) advances = [glyph['ax'] for glyph in hb_output] _advance_cache[(text, font)] = advances return advances + _shape_cache = {} def get_glyphs(text, font): """Get a list of shaped glyphs for text rendered in a font.""" @@ -40,8 +46,7 @@ def get_glyphs(text, font): except KeyError: pass - hb_output = render.run_harfbuzz_on_text(text, font, None) - hb_output = json.loads(hb_output) + hb_output = _run_harfbuzz(text, font, None) shapes = [glyph['g'] for glyph in hb_output] _shape_cache[(text, font)] = shapes return shapes |