2 * << Haru Free PDF Library 2.0.0 >> -- font_demo.cpp
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.
26 error_handler (HPDF_STATUS error_no,
27 HPDF_STATUS detail_no,
30 printf ("ERROR: error_no=%04X, detail_no=%u\n",
31 (HPDF_UINT)error_no, (HPDF_UINT)detail_no);
33 throw std::exception ();
36 const char *font_list[] = {
40 "Courier-BoldOblique",
44 "Helvetica-BoldOblique",
54 int main (int argc, char **argv)
56 const char *page_title = "Font Demo";
66 strcpy (fname, argv[0]);
67 strcat (fname, ".pdf");
69 pdf = HPDF_New (error_handler, NULL);
71 printf ("error: cannot create PdfDoc object\n");
76 /* Add a new page object. */
77 page = HPDF_AddPage (pdf);
79 height = HPDF_Page_GetHeight (page);
80 width = HPDF_Page_GetWidth (page);
82 /* Print the lines of the page. */
83 HPDF_Page_SetLineWidth (page, 1);
84 HPDF_Page_Rectangle (page, 50, 50, width - 100, height - 110);
85 HPDF_Page_Stroke (page);
87 /* Print the title of the page (with positioning center). */
88 def_font = HPDF_GetFont (pdf, "Helvetica", NULL);
89 HPDF_Page_SetFontAndSize (page, def_font, 24);
91 tw = HPDF_Page_TextWidth (page, page_title);
92 HPDF_Page_BeginText (page);
93 HPDF_Page_MoveTextPos (page, (width - tw) / 2, height - 50);
94 HPDF_Page_ShowText (page, page_title);
95 HPDF_Page_EndText (page);
97 /* output subtitle. */
98 HPDF_Page_BeginText (page);
99 HPDF_Page_MoveTextPos (page, 60, height - 80);
100 HPDF_Page_SetFontAndSize (page, def_font, 16);
101 HPDF_Page_ShowText (page, "<Standerd Type1 fonts samples>");
102 HPDF_Page_EndText (page);
104 HPDF_Page_BeginText (page);
105 HPDF_Page_MoveTextPos (page, 60, height - 105);
108 while (font_list[i]) {
109 const char* samp_text = "abcdefgABCDEFG12345!#$%&+-@?";
110 HPDF_Font font = HPDF_GetFont (pdf, font_list[i], NULL);
112 /* print a label of text */
113 HPDF_Page_SetFontAndSize (page, def_font, 9);
114 HPDF_Page_ShowText (page, font_list[i]);
115 HPDF_Page_MoveTextPos (page, 0, -18);
117 /* print a sample text. */
118 HPDF_Page_SetFontAndSize (page, font, 20);
119 HPDF_Page_ShowText (page, samp_text);
120 HPDF_Page_MoveTextPos (page, 0, -20);
125 HPDF_Page_EndText (page);
127 HPDF_SaveToFile (pdf, fname);