Exemplo n.º 1
0
 def test_newPage_empty_implicit_first_page(self):
     drawBot.newDrawing()
     drawBot.rect(100, 100, 200, 200)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 2
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 3
0
 def test_newPage_following(self):
     drawBot.newDrawing()
     drawBot.size(400, 500)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 400)
     self.assertEqual(drawBot.height(), 500)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 4
0
 def test_newPage_empty_implicit_first_page(self):
     drawBot.newDrawing()
     drawBot.rect(100, 100, 200, 200)
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 2)
Exemplo n.º 5
0
 def test_newPage_empty_multiple(self):
     drawBot.newDrawing()
     drawBot.newPage()
     drawBot.newPage()
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 3)
Exemplo n.º 6
0
 def test_newPage_empty_multiple(self):
     drawBot.newDrawing()
     drawBot.newPage()
     drawBot.newPage()
     drawBot.newPage()
     self.assertEqual(drawBot.width(), 1000)
     self.assertEqual(drawBot.height(), 1000)
     self.assertEqual(drawBot.pageCount(), 3)
def new(layer, totalPages):
    d.newPage(paperSize)
    w, h = d.width(), d.height()

    m = l.associatedFontMaster()
    d.font(".SF Compact Text", 10)
    d.text("%s    %s" % (layer.parent.name, layer.name), (margin, margin))
    d.text("%s/%s" % (d.pageCount(), totalPages - 1), (w - margin, margin),
           align="right")
    ma, md, mx, mc = m.ascender, m.descender, m.xHeight, m.capHeight
    zones = [az.position + az.size for az in m.alignmentZones] + [ma, md]
    boundsTop, boundsBtm = max(zones), min(zones)
    sf = float(h - margin * 3) / (boundsTop - boundsBtm)  #scalefactor
    d.scale(sf)
    wNew = w / sf  # scaled paper size
    d.translate((margin / sf), -boundsBtm + (margin * 2) / sf)

    # drawing metrics lines
    d.stroke(0, 0, 0, 0.5)
    d.strokeWidth(0.5 / sf)
    d.fill(None)
    lw = layer.width
    d.rect(0, md, lw, ma - md)
    d.line((0, mc), (lw, mc))  # x-height
    d.line((0, mx), (lw, mx))  # x-height
    d.line((0, 0), (lw, 0))  # baseline

    # alignment zones
    d.stroke(None)
    d.fill(0.7, 0.3, 0, 0.1)
    for az in m.alignmentZones:
        d.rect(0, az.position, lw, az.size)

    # drawing nodes
    offcurves = []
    smooths = []
    sharps = []
    for p in layer.paths:
        smooths += [n for n in p.nodes if n.connection == GSSMOOTH]
        sharps += [
            n for n in p.nodes
            if n.type != OFFCURVE and n.connection != GSSMOOTH
        ]
        offcurves += [n for n in p.nodes if n.type == OFFCURVE]
        d.stroke(0, 0, 0, 0.2)
        for n in p.nodes:
            if n.type == OFFCURVE:
                if n.nextNode.type != OFFCURVE:
                    d.line((n.x, n.y), (n.nextNode.x, n.nextNode.y))
                elif n.prevNode.type != OFFCURVE:
                    d.line((n.prevNode.x, n.prevNode.y), (n.x, n.y))
    d.stroke(None)
    nodeSize = 3 / sf
    hf = nodeSize / 2  #half
    d.fill(0, 0, 1, 0.5)
    for n in sharps:
        d.rect(n.x - hf, n.y - hf, nodeSize, nodeSize)
    d.fill(0, 0.7, 0, 0.5)
    for n in smooths:
        d.oval(n.x - hf, n.y - hf, nodeSize, nodeSize)
    d.fill(0, 0, 0, 0.2)
    for n in offcurves:
        d.oval(n.x - hf, n.y - hf, nodeSize, nodeSize)

    # drawing anchors
    d.stroke(None)
    d.fill(0.7, 0.25, 0.0, 0.75)
    nodeSize = 4 / sf
    hf = nodeSize * 0.7
    for a in layer.anchors:
        # print(a, (ma, md, mc, mx, 0))
        if a.y in (ma, md, mc, mx, 0):
            d.polygon((a.x - hf, a.y), (a.x, a.y - hf), (a.x + hf, a.y),
                      (a.x, a.y + hf),
                      close=True)
        else:
            d.oval(a.x - hf, a.y - hf, nodeSize, nodeSize)

    # glyph outline
    d.fill(0, 0, 0, 0.3)
    d.stroke(0, 0, 0, 1)
    d.drawPath(layer.completeBezierPath)

    return sf, ma, md