11#include "hdtd.h"
2- #include <ctype.h>
3- //============ patch get first char
4- static unsigned patch_get_first_char (wchar_t * unicode ) {
5- char buf [4 ];
6- wchar_t wc = unicode [0 ];
7- //Is it a letter?
8- if ((wc >= 'a' && wc <= 'z' ) || (wc >= 'A' && wc <= 'Z' ))
9- wc = toupper (unicode [0 ]);
10-
11- int size = wctomb (buf , wc );
12- //int size=wctomb(buf,toupper(unicode[0]));
13- if (size > 0 ) {
14- return (unsigned char )buf [0 ];
15- }
16- else {
17- return toupper (unicode [0 ]);
18- }
19- }
202//================ patch unicode to utf8 ==================
21- static int to_utf8 (char * buf , wchar_t c , int buf_size ) {
3+ static int to_utf8 (char * buf , hd_wchar_t c , int buf_size ) {
224 int size = 0 ;
235 //0x0000-0x007f
246 if (c < 0x80 ) {
@@ -73,7 +55,7 @@ static int to_utf8(char *buf, wchar_t c, int buf_size) {
7355
7456 return size ;
7557}
76- static int unicode_to_utf8 (char * buf , wchar_t * unicode , int buf_size ) {
58+ static int unicode_to_utf8 (char * buf , hd_wchar_t * unicode , int buf_size ) {
7759 char * p = buf ;
7860 int total_size = 0 ;
7961 //Used to store'\0'
@@ -115,33 +97,33 @@ int main() {
11597
11698 /* Open the document. */
11799 hd_try (ctx )
118- doc = hd_open_document (ctx , "F:/pdf/file98 .pdf" );
100+ doc = hd_open_document (ctx , "/Users/sjw/Documents/debugfile/f0711656 .pdf" );
119101 hd_catch (ctx ) {
120102 fprintf (stderr , "cannot open document: %s\n" , hd_caught_message (ctx ));
121103 hd_drop_context (ctx );
122104 return EXIT_FAILURE ;
123105 }
124- hd_page * page ;
125- hd_try (ctx )
126- page = hd_load_page (ctx , doc , 0 );
127- hd_catch (ctx ) {
128- fprintf (stderr , "cannot load page: %s\n" , hd_caught_message (ctx ));
129- hd_drop_context (ctx );
130- return EXIT_FAILURE ;
131- }
106+
107+ hd_page * page = hd_load_page (ctx , doc , 0 );
132108 char buf [512 ] = {0 };
133109
134110 hd_try (ctx )
135111 {
136112 hd_run_page_contents (ctx , page , buf );
137113 unsigned char filenameUtf8 [128 ];
138114 memset (filenameUtf8 , 0 , 128 );
139- unicode_to_utf8 (filenameUtf8 , buf , 32 );
140- FILE * fp ;
115+ unsigned int len ;
116+ len = (ctx -> flush_size > 32 ) ? 32 : ctx -> flush_size ;
117+ if (len > 0 )
118+ {
119+ unicode_to_utf8 (filenameUtf8 , (hd_wchar_t * )buf , len );
120+ FILE * fp ;
121+
122+ fp = fopen ("/Users/sjw/Documents/debugfile/test.txt" ,"a+" );
123+ fprintf (fp ,"%s" ,filenameUtf8 );
124+ fclose (fp );
125+ }
141126
142- fp = fopen ("F:/test.txt" ,"a+" );
143- fprintf (fp ,"%s" ,filenameUtf8 );
144- fclose (fp );
145127 }
146128 hd_catch (ctx )
147129 {
@@ -153,5 +135,4 @@ int main() {
153135 hd_drop_document (ctx , doc );
154136 hd_drop_context (ctx );
155137 printf ("hd_new_context is end\n" );
156- return 0 ;
157138}
0 commit comments