I'm programmatically converting (in perl with Font::TTF) a proportional font to "fixed-width" and wrestling with nested composite glyphs. Straightforward approach seems horrendously complex, and I'm wondering if there is a simpler approach that I am missing ...
Adjusting of simple glyphs is straightforward: reset AdvanceWidth and, if needed, shift glyph points in the X axis. However ...
If a simple glyph is a component in another composite glyph, the attachment points are now incorrect since the component may be X-shifted. The attachment points have to be adjusted to account for the X-shift.
Furthermore, composite glyphs can be arbitrarily nested, so some kind of iterative strategy seems to be needed. No composite glyph can be processed until all it's components have been processed ... i.e. starting with all simple glyphs then composite glyphs that only have simple glyphs as components, then working your way up the dependency tree of composite glyphs. At each stage, a structure is needed to remember how much each component has been re-positioned.
Things get (much) more thorny if I want to scale some wider glyphs in the X direction to fit the fixed-width bounding box, such as is done by the Python-based monospacifier tool (https://github.com/cpitclaudel/monospacifier
... which I can't actually run)
Is there a simpler strategy to what I'm trying to do?
I could (groan) flatten composites into simple glyphs, but that seems heavy-handed.
FYI, I can't just set the OS2.isFixedPitch and let (hope) the rendering engine forces everything to monospace, since the font does use 3 widths: 1× wide (eg. Latin), 2× wide for most Asian 'fullwidth', and 0 wide for appopriate code points, so not strictly monospaced.
Any thoughts / ideas appreciated!