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:
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.
Directly deleting a contour from a glyph’s layer does not have any effect in FontForge 20201107 on macOS 10.14.6.
That script outputs:
The foreground layer has the same number of contours before and after the
delstatement, indicating that it has no effect. However, the documentation says “You may [...] usedel 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?
I suppose what is happening is that
glyph.layersreturns a copy of the list of layers, and modifying the copy does not modify the glyph’s real list. However, unlike the documentation forglyph.foreground, which says “This is a copy of the glyph’s data”, the documentation forglyph.layersdoes not indicate that it is a copy. I therefore think that, if this is the intended behavior, the documentation ofglyph.layersshould be clarified.