2 * << Haru Free PDF Library 2.0.0 >> -- font_demo.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 const char *font_list[] = {
41 "Courier-BoldOblique",
45 "Helvetica-BoldOblique",
55 int main (int argc, char **argv)
57 const char *page_title = "Font Demo";
67 strcpy (fname, argv[0]);
68 strcat (fname, ".pdf");
70 pdf = HPDF_New (error_handler, NULL);
72 printf ("error: cannot create PdfDoc object\n");
81 /* Add a new page object. */
82 page = HPDF_AddPage (pdf);
84 height = HPDF_Page_GetHeight (page);
85 width = HPDF_Page_GetWidth (page);
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);
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);
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);
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);
107 HPDF_Page_BeginText (page);
108 HPDF_Page_MoveTextPos (page, 60, height - 105);
111 while (font_list[i]) {
112 const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
113 HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);
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);
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);
128 HPDF_Page_EndText (page);
130 HPDF_SaveToFile (pdf, fname);