1#!/usr/bin/python
2# $Id: chartab.py 14574 2005-10-29 16:27:43Z bonefish $
3#
4# PDFlib client: hello character table in Python
5#
6
7from sys import *
8from pdflib_py import *
9
10# change these as required
11fontname = "LuciduxSans-Oblique"
12
13# This is where font/image/PDF input files live. Adjust as necessary.
14searchpath = "../data"
15
16# list of encodings to use
17encoding = ["iso8859-1", "iso8859-2", "iso8859-15"]
18
19# whether or not to embed the font
20embed = ""
21# embed = "not "
22embedding = "embedding"
23# embedding = ""
24
25ENCODINGS       = 3
26FONTSIZE        = 16
27TOP             = 700
28LEFT            = 50
29YINCR           = 2*FONTSIZE
30XINCR           = 2*FONTSIZE
31
32# create a new PDFlib object
33p = PDF_new()
34
35# open new PDF file
36if PDF_open_file(p, "chartab.pdf") == -1:
37    print "Error: " + PDF_get_errmsg(p) + "\n"
38    exit(2)
39
40PDF_set_parameter(p, "openaction", "fitpage")
41PDF_set_parameter(p, "fontwarning", "true")
42
43PDF_set_parameter(p, "SearchPath", searchpath)
44
45# This line is required to avoid problems on Japanese systems
46PDF_set_parameter(p, "hypertextencoding", "winansi")
47
48PDF_set_info(p, "Creator", "chartab.c")
49PDF_set_info(p, "Author", "Thomas Merz")
50PDF_set_info(p, "Title", "Character table (C)")
51
52# loop over all encodings
53for page in range(0, ENCODINGS, 1):
54    PDF_begin_page(p, 595, 842)		# start a new page
55
56    # print the heading and generate the bookmark
57    font = PDF_load_font(p, "Helvetica", "winansi", "")
58    PDF_setfont(p, font, FONTSIZE)
59    buf = fontname + " (" + encoding[page] + ") " + embed + "embedded"
60
61    PDF_show_xy(p, buf, LEFT - XINCR, TOP + 3 * YINCR)
62    PDF_add_bookmark(p, buf, 0, 0)
63
64    # print the row and column captions
65    PDF_setfont(p, font, 2 * FONTSIZE/3)
66
67    for row in range(0, 16, 1):
68	buf = "x" + repr(row)
69	PDF_show_xy(p, buf, LEFT + row*XINCR, TOP + YINCR)
70
71	buf = "x" + repr(row)
72	PDF_show_xy(p, buf, LEFT - XINCR, TOP - row * YINCR)
73
74    # print the character table
75    font = PDF_load_font(p, fontname, encoding[page], embedding)
76    PDF_setfont(p, font, FONTSIZE)
77
78    y = TOP
79    x = LEFT
80
81    for row in range(0, 16, 1):
82	for col in range(0, 16, 1):
83	    val = (16*row + col)
84	    if val != 0:
85		buf = chr(val)
86		PDF_show_xy(p, buf, x, y)
87	    x += XINCR
88	x = LEFT
89	y -= YINCR
90
91    PDF_end_page(p)                        # close page
92
93PDF_close(p)                               # close PDF document
94
95PDF_delete(p)                              # delete the PDFlib object
96