File: visualTest.py

package info (click to toggle)
python-booleanoperations 0.9.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: python: 1,249; makefile: 5
file content (87 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# run in DrawBot RoboFont extension
border = 20
dotSize = 10
offDotSize = dotSize * .5

try:
    CurrentFont
except NameError:
    class CurrentFont(dict):

        glyphOrder = []

        def save(self, path=None):
            pass

try:
    saveImage
except NameError:
    def saveImage(*args, **kwargs):
        pass


f = CurrentFont()


def drawOffCurve(anchor, off):
    x, y = anchor
    offx, offy = off
    if offx or offy:
        offx += x
        offy += y
        with savedState():
            stroke(1, 0, 0)
            fill(1, 0, 0)
            line((x, y), (offx, offy))
            oval(offx - offDotSize, offy - offDotSize, offDotSize * 2, offDotSize * 2)


def drawGlyphWithPoints(glyph):
    fill(0, .1)
    stroke(0)
    drawGlyph(glyph)
    stroke(None)

    for contour in glyph:
        fill(0, 1, 0)
        for point in contour.bPoints:
            x, y = point.anchor
            drawOffCurve((x, y), point.bcpIn)
            drawOffCurve((x, y), point.bcpOut)
            oval(x - dotSize, y - dotSize, dotSize * 2, dotSize * 2)
            fill(1, 0, 0)


for glyphName in f.glyphOrder:
    if glyphName not in f:
        continue
    g = f[glyphName]
    bounds = g.bounds
    if not bounds:
        continue
    minx, miny, maxx, maxy = bounds
    w = maxx - minx
    h = maxy - miny
    layerCount = len(f.layers)
    newPage((w + border) * layerCount + border, h  + border * 2 + 100)
    translate(border, border + 100)
    translate(-minx, -miny)
    fontSize(20)
    stroke()
    text("%s" % g.name, (w * .5, -100 + miny), align="center")
    drawGlyphWithPoints(g)
    translate(w + border, 0)
    for layer in f.layers:
        if layer.name == "foreground":
            continue
        fill(0)
        text(layer.name, (w * .5, -100 + miny), align="center")
        if g.name not in layer:
            translate(w + border)
            continue
        lg = layer[g.name]
        drawGlyphWithPoints(lg)
        translate(w + border)


saveImage("visualTest.pdf")