more tests run again
[PyX/mjg.git] / test / functional / test_text.py
blob965d6e79e0fa7fcc1df96788dbb991ee3562abbe
1 #!/usr/bin/env python
2 import sys; sys.path[:0] = ["../.."]
4 from pyx import *
5 from pyx import text
7 c = canvas.canvas()
8 text.set(mode="latex")
9 text.preamble(r"""%
10 \usepackage{graphicx}
11 \usepackage{color}
12 \usepackage{rotating}
13 \usepackage{helvet}
14 % \graphicspath{{eps/}}
16 \definecolor{col0}{gray}{0.1}
17 \definecolor{col1}{cmyk}{0.3, 0.2, 0.1, 0.1}
18 \definecolor{col2}{rgb}{0.4, 0.3, 0.1}
19 \definecolor{col3}{RGB}{200, 200, 200}
20 \definecolor{col4}{hsb}{0.1, 0.1, 0.1}
21 \definecolor{col5}{named}{Red}
22 % \definecolor{col6}{pyx}{Some-PyX-Colour}
23 \definecolor{col0}{gray}{0.5}""", text.texmessage.ignore)
25 c.stroke(path.line(-1, 0, 6, 0))
27 c.stroke(path.line(6, 5, 6.99, 5), style.linewidth.THIN)
28 c.stroke(path.line(6, 6, 6.99, 6), style.linewidth.THIN)
29 c.stroke(path.line(8.01, 5, 9, 5), style.linewidth.THIN)
30 c.stroke(path.line(8.01, 6, 9, 6), style.linewidth.THIN)
31 c.stroke(path.line(7, 4, 7, 4.99), style.linewidth.THIN)
32 c.stroke(path.line(8, 4, 8, 4.99), style.linewidth.THIN)
33 c.stroke(path.line(7, 6.01, 7, 7), style.linewidth.THIN)
34 c.stroke(path.line(8, 6.01, 8, 7), style.linewidth.THIN)
35 c.text(7, 5, "\\vrule width1truecm height1truecm")
37 c.text(6.2, 0, "0", text.vshift.middlezero)
38 c.text(-1.2, 0, "abc", text.vshift.mathaxis, text.halign.right)
40 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), text.valign.bottombaseline)
41 c.insert(t1)
42 c.stroke(t1.path())
44 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)))
45 c.stroke(t2.path())
46 c.stroke(path.line(*(t1.marker("beforeb") + t2.marker("beforeb"))), color.rgb.red)
47 c.stroke(path.line(*(t1.marker("afterb") + t2.marker("afterb"))), color.rgb.green)
49 c.text(0, 3, r"\int\limits_{-\infty}^\infty \!{\rm d}x\, e^{-a x^2} = \sqrt{\pi\over a}", text.mathmode)
50 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)
52 c.stroke(c.text(1, 2, r"Hello, world!").path())
54 # test a virtual font with encoding
55 c.text(0, 8, r"\sffamily VF test: \"o\ss ffl \char0")
56 c.text(0, 9, r"\sffamily \fontsize{30}{35}\selectfont VF test: \"o\ss ffl \char0")
58 # test the specials
59 c.stroke(c.text(10, 2, r"Hello, \color{green}world!", trafo.slant(1)).path())
60 c.stroke(c.text(10, 0, r"\begin{rotate}{90}\parbox{5cm}{rotated\\ in \LaTeX}\end{rotate}"))
62 d = canvas.canvas()
63 d.stroke(path.rect(0,0, 1,1))
64 d.stroke(path.line(0,0, 1,1))
65 d.stroke(path.line(1,0, 0,1))
66 d.writetofile("sample")
67 c.stroke(c.text(10, 4, r"""%
68 \fbox{\includegraphics[%
69 %type=eps, %% type of the file ... should not change anything --
70 % BUG!!!!!! size and filename information gets
71 % wrong when this is used ===> not supported!
72 %command=..., %% not supported!
73 %bb = 0 0 20 20, %% bounding box in original size
74 hiresbb=, %! read high resolution in original file (if not bb)
75 %viewport= 0 0 15 15, %% bounding box with respect to bb
76 %trim=1 1 1 1, %% correction of the bounding box with respect to bb
77 width=1in, %! final width
78 height=2in, %! final height
79 %totalheight=3in, %% final height+depth
80 %keepaspectratio=, %! keep aspect ratio, but do not exceed width nor height
81 angle=30, %! wraps around include
82 origin=tr, %% one or two chars of 'lrtcbB' (B for baseline)
83 %scale=2, %! wraps around rotating and include
84 %draft=, %% do not print anything,
85 clip=]% %! directly in dvi
86 {sample}}""", text.texmessage.graphicsload))
87 c.stroke(c.text(10, 0, r"""
88 \textcolor{col0}{abc}
89 \textcolor{col1}{abc}
90 \textcolor{col2}{abc}
91 \textcolor{col3}{abc}
92 \textcolor{col4}{abc}
93 \textcolor{col5}{abc}
94 % \textcolor{col6}{abc}%
95 """, text.parbox(3)))
96 c.stroke(c.text(15, 0, r"""
97 \colorbox{col2}{ColorBox}\\
98 \fcolorbox{col3}{col4}{FColorBox}"""))
100 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!")
102 c.writetofile("test_text", paperformat="a4")