2 ## * << Haru Free PDF Library 2.0.0 >> -- encoding_list.c
4 ## * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
6 ## * Permission to use, copy, modify, distribute and sell this software
7 ## * and its documentation for any purpose is hereby granted without fee,
8 ## * provided that the above copyright notice appear in all copies and
9 ## * that both that copyright notice and this permission notice appear
10 ## * in supporting documentation.
11 ## * It is provided "as is" without express or implied warranty.
15 ## port to python by Li Jun
16 ## http://groups.google.com/group/pythoncia
24 path=os.path.normpath(os.path.split(os.path.realpath(__file__))[0]+'\..'*up)
25 if path not in sys.path:
31 from haru.c_func import *
32 from haru.hpdf_errorcode import *
35 @HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
36 def error_handler (error_no, detail_no, user_data):
38 printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
50 def draw_graph (page):
54 # Draw vertical lines.
55 HPDF_Page_SetLineWidth (page, 0.5)
58 x = i * CELL_WIDTH + 40
60 HPDF_Page_MoveTo (page, x, PAGE_HEIGHT - 60)
61 HPDF_Page_LineTo (page, x, 40)
62 HPDF_Page_Stroke (page)
64 if (i > 0 and i <= 16):
65 HPDF_Page_BeginText (page)
66 HPDF_Page_MoveTextPos (page, x + 5, PAGE_HEIGHT - 75)
68 HPDF_Page_ShowText (page, buf)
69 HPDF_Page_EndText (page)
71 # Draw horizontal lines.
73 y = i * CELL_HEIGHT + 40
75 HPDF_Page_MoveTo (page, 40, y)
76 HPDF_Page_LineTo (page, PAGE_WIDTH - 40, y)
77 HPDF_Page_Stroke (page)
80 HPDF_Page_BeginText (page)
81 HPDF_Page_MoveTextPos (page, 45, y + 5)
84 HPDF_Page_ShowText (page, buf)
85 HPDF_Page_EndText (page)
88 def draw_fonts (page):
89 HPDF_Page_BeginText (page)
91 # Draw all character from 0x20 to 0xFF to the canvas.
95 y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT)
96 x = j * CELL_WIDTH + 50
100 buf[0] = (i - 1) * 16 + (j - 1)
102 d = x - HPDF_Page_TextWidth (page, buf) / 2
103 HPDF_Page_TextOut (page, d, y, buf)
106 HPDF_Page_EndText (page)
137 pdf = HPDF_NewEx (error_handler, NULL, NULL, 0, NULL)
139 printf ("error: cannot create PdfDoc object\n")
142 fname=os.path.realpath(sys.argv[0])
143 fname=fname[:fname.rfind('.')]+'.pdf'
145 # set compression mode
146 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL)
148 # Set page mode to use outlines.
149 HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE)
152 font = HPDF_GetFont (pdf, "Helvetica", NULL)
155 font_name = HPDF_LoadType1FontFromFile (pdf, "type1/a010013l.afm",
156 "type1/a010013l.pfb")
158 # create outline root.
159 root = HPDF_CreateOutline (pdf, NULL, "Encoding list", NULL)
160 HPDF_Outline_SetOpened (root, HPDF_TRUE)
163 while (encodings[i]):
164 page = HPDF_AddPage (pdf)
166 HPDF_Page_SetWidth (page, PAGE_WIDTH)
167 HPDF_Page_SetHeight (page, PAGE_HEIGHT)
169 outline = HPDF_CreateOutline (pdf, root, encodings[i], NULL)
170 dst = HPDF_Page_CreateDestination (page)
171 HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1)
172 # HPDF_Destination_SetFitB(dst);
173 HPDF_Outline_SetDestination(outline, dst)
175 HPDF_Page_SetFontAndSize (page, font, 15)
178 HPDF_Page_BeginText (page)
179 HPDF_Page_SetFontAndSize (page, font, 20)
180 HPDF_Page_MoveTextPos (page, 40, PAGE_HEIGHT - 50)
181 HPDF_Page_ShowText (page, encodings[i])
182 HPDF_Page_ShowText (page, " Encoding")
183 HPDF_Page_EndText (page)
185 if encodings[i]=="Symbol-Set":
186 font2 = HPDF_GetFont (pdf, "Symbol", NULL)
187 elif encodings[i]=="ZapfDingbats-Set":
188 font2 = HPDF_GetFont (pdf, "ZapfDingbats", NULL)
190 font2 = HPDF_GetFont (pdf, font_name, encodings[i])
192 HPDF_Page_SetFontAndSize (page, font2, 14)
198 # save the document to a file
199 HPDF_SaveToFile (pdf, fname)