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.
28 error_handler (HPDF_STATUS error_no,
29 HPDF_STATUS detail_no,
32 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
33 (HPDF_UINT)detail_no);
37 static const int PAGE_WIDTH = 420;
38 static const int PAGE_HEIGHT = 400;
39 static const int CELL_WIDTH = 20;
40 static const int CELL_HEIGHT = 20;
41 static const int CELL_HEADER = 10;
44 draw_graph (HPDF_Page page);
48 draw_fonts (HPDF_Page page);
52 draw_graph (HPDF_Page page)
57 /* Draw 16 X 15 cells */
59 /* Draw vertical lines. */
60 HPDF_Page_SetLineWidth (page, 0.5);
62 for (i = 0; i <= 17; i++) {
63 int x = i * CELL_WIDTH + 40;
65 HPDF_Page_MoveTo (page, x, PAGE_HEIGHT - 60);
66 HPDF_Page_LineTo (page, x, 40);
67 HPDF_Page_Stroke (page);
69 if (i > 0 && i <= 16) {
70 HPDF_Page_BeginText (page);
71 HPDF_Page_MoveTextPos (page, x + 5, PAGE_HEIGHT - 75);
73 _snprintf(buf, 5, "%X", i - 1);
75 snprintf(buf, 5, "%X", i - 1);
77 HPDF_Page_ShowText (page, buf);
78 HPDF_Page_EndText (page);
82 /* Draw horizontal lines. */
83 for (i = 0; i <= 15; i++) {
84 int y = i * CELL_HEIGHT + 40;
86 HPDF_Page_MoveTo (page, 40, y);
87 HPDF_Page_LineTo (page, PAGE_WIDTH - 40, y);
88 HPDF_Page_Stroke (page);
91 HPDF_Page_BeginText (page);
92 HPDF_Page_MoveTextPos (page, 45, y + 5);
94 _snprintf(buf, 5, "%X", 15 - i);
96 snprintf(buf, 5, "%X", 15 - i);
98 HPDF_Page_ShowText (page, buf);
99 HPDF_Page_EndText (page);
106 draw_fonts (HPDF_Page page)
111 HPDF_Page_BeginText (page);
113 /* Draw all character from 0x20 to 0xFF to the canvas. */
114 for (i = 1; i < 17; i++) {
115 for (j = 1; j < 17; j++) {
116 unsigned char buf[2];
117 int y = PAGE_HEIGHT - 55 - ((i - 1) * CELL_HEIGHT);
118 int x = j * CELL_WIDTH + 50;
122 buf[0] = (i - 1) * 16 + (j - 1);
126 d = x - HPDF_Page_TextWidth (page, (char*)buf) / 2;
127 HPDF_Page_TextOut (page, d, y, (char*)buf);
133 HPDF_Page_EndText (page);
137 int main (int argc, char **argv)
142 const char *font_name;
146 const char *encodings[] = {
171 pdf = HPDF_NewEx (error_handler, NULL, NULL, 0, NULL);
173 printf ("error: cannot create PdfDoc object\n");
182 strcpy (fname, argv[0]);
183 strcat (fname, ".pdf");
185 /* set compression mode */
186 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
188 /* Set page mode to use outlines. */
189 HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);
191 /* get default font */
192 font = HPDF_GetFont (pdf, "Helvetica", NULL);
194 /* load font object */
196 font_name = HPDF_LoadType1FontFromFile (pdf, "type1\\a010013l.afm",
197 "type1\\a010013l.pfb");
199 font_name = HPDF_LoadType1FontFromFile (pdf, "type1/a010013l.afm",
200 "type1/a010013l.pfb");
203 /* create outline root. */
204 root = HPDF_CreateOutline (pdf, NULL, "Encoding list", NULL);
205 HPDF_Outline_SetOpened (root, HPDF_TRUE);
207 while (encodings[i]) {
208 HPDF_Page page = HPDF_AddPage (pdf);
209 HPDF_Outline outline;
210 HPDF_Destination dst;
213 HPDF_Page_SetWidth (page, PAGE_WIDTH);
214 HPDF_Page_SetHeight (page, PAGE_HEIGHT);
216 outline = HPDF_CreateOutline (pdf, root, encodings[i], NULL);
217 dst = HPDF_Page_CreateDestination (page);
218 HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1);
219 /* HPDF_Destination_SetFitB(dst); */
220 HPDF_Outline_SetDestination(outline, dst);
222 HPDF_Page_SetFontAndSize (page, font, 15);
225 HPDF_Page_BeginText (page);
226 HPDF_Page_SetFontAndSize (page, font, 20);
227 HPDF_Page_MoveTextPos (page, 40, PAGE_HEIGHT - 50);
228 HPDF_Page_ShowText (page, encodings[i]);
229 HPDF_Page_ShowText (page, " Encoding");
230 HPDF_Page_EndText (page);
232 if (strcmp (encodings[i], "Symbol-Set") == 0)
233 font2 = HPDF_GetFont (pdf, "Symbol", NULL);
234 else if (strcmp (encodings[i], "ZapfDingbats-Set") == 0)
235 font2 = HPDF_GetFont (pdf, "ZapfDingbats", NULL);
237 font2 = HPDF_GetFont (pdf, font_name, encodings[i]);
239 HPDF_Page_SetFontAndSize (page, font2, 14);
245 /* save the document to a file */
246 HPDF_SaveToFile (pdf, fname);