| 1 |
import logging |
| 2 |
|
| 3 |
from babelfont import Glyph |
| 4 |
from babelfont.Font import Font |
| 5 |
|
| 6 |
logger = logging.getLogger(__name__) |
| 7 |
|
| 8 |
|
| 9 |
def decompose_mixed_glyphs(font: Font, _args=None): |
| 10 |
logger.info("Decomposing mixed glyphs") |
| 11 |
|
| 12 |
exportable = set(glyph.name for glyph in font.glyphs if glyph.exported) |
| 13 |
done = set() |
| 14 |
for glyph in font.glyphs: |
| 15 |
decompose_a_glyph(font, glyph, exportable, done) |
| 16 |
|
| 17 |
|
| 18 |
def decompose_a_glyph(font: Font, glyph: Glyph, exportable, done): |
| 19 |
if glyph.name in done: |
| 20 |
return |
| 21 |
for layer in glyph.layers: |
| 22 |
for c in layer.components: |
| 23 |
decompose_a_glyph(font, font.glyphs[c.ref], exportable, done) |
| 24 |
if (layer.paths and layer.components) or any( |
| 25 |
c.ref not in exportable for c in layer.components |
| 26 |
): |
| 27 |
layer.decompose() |
| 28 |
done.add(glyph.name) |