OSDN Git Service

binding with libharu.
[putex/putex.git] / src / texsourc / lib / libhpdf / demo / font_demo.c
1 /*
2  * << Haru Free PDF Library 2.0.0 >> -- font_demo.c
3  *
4  * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
5  *
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.
12  *
13  */
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <setjmp.h>
19 #include "hpdf.h"
20
21 jmp_buf env;
22
23 #ifdef HPDF_DLL
24 void  __stdcall
25 #else
26 void
27 #endif
28 error_handler (HPDF_STATUS   error_no,
29                HPDF_STATUS   detail_no,
30                void         *user_data)
31 {
32     printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
33                 (HPDF_UINT)detail_no);
34     longjmp(env, 1);
35 }
36
37 const char *font_list[] = {
38     "Courier",
39     "Courier-Bold",
40     "Courier-Oblique",
41     "Courier-BoldOblique",
42     "Helvetica",
43     "Helvetica-Bold",
44     "Helvetica-Oblique",
45     "Helvetica-BoldOblique",
46     "Times-Roman",
47     "Times-Bold",
48     "Times-Italic",
49     "Times-BoldItalic",
50     "Symbol",
51     "ZapfDingbats",
52     NULL
53 };
54
55 int main (int argc, char **argv)
56 {
57     const char *page_title = "Font Demo";
58     HPDF_Doc  pdf;
59     char fname[256];
60     HPDF_Page page;
61     HPDF_Font def_font;
62     HPDF_REAL tw;
63     HPDF_REAL height;
64     HPDF_REAL width;
65     HPDF_UINT i;
66
67     strcpy (fname, argv[0]);
68     strcat (fname, ".pdf");
69
70     pdf = HPDF_New (error_handler, NULL);
71     if (!pdf) {
72         printf ("error: cannot create PdfDoc object\n");
73         return 1;
74     }
75
76     if (setjmp(env)) {
77         HPDF_Free (pdf);
78         return 1;
79     }
80
81     /* Add a new page object. */
82     page = HPDF_AddPage (pdf);
83
84     height = HPDF_Page_GetHeight (page);
85     width = HPDF_Page_GetWidth (page);
86
87     /* Print the lines of the page. */
88     HPDF_Page_SetLineWidth (page, 1);
89     HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
90     HPDF_Page_Stroke (page);
91
92     /* Print the title of the page (with positioning center). */
93     def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
94     HPDF_Page_SetFontAndSize (page, def_font, 24);
95
96     tw = HPDF_Page_TextWidth (page, page_title);
97     HPDF_Page_BeginText (page);
98     HPDF_Page_TextOut (page, (width - tw) / 2, height - 50, page_title);
99     HPDF_Page_EndText (page);
100
101     /* output subtitle. */
102     HPDF_Page_BeginText (page);
103     HPDF_Page_SetFontAndSize (page, def_font, 16);
104     HPDF_Page_TextOut (page, 60, height - 80, "<Standerd Type1 fonts samples>");
105     HPDF_Page_EndText (page);
106
107     HPDF_Page_BeginText (page);
108     HPDF_Page_MoveTextPos (page, 60, height - 105);
109
110     i = 0;
111     while (font_list[i]) {
112         const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
113         HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);
114
115         /* print a label of text */
116         HPDF_Page_SetFontAndSize (page, def_font, 9);
117         HPDF_Page_ShowText (page, font_list[i]);
118         HPDF_Page_MoveTextPos (page, 0, -18);
119
120         /* print a sample text. */
121         HPDF_Page_SetFontAndSize (page, font, 20);
122         HPDF_Page_ShowText (page, samp_text);
123         HPDF_Page_MoveTextPos (page, 0, -20);
124
125         i++;
126     }
127
128     HPDF_Page_EndText (page);
129
130     HPDF_SaveToFile (pdf, fname);
131
132     /* clean up */
133     HPDF_Free (pdf);
134
135     return 0;
136 }
137