2 * << Haru Free PDF Library 2.0.0 >> -- ttfont_demo_jp.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 int main (int argc, char **argv)
43 HPDF_Font detail_font;
44 HPDF_UINT page_height;
48 const char *detail_font_name;
52 printf ("ttfont_jp_demo <ttf-font-filename> [-E]\n");
53 printf ("ttfont_jp_demo <ttc-font-filename> <index> [-E]\n");
58 f = fopen ("mbtext\\sjis.txt", "rb");
60 f = fopen ("mbtext/sjis.txt", "rb");
64 printf ("error: cannot open 'mbtext/sjis.txt'\n");
68 fgets (SAMP_TXT, 2048, f);
71 strcpy (fname, argv[0]);
72 strcat (fname, ".pdf");
74 pdf = HPDF_New (error_handler, NULL);
76 printf ("error: cannot create PdfDoc object\n");
85 /* declaration for using Japanese encoding. */
86 HPDF_UseJPEncodings (pdf);
88 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
91 if (argc == 4 && strcmp (argv[3], "-E") == 0)
92 detail_font_name = HPDF_LoadTTFontFromFile2 (pdf, argv[1],
93 atoi (argv[2]), HPDF_TRUE);
94 else if (argc == 3 && strcmp (argv[2], "-E") == 0)
95 detail_font_name = HPDF_LoadTTFontFromFile (pdf, argv[1], HPDF_TRUE);
97 detail_font_name = HPDF_LoadTTFontFromFile2 (pdf, argv[1],
98 atoi (argv[2]), HPDF_FALSE);
100 detail_font_name = HPDF_LoadTTFontFromFile (pdf, argv[1], HPDF_FALSE);
102 /* add a new page object. */
103 page = HPDF_AddPage (pdf);
105 title_font = HPDF_GetFont (pdf, "Helvetica", NULL);
107 detail_font = HPDF_GetFont (pdf, detail_font_name, "90msp-RKSJ-H");
109 HPDF_Page_SetFontAndSize (page, title_font, 10);
111 HPDF_Page_BeginText (page);
113 /* move the position of the text to top of the page. */
114 HPDF_Page_MoveTextPos(page, 10, 190);
115 HPDF_Page_ShowText (page, detail_font_name);
116 HPDF_Page_ShowText (page, " (");
117 HPDF_Page_ShowText (page, HPDF_Font_GetEncodingName (detail_font));
118 HPDF_Page_ShowText (page, ")");
120 HPDF_Page_SetFontAndSize (page, detail_font, 15);
121 HPDF_Page_MoveTextPos (page, 10, -20);
122 HPDF_Page_ShowText (page, "abcdefghijklmnopqrstuvwxyz");
123 HPDF_Page_MoveTextPos (page, 0, -20);
124 HPDF_Page_ShowText (page, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
125 HPDF_Page_MoveTextPos (page, 0, -20);
126 HPDF_Page_ShowText (page, "1234567890");
127 HPDF_Page_MoveTextPos (page, 0, -20);
129 HPDF_Page_SetFontAndSize (page, detail_font, 10);
130 HPDF_Page_ShowText (page, SAMP_TXT);
131 HPDF_Page_MoveTextPos (page, 0, -18);
133 HPDF_Page_SetFontAndSize (page, detail_font, 16);
134 HPDF_Page_ShowText (page, SAMP_TXT);
135 HPDF_Page_MoveTextPos (page, 0, -27);
137 HPDF_Page_SetFontAndSize (page, detail_font, 23);
138 HPDF_Page_ShowText (page, SAMP_TXT);
139 HPDF_Page_MoveTextPos (page, 0, -36);
141 HPDF_Page_SetFontAndSize (page, detail_font, 30);
142 HPDF_Page_ShowText (page, SAMP_TXT);
143 HPDF_Page_MoveTextPos (page, 0, -36);
145 pw = HPDF_Page_TextWidth (page, SAMP_TXT);
147 page_width = pw + 40;
149 HPDF_Page_SetWidth (page, page_width);
150 HPDF_Page_SetHeight (page, page_height);
152 /* finish to print text. */
153 HPDF_Page_EndText (page);
155 HPDF_Page_SetLineWidth (page, 0.5);
157 HPDF_Page_MoveTo (page, 10, page_height - 25);
158 HPDF_Page_LineTo (page, page_width - 10, page_height - 25);
159 HPDF_Page_Stroke (page);
161 HPDF_Page_MoveTo (page, 10, page_height - 85);
162 HPDF_Page_LineTo (page, page_width - 10, page_height - 85);
163 HPDF_Page_Stroke (page);
165 HPDF_SaveToFile (pdf, fname);