Skip to content

Commit 4ebe961

Browse files
author
sjw
committed
Typedef hd_wchar_t
1 parent f030714 commit 4ebe961

3 files changed

Lines changed: 21 additions & 38 deletions

File tree

include/hdtd/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "memento.h"
2727
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
2828

29+
typedef unsigned short hd_wchar_t;
30+
2931
#if defined(_MSC_VER) && (_MSC_VER < 1700) /* MSVC older than VS2012 */
3032
typedef signed char int8_t;
3133
typedef short int int16_t;

main.c

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
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
}

source/pdf/pdf-op-run.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pdf_show_char(hd_context *ctx, pdf_run_processor *pr, int cid)
3737

3838
if ((ctx->flush_size < 62) && cid > 0 && ucslen > 0)
3939
{
40-
wchar_t *wc = (wchar_t *)&ucsbuf[0];
40+
hd_wchar_t *wc = (hd_wchar_t *)&ucsbuf[0];
4141
switch (*wc)
4242
{
4343
case '/':
@@ -57,14 +57,14 @@ pdf_show_char(hd_context *ctx, pdf_run_processor *pr, int cid)
5757
|| (*wc >= 'A' && *wc <= 'Z')
5858
|| (*wc >= '0' && *wc <= '9')))
5959
{
60-
memcpy(ctx->contents + ctx->flush_size, (wchar_t *)&ucsbuf[0], 2);
60+
memcpy(ctx->contents + ctx->flush_size, (hd_wchar_t *)&ucsbuf[0], 2);
6161
ctx->flush_size += 2;
6262
}
6363
else if (isunicode)
6464
{
6565
if (*wc >= 0x4e00 && *wc <= 0x9fa5)
6666
{
67-
memcpy(ctx->contents + ctx->flush_size, (wchar_t *)&ucsbuf[0], 2);
67+
memcpy(ctx->contents + ctx->flush_size, (hd_wchar_t *)&ucsbuf[0], 2);
6868
ctx->flush_size += 2;
6969
}
7070
}

0 commit comments

Comments
 (0)