#!/usr/bin/env python3
"""Remove Corner hints from a .glyphs source file.

Equivalent to running layer.decomposeCorners() in Glyphs.app,
as intended by sources/inco_fix.py. Corner hints cause
CornerComponentsFilter to fail when SHAPE_ORDER has components
before paths, because the hint origin uses path indices but the
filter maps through the combined shape order.
"""
import sys
import glyphsLib

if len(sys.argv) != 3:
    print(f"Usage: {sys.argv[0]} <input.glyphs> <output.glyphs>", file=sys.stderr)
    sys.exit(1)

font = glyphsLib.GSFont(sys.argv[1])

count = 0
for glyph in font.glyphs:
    for layer in glyph.layers:
        corners = [h for h in layer.hints if h.type == "Corner"]
        if corners:
            for h in corners:
                layer.hints.remove(h)
                count += 1

font.save(sys.argv[2])
print(f"Removed {count} corner hints", file=sys.stderr)
