- path module
[PyX/mjg.git] / test / functional / test_text.py
blobd1b04fe86efcbcdfe1868e336bc603d6d98783ca
1 #!/usr/bin/env python
2 import sys; sys.path[:0] = ["../.."]
4 from pyx import *
6 c = canvas.canvas()
7 text.set(mode="latex")
8 text.preamble(r"""%
9 \usepackage{graphicx}
10 \usepackage{color}
11 \usepackage{rotating}
12 \usepackage{helvet}
13 % \graphicspath{{eps/}}
15 \definecolor{col0}{gray}{0.1}
16 \definecolor{col1}{cmyk}{0.3, 0.2, 0.1, 0.1}
17 \definecolor{col2}{rgb}{0.4, 0.3, 0.1}
18 \definecolor{col3}{RGB}{200, 200, 200}
19 \definecolor{col4}{hsb}{0.1, 0.1, 0.1}
20 \definecolor{col5}{named}{Red}
21 % \definecolor{col6}{pyx}{Some-PyX-Colour}
22 \definecolor{col0}{gray}{0.5}""", [text.texmessage.ignore])
24 c.stroke(path.line(-1, 0, 6, 0))
26 c.stroke(path.line(6, 5, 6.99, 5), [style.linewidth.THIN])
27 c.stroke(path.line(6, 6, 6.99, 6), [style.linewidth.THIN])
28 c.stroke(path.line(8.01, 5, 9, 5), [style.linewidth.THIN])
29 c.stroke(path.line(8.01, 6, 9, 6), [style.linewidth.THIN])
30 c.stroke(path.line(7, 4, 7, 4.99), [style.linewidth.THIN])
31 c.stroke(path.line(8, 4, 8, 4.99), [style.linewidth.THIN])
32 c.stroke(path.line(7, 6.01, 7, 7), [style.linewidth.THIN])
33 c.stroke(path.line(8, 6.01, 8, 7), [style.linewidth.THIN])
34 c.text(7, 5, "\\vrule width1truecm height1truecm")
36 c.text(6.2, 0, "0", [text.vshift.middlezero])
37 c.text(-1.2, 0, "abc", [text.vshift.mathaxis, text.halign.right])
39 t1 = text.text(0, 0, "a \PyXMarker{beforeb}b\PyXMarker{afterb} c d e f g h i j k l m n o p q r s t u v w x y z", [text.parbox(2, baseline=text.parbox.bottom)])
40 c.insert(t1)
41 c.stroke(t1.path())
43 t2 = c.insert(text.text(3, 0, "a \PyXMarker{beforeb}b\PyXMarker{afterb} c d e f g h i j k l m n o p q r s t u v w x y z", [text.parbox(2, baseline=text.parbox.top)]))
44 c.stroke(t2.path())
45 c.stroke(path.line(*(t1.marker("beforeb") + t2.marker("beforeb"))), [color.rgb.red])
46 c.stroke(path.line(*(t1.marker("afterb") + t2.marker("afterb"))), [color.rgb.green])
48 c.text(0, 3, r"\int\limits_{-\infty}^\infty \!{\rm d}x\, e^{-a x^2} = \sqrt{\pi\over a}", [text.mathmode])
49 c.text(0, 6, r"\int\limits_{-\infty}^\infty \!{\rm d}x\, e^{-a x^2} = \sqrt{\pi\over a}", [text.size.LARGE, text.mathmode])
51 c.stroke(c.text(1, 2, r"Hello, world!").path())
53 # test a virtual font with encoding
54 c.text(0, 8, r"\sffamily VF test: \"o\ss ffl \char0")
55 c.text(0, 9, r"\sffamily \fontsize{30}{35}\selectfont VF test: \"o\ss ffl \char0")
57 # scaling test
58 unit.set(xscale=2)
59 t = c.text(0, 11, r"scale test", [color.rgb.green])
60 unit.set(xscale=1)
61 t = c.text(0, 11, r"scale test", [color.rgb.red])
63 # test font stripping (proper usedchar selection)
64 c.text(0, 12, r"usechar test (``fl'' should be typed):")
65 myrunner = text.texrunner(fontmaps="download35.map")
66 myrunner.preamble(r"\font\pyxfont=phvr8t\pyxfont")
67 c.insert(myrunner.text(5.5, 12, r"\char'035"))
69 myrunner2 = text.texrunner(fontmaps="download35.map")
70 myrunner2.preamble(r"\font\pyxfont=ptmr8t\pyxfont")
71 c.insert(myrunner2.text(6.5, 12, r"\char'035"))
73 # test the specials
74 c.stroke(c.text(10, 2, r"Hello, \color{green}world!", [trafo.slant(1)]).path())
75 c.insert(c.text(10, 0, r"\begin{rotate}{90}\parbox{5cm}{rotated\\ in \LaTeX}\end{rotate}"))
77 d = canvas.canvas()
78 d.stroke(path.rect(0,0, 1,1))
79 d.stroke(path.line(0,0, 1,1))
80 d.stroke(path.line(1,0, 0,1))
81 d.writeEPSfile("sample")
82 c.insert(c.text(10, 0, r"""
83 \textcolor{col0}{abc}
84 \textcolor{col1}{abc}
85 \textcolor{col2}{abc}
86 \textcolor{col3}{abc}
87 \textcolor{col4}{abc}
88 \textcolor{col5}{abc}
89 % \textcolor{col6}{abc}%
90 """, [text.parbox(3)]))
91 c.insert(c.text(15, 0, r"""
92 \colorbox{col2}{ColorBox}\\
93 \fcolorbox{col3}{col4}{FColorBox}"""))
95 c.text(4, 2, r"{\color[cmyk]{0.1,0.2,0.3,0.4}c\color[gray]{0.5}o\color[hsb]{0.2,0.3,0.4}l\color[rgb]{0.2,0.4,0.6}o\color[RGB]{100,200,50}r}s!")
97 c.writePDFfile("test_text", paperformat=document.paperformat.A4)
99 c.insert(c.text(10, 4, r"""%
100 \fbox{\includegraphics[%
101 %type=eps, %% type of the file ... should not change anything --
102 % BUG!!!!!! size and filename information gets
103 % wrong when this is used ===> not supported!
104 %command=..., %% not supported!
105 %bb = 0 0 20 20, %% bounding box in original size
106 hiresbb=, %! read high resolution in original file (if not bb)
107 %viewport= 0 0 15 15, %% bounding box with respect to bb
108 %trim=1 1 1 1, %% correction of the bounding box with respect to bb
109 width=1in, %! final width
110 height=2in, %! final height
111 %totalheight=3in, %% final height+depth
112 %keepaspectratio=, %! keep aspect ratio, but do not exceed width nor height
113 angle=30, %! wraps around include
114 origin=tr, %% one or two chars of 'lrtcbB' (B for baseline)
115 %scale=2, %! wraps around rotating and include
116 %draft=, %% do not print anything,
117 clip=]% %! directly in dvi
118 {sample}}"""))
119 c.writeEPSfile("test_text", paperformat=document.paperformat.A4)