| 1 |
import fontforge |
| 2 |
|
| 3 |
font = fontforge.font() |
| 4 |
glyph = font.createChar(0x41) |
| 5 |
|
| 6 |
|
| 7 |
pen = glyph.glyphPen() |
| 8 |
pen.moveTo((0,0)) |
| 9 |
pen.lineTo((1,1)) |
| 10 |
pen.lineTo((1,0)) |
| 11 |
pen.closePath() |
| 12 |
del pen |
| 13 |
|
| 14 |
|
| 15 |
glyph.activeLayer = 0 |
| 16 |
glyph.background.is_quadratic = False |
| 17 |
pen = glyph.glyphPen() |
| 18 |
pen.moveTo((1,1)) |
| 19 |
pen.closePath() |
| 20 |
del pen |
| 21 |
|
| 22 |
font.generate('a.ttf', flags=('PfEd-background')) |
| 23 |
font.close() |
| 24 |
|
| 25 |
font = fontforge.open('a.ttf') |
| 26 |
glyph = font[0x41] |
| 27 |
|
| 28 |
assert len(glyph.foreground) == 1, 'Foreground contains a contour' |
| 29 |
assert len(glyph.background) == 1, 'Background contains a contour' |
| 30 |
|
| 31 |
fgc = fontforge.contour(True) |
| 32 |
fgc.closed = True |
| 33 |
fgc[:] = ((0,0), (1,1), (1,0)) |
| 34 |
|
| 35 |
assert glyph.foreground[0] == fgc, 'Foreground contour matches expected contour' |
| 36 |
assert list(glyph.foreground[0]) == list(fgc), 'Foreground contour points matches expected contour points' |
| 37 |
|
| 38 |
bgc = fontforge.contour(False) |
| 39 |
bgc.closed = True |
| 40 |
bgc[:] = ((1,1),) |
| 41 |
assert glyph.background[0] == bgc, 'Background contour matches expected contour' |
| 42 |
assert list(glyph.background[0]) == list(bgc), 'Foreground contour points matches expected contour points' |
| 43 |
|
| 44 |
font.close() |