Skip to content

Unclear how to delete a contour from a glyph’s layer #4581

@dscorbett

Description

@dscorbett

Directly deleting a contour from a glyph’s layer does not have any effect in FontForge 20201107 on macOS 10.14.6.

import fontforge


font = fontforge.font()
glyph = font.createChar(0x003D)
pen = glyph.glyphPen()

contour = fontforge.contour()
contour.moveTo(0, 0)
contour.lineTo(500, 0)
contour.draw(pen)

contour = fontforge.contour()
contour.moveTo(0, 500)
contour.lineTo(500, 500)
contour.draw(pen)

glyph.stroke('circular', 20, 'round')
print(len(glyph.layers[1]))
del glyph.layers[1][1]
print(len(glyph.layers[1]))

That script outputs:

2
2

The foreground layer has the same number of contours before and after the del statement, indicating that it has no effect. However, the documentation says “You may [...] use del l[i] to remove the entry (reducing the number by one)”.

It is possible to work around this using assignment, but it wasn’t initially obvious to me that this was necessary. Is this the intended API?

foreground = glyph.layers[1]
del foreground[1]
glyph.layers[1] = foreground

I suppose what is happening is that glyph.layers returns a copy of the list of layers, and modifying the copy does not modify the glyph’s real list. However, unlike the documentation for glyph.foreground, which says “This is a copy of the glyph’s data”, the documentation for glyph.layers does not indicate that it is a copy. I therefore think that, if this is the intended behavior, the documentation of glyph.layers should be clarified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions