added new small font test
[swftools.git] / spec / textarea3.py
1 from sys import * 
2 from pdflib_py import * 
3 import md5
4 import Image
5 import math
6
7 img = Image.open("baboon.png")
8 width, height = img.size
9 img.load()
10
11 p = PDF_new() 
12 PDF_open_file(p, "textarea3.pdf")
13
14 PDF_set_parameter(p, "usercoordinates", "true")
15
16 PDF_set_info(p, "Creator", "smalltext.py")
17 PDF_begin_page(p, width, height)
18 font = PDF_load_font(p, "Courier", "host", "")
19
20 PDF_setrgbcolor_fill(p, 0.0, 0.0, 0.0)
21 PDF_moveto(p, 0, 0)
22 PDF_lineto(p, width, 0)
23 PDF_lineto(p, width, height)
24 PDF_lineto(p, 0, height)
25 PDF_lineto(p, 0, 0)
26 PDF_fill(p)
27
28 PDF_setfont(p, font, 4.0)
29 i = 0
30 for y in range(height / 3):
31     text = "".join([md5.md5(str(i+j*732849)).hexdigest() for j in range(9)])
32     for x in range(width / 3):
33         r,g,b = img.getpixel((x*3, height-1-y*3))
34         l = math.sqrt(r*r+g*g+b*b)
35         if not r and not g and not b:
36             continue
37         white = l / 444.0
38         PDF_setfont(p, font, 0.5+white*7)
39         PDF_setrgbcolor_fill(p, r/l, g/l, b/l)
40         PDF_set_text_pos(p, x*3, y*3);
41         PDF_show(p, text[x])
42     i = i + 1
43
44 PDF_end_page(p)
45 PDF_close(p)
46 PDF_delete(p);