2 * << Haru Free PDF Library 2.0.0 >> -- chfont_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.
20 #include "grid_sheet.h"
29 error_handler (HPDF_STATUS error_no,
30 HPDF_STATUS detail_no,
33 printf ("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no,
34 (HPDF_UINT)detail_no);
39 const char* FILE_SEPARATOR = "\\";
41 const char* FILE_SEPARATOR = "/";
45 main (int argc, char **argv)
53 const char *fcp936_name;
54 const char *fcp932_name;
60 printf ("chfont_demo <cp936-ttc-font-file-name> "
61 "<cp936-index> <cp932-ttc-font-file-name> <cp932-index>\n");
65 strcpy (fname, "mbtext");
66 strcat (fname, FILE_SEPARATOR);
67 strcat (fname, "cp932.txt");
68 cp932 = fopen (fname, "rb");
70 printf ("error: cannot open cp932.txt\n");
74 strcpy (fname, "mbtext");
75 strcat (fname, FILE_SEPARATOR);
76 strcat (fname, "cp936.txt");
77 cp936 = fopen (fname, "rb");
79 printf ("error: cannot open cp936.txt\n");
83 strcpy (fname, argv[0]);
84 strcat (fname, ".pdf");
86 pdf = HPDF_New (error_handler, NULL);
88 printf ("error: cannot create PdfDoc object\n");
97 HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
98 HPDF_UseJPEncodings (pdf);
99 HPDF_UseCNSEncodings (pdf);
101 fcp936_name = HPDF_LoadTTFontFromFile2 (pdf, argv[1], atoi(argv[2]),
103 fcp932_name = HPDF_LoadTTFontFromFile2 (pdf, argv[3], atoi(argv[4]),
106 /* add a new page object. */
107 page = HPDF_AddPage (pdf);
109 HPDF_Page_SetHeight (page, 300);
110 HPDF_Page_SetWidth (page, 550);
112 fcp936 = HPDF_GetFont (pdf, fcp936_name, "GBK-EUC-H");
113 fcp932 = HPDF_GetFont (pdf, fcp932_name, "90ms-RKSJ-H");
115 print_grid (pdf, page);
117 HPDF_Page_SetTextLeading (page, 20);
119 HPDF_Page_BeginText (page);
120 HPDF_Page_MoveTextPos (page, 50, 250);
121 HPDF_Page_SetTextLeading (page, 25);
123 while (fgets (buf, 1024, cp936)) {
124 HPDF_Page_SetFontAndSize (page, fcp936, 18);
125 buf [strlen (buf)] = 0;
126 HPDF_Page_ShowText (page, buf);
128 if (fgets (buf, 1024, cp932)) {
129 HPDF_Page_SetFontAndSize (page, fcp932, 18);
130 buf [strlen (buf)] = 0;
131 HPDF_Page_ShowText (page, buf);
134 HPDF_Page_MoveToNextLine (page);
137 /* save the document to a file */
138 HPDF_SaveToFile (pdf, fname);