do not lookup metric informations (width field) for missing glyphs (marked by None...
[PyX/mjg.git] / test / functional / test_pdfextra.py
bloba7306784836b3e00f3ec21b5963ff9745041f4b9
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-1 -*-
3 import sys; sys.path[:0] = ["../.."]
5 import pyx
6 from pyx import *
7 from pyx.font.font import PDFTimesBold
8 from pyx.pdfextra import *
11 def texttest():
12 c = canvas.canvas()
13 d = 0.0
15 llx, lly, w, h = 0, 0, 5, 1
16 c.text(llx, lly+h, "first textfield:", [text.vshift(-0.5)])
17 c.stroke(path.rect(llx-d, lly-d, w+2*d, h+2*d))
18 c.insert(textfield(llx, lly, w, h, name="textfield", defaultvalue="hallo", multiline=1,
19 font=PDFTimesBold))
21 llx, lly, w, h = 0, -2, 1, 1
22 c.text(llx, lly+h, "second textfield:", [text.vshift(-0.5)])
23 c.stroke(path.rect(llx-d, lly-d, w+2*d, h+2*d))
24 c.insert(textfield(llx, lly, w, h, name="another"))
26 # XXX scaling of textsize
27 # XXX font does not work
29 return c
31 def checkboxtest():
32 c = canvas.canvas()
34 c.text(0, 0, "first checkbox:", [text.vshift(-0.5)])
35 c.insert(checkbox(0, -0.5, name="checkbox", defaulton=1))
37 return c
39 def radiotest():
40 c = canvas.canvas()
42 c.text(0, 0, "first radiobuttons:", [text.vshift(-0.5)])
43 pos = [(0, -0.5), (0, -1.0), (0, -1.5)]
44 values = ["One", "Two", "Three"]
45 for (x, y), value in zip(pos, values):
46 c.text(x+12*unit.x_pt, y, value)
47 c.insert(radiobuttons(pos, name="button", values=values, defaultvalue=values[0]))
49 # XXX : default entry is activated with the others
51 return c
53 def choicetest():
54 c = canvas.canvas()
55 d = 0.0
57 llx, lly, w, h = 0, 0, 5, 1
58 values = ["One", "Two", "Three"]
59 c.text(llx, lly+h, "first choicefield:", [text.vshift(-0.5)])
60 c.stroke(path.rect(llx-d, lly-d, w+2*d, h+2*d))
61 c.insert(choicefield(llx, lly, w, h, name="choicefield", values=values, defaultvalue=values[0],
62 font=PDFTimesBold))
64 # XXX font does not work
66 return c
68 # write all test into one canvas
69 c = canvas.canvas()
70 for cc in [texttest(), checkboxtest(), radiotest(), choicetest()]:
71 if not c:
72 t = []
73 else:
74 t = [trafo.translate(0, c.bbox().bottom() - cc.bbox().top() - 1)]
75 c.insert(cc, t)
76 c.stroke(cc.bbox().path(), t + [color.rgb.red, style.linestyle.dotted])
78 # test the transformation behaviour:
79 cc = canvas.canvas([trafo.scale(0.3), trafo.rotate(90)])
80 cc.fill(c.bbox().path(), [color.gray(0.9)])
81 cc.insert(c)
82 d = document.document([document.page(cc, bboxenlarge=1)])
83 d.writePDFfile("test_pdfextra", compress=0)
85 # vim:syntax=python
86 # vim:fdm=marker:fmr=<<<,>>>: