| 1 |
import logging |
| 2 |
from importlib.resources import files |
| 3 |
from xml.etree import ElementTree |
| 4 |
|
| 5 |
from babelfont import Font |
| 6 |
|
| 7 |
logger = logging.getLogger(__name__) |
| 8 |
|
| 9 |
|
| 10 |
def bake_in_glyphdata(font: Font, args=None): |
| 11 |
logger.info("Baking in glyph data") |
| 12 |
|
| 13 |
if not args or "file" not in args: |
| 14 |
data_dir = files("babelfont.data") |
| 15 |
file = data_dir / "GlyphData.xml" |
| 16 |
else: |
| 17 |
file = args["file"] |
| 18 |
|
| 19 |
parsed = ElementTree.parse(open(file, "rb")).getroot() |
| 20 |
for glyph in parsed: |
| 21 |
data = glyph.attrib |
| 22 |
if data["name"] not in font.glyphs: |
| 23 |
continue |
| 24 |
myglyph = font.glyphs[data["name"]] |
| 25 |
if "production" in data and not myglyph.production_name: |
| 26 |
myglyph.production_name = data["production"] |
| 27 |
if "category" in data and not myglyph.category: |
| 28 |
if data["category"] == "Mark": |
| 29 |
myglyph.category = "mark" |