babelfont icon indicating copy to clipboard operation
babelfont copied to clipboard

Decompose components?

Open arrowtype opened this issue 4 years ago • 1 comments

First, this is an awesome project, and I’m just coming across it for the first time. It is such a needed tool. Thank you for working on it!

I’m trying to decompose select components, but it’s not quite working how I expect it to. Is this method implemented yet, or am I trying it a little too early?

This is the primary way I expect it to work:

from babelfont import OpenFont

font = OpenFont(RecMono-Casual-1.053.ttf)

for glyph in font:
    print(glyph.name, glyph.width)
    if glyph.width > 600:
        for comp in glyph.components:
            comp.decompose()
Traceback (most recent call last):
  File "src/build-scripts/make-release/dlig2calt.py", line 109, in <module>
    fire.Fire(decomposeCodeLigs)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "src/build-scripts/make-release/dlig2calt.py", line 37, in decomposeCodeLigs
    comp.decompose()
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fontParts/base/component.py", line 320, in decompose
    self._decompose()
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/babelfont/ttf/component.py", line 66, in _decompose
    glyph = component.glyph
AttributeError: 'GlyphComponent' object has no attribute 'glyph'

I have also tried:

from babelfont import OpenFont

font = OpenFont(RecMono-Casual-1.053.ttf)

for glyph in font:
    print(glyph.name, glyph.width)
    if glyph.width > 600:
        for comp in glyph.components:
            glyph.decomposeComponent(comp)
Traceback (most recent call last):
  File "src/build-scripts/make-release/dlig2calt.py", line 108, in <module>
    fire.Fire(decomposeCodeLigs)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 471, in _Fire
    target=component.__name__)
  File "/Users/stephennixon/type-repos/recursive/venv/lib/python3.7/site-packages/fire/core.py", line 675, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "src/build-scripts/make-release/dlig2calt.py", line 36, in decomposeCodeLigs
    glyph.decomposeComponent(comp)
AttributeError: 'TTGlyph' object has no attribute 'decomposeComponent'

Am I missing something obvious? Thank you for any insights!

arrowtype avatar Jul 23 '20 00:07 arrowtype

Hmmm, I have to admit I've never tried doing that, and looking at the code it looks like I just copied a few functions from the UFO components module to get something basic working. I am not terribly surprised that decompose doesn't work. :-) Will get it working tomorrow.

simoncozens avatar Jul 23 '20 19:07 simoncozens