From: Matthias Kramm Date: Tue, 9 Feb 2010 03:17:28 +0000 (-0800) Subject: added new small font test X-Git-Tag: version-0-9-1~156 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=2ae4de9c7804375cae8f65a7b50c9469d017b45a;hp=d02e2539d1d9c7ecf37e57666e6561293baa2c90 added new small font test --- diff --git a/spec/textarea3.pdf b/spec/textarea3.pdf new file mode 100644 index 0000000..4e5f882 Binary files /dev/null and b/spec/textarea3.pdf differ diff --git a/spec/textarea3.py b/spec/textarea3.py new file mode 100644 index 0000000..556aa79 --- /dev/null +++ b/spec/textarea3.py @@ -0,0 +1,46 @@ +from sys import * +from pdflib_py import * +import md5 +import Image +import math + +img = Image.open("baboon.png") +width, height = img.size +img.load() + +p = PDF_new() +PDF_open_file(p, "textarea3.pdf") + +PDF_set_parameter(p, "usercoordinates", "true") + +PDF_set_info(p, "Creator", "smalltext.py") +PDF_begin_page(p, width, height) +font = PDF_load_font(p, "Courier", "host", "") + +PDF_setrgbcolor_fill(p, 0.0, 0.0, 0.0) +PDF_moveto(p, 0, 0) +PDF_lineto(p, width, 0) +PDF_lineto(p, width, height) +PDF_lineto(p, 0, height) +PDF_lineto(p, 0, 0) +PDF_fill(p) + +PDF_setfont(p, font, 4.0) +i = 0 +for y in range(height / 3): + text = "".join([md5.md5(str(i+j*732849)).hexdigest() for j in range(9)]) + for x in range(width / 3): + r,g,b = img.getpixel((x*3, height-1-y*3)) + l = math.sqrt(r*r+g*g+b*b) + if not r and not g and not b: + continue + white = l / 444.0 + PDF_setfont(p, font, 0.5+white*7) + PDF_setrgbcolor_fill(p, r/l, g/l, b/l) + PDF_set_text_pos(p, x*3, y*3); + PDF_show(p, text[x]) + i = i + 1 + +PDF_end_page(p) +PDF_close(p) +PDF_delete(p);