fixed memory realloc issue in xpdf
[swftools.git] / spec / textposition.py
1 from sys import * 
2 from pdflib_py import * 
3 from math import sin,cos
4 p = PDF_new() 
5 PDF_open_file(p, "textposition.pdf")
6
7 PDF_set_parameter(p, "usercoordinates", "true")
8
9 width = 612
10 height = 500
11 PDF_begin_page(p, width, height)
12
13 font = PDF_load_font(p, "Helvetica-Bold", "host", "")
14
15 PDF_setfont(p, font, 18.0)
16
17 a=0.7
18 b=-0.7
19 matrices = [[1,0,0,1,100,200],
20             [cos(a),sin(a),-sin(a),cos(a),400,75],
21             [1,0,0,-1,100,350],
22             [-1,0,0,1,450,270],
23             [1.9,0.5,0.6,1.4,50,-140],
24             [cos(b),sin(b),sin(b),-cos(b),100,300],
25             [1.0,0,0,5,-90,-200],
26            ]
27
28 for m in matrices:
29     PDF_save(p)
30     PDF_setmatrix(p, m[0],m[1],m[2],m[3],m[4],m[5])
31     x,y = 100,100
32     PDF_set_text_pos(p, x,y)
33     w = PDF_stringwidth(p, "HELLO WORLD", font, 18.0)
34     h = 18.0 - 4
35     PDF_setrgbcolor_fill(p, 0.0, 0.0, 0.0)
36     PDF_show(p, "HELLO WORLD")
37
38     PDF_setrgbcolor_fill(p, 0.0, 0.0, 1.0)
39     PDF_moveto(p, x,y)
40     PDF_lineto(p, x+w,y)
41     PDF_lineto(p, x+w,y+h)
42     PDF_lineto(p, x,y+h)
43     PDF_lineto(p, x,y)
44     PDF_moveto(p, x-20,y-20)
45     PDF_lineto(p, x-20,y+20+h)
46     PDF_lineto(p, x+20+w,y+20+h)
47     PDF_lineto(p, x+20+w,y-20)
48     PDF_lineto(p, x-20,y-20)
49     PDF_fill(p);
50     PDF_restore(p)
51
52 PDF_end_page(p)
53 PDF_close(p)
54 PDF_delete(p);