rewrite VF scaling code to fix kerning
[PyX.git] / test / functional / test_text.py
blobe63d9d882b49ba3b3023bb1020c80ddf6d42ec24
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}{pyx.color.cmyk.PineGreen}
22 \definecolor{col7}{pyx}{color.cmyk(0.92, 0, 0.59, 0.25)}
23 \definecolor{col0}{gray}{0.5}""")
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, baseline=text.parbox.bottom)])
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, baseline=text.parbox.top)]))
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\char0")
56 c.text(0, 9, r"\sffamily \fontsize{30}{35}\selectfont VF test: \"o\ss ffl \char0\char0")
58 # scaling test
59 unit.set(xscale=2)
60 t = c.text(0, 11, r"scale test", [color.rgb.green])
61 unit.set(xscale=1)
62 t = c.text(0, 11, r"scale test", [color.rgb.red])
64 # test font stripping (proper usedchar selection)
65 from pyx.dvi import mapfile
66 fontmap = mapfile.readfontmap(["download35.map"])
67 c.text(0, 12, r"usechar test (``fl'' should be typed):")
68 myrunner = text.texrunner()
69 myrunner.preamble(r"\font\pyxfont=phvr8t\pyxfont")
70 c.insert(myrunner.text(5.5, 12, r"\char'035", fontmap=fontmap))
72 myrunner2 = text.texrunner()
73 myrunner2.preamble(r"\font\pyxfont=ptmr8t\pyxfont")
74 c.insert(myrunner2.text(6.5, 12, r"\char'035", fontmap=fontmap))
76 # test the specials
77 c.stroke(c.text(10, 2, r"Hello, \color{green}world!", [trafo.slant(1)]).path())
78 c.insert(c.text(10, 0, r"\begin{rotate}{90}\parbox{5cm}{rotated\\ in \LaTeX}\end{rotate}"))
80 d = canvas.canvas()
81 d.stroke(path.rect(0,0, 1,1))
82 d.stroke(path.line(0,0, 1,1))
83 d.stroke(path.line(1,0, 0,1))
84 d.writeEPSfile("eps/sample")
85 c.insert(c.text(10, 0, r"""
86 \textcolor{col0}{col0}
87 \textcolor{col1}{col1}
88 \textcolor{col2}{col2}
89 \textcolor{col3}{col3}
90 \textcolor{col4}{col4}
91 \textcolor{col5}{col5}
92 \textcolor{col6}{col6}
93 \textcolor{col7}{col7}%
94 """, [text.parbox(3.5)]))
95 c.insert(c.text(15, 0, r"""
96 \colorbox{col1}{ColorBox}\\
97 \fcolorbox{col5}{col6}{FColorBox}"""))
99 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!")
101 c.writePDFfile("test_text", paperformat=document.paperformat.A4)
103 c.insert(c.text(10, 4, r"""%
104 \fbox{\includegraphics[%
105 %type=eps, %% type of the file ... should not change anything --
106 % BUG!!!!!! size and filename information gets
107 % wrong when this is used ===> not supported!
108 %command=..., %% not supported!
109 bb = 0 0 25 25, %% bounding box in original size
110 hiresbb=, %! read high resolution in original file (if not bb)
111 %viewport= 0 0 15 15, %% bounding box with respect to bb
112 %trim=1 1 1 1, %% correction of the bounding box with respect to bb
113 width=1in, %! final width
114 height=2in, %! final height
115 %totalheight=3in, %% final height+depth
116 %keepaspectratio=, %! keep aspect ratio, but do not exceed width nor height
117 angle=30, %! wraps around include
118 origin=tr, %% one or two chars of 'lrtcbB' (B for baseline)
119 %scale=2, %! wraps around rotating and include
120 %draft=, %% do not print anything,
121 clip=]% %! directly in dvi
122 {sample}}"""))
123 c.writeEPSfile("test_text", paperformat=document.paperformat.A4)