57
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <io.h>
|
|
5 #include <windows.h>
|
|
6 #include <xdw_api.h>
|
|
7 #include <xdwapian.h>
|
|
8
|
|
9 #define MAXLINE 12000
|
|
10 #define BLOCKSZ 128
|
|
11
|
|
12 void xdw2txt(const char* xdwfile, const char* txtfile) {
|
|
13 char in_path[_MAX_PATH];
|
|
14 _fullpath(in_path, xdwfile, _MAX_PATH);
|
|
15
|
|
16 XDW_DOCUMENT_HANDLE h = NULL;
|
|
17 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
|
|
18 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) {
|
|
19 printf("XDW Error: cannot open %s\n", xdwfile);
|
|
20 return;
|
|
21 }
|
|
22
|
|
23 int api_result = XDW_GetFullText(h, txtfile, NULL);
|
|
24 if (api_result < 0) {
|
|
25 printf("Error: cannot write text\n");
|
|
26 return;
|
|
27 }
|
|
28 XDW_CloseDocumentHandle(h, NULL);
|
|
29 }
|
|
30
|
|
31 void xdwsplit1(const char* xdwfile) {
|
|
32 char in_path[_MAX_PATH];
|
|
33 _fullpath(in_path, xdwfile, _MAX_PATH);
|
|
34
|
|
35 XDW_DOCUMENT_HANDLE h = NULL;
|
|
36 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_READONLY, XDW_AUTH_NODIALOGUE};
|
|
37 if (XDW_OpenDocumentHandle(in_path, &h, (XDW_OPEN_MODE*)&mode)) {
|
|
38 printf("Error: cannot open %s\n", xdwfile);
|
|
39 return;
|
|
40 }
|
|
41
|
|
42 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0, 0, 0};
|
|
43 XDW_GetDocumentInformation(h, &info);
|
|
44 int nPage = info.nPages;
|
|
45
|
|
46 char buf[_MAX_PATH];
|
|
47 for (int i = 1; i <= nPage; i++) {
|
|
48 sprintf(buf, "fwtmp_%05d.xdw", i);
|
|
49 _fullpath(in_path, buf, _MAX_PATH);
|
|
50
|
|
51 int api_result = XDW_GetPage(h, i, in_path, NULL);
|
|
52 if (api_result < 0) {
|
|
53 printf("XDW Error: cannot get page\n");
|
|
54 return;
|
|
55 }
|
|
56 }
|
|
57 XDW_CloseDocumentHandle(h, NULL);
|
|
58 }
|
|
59
|
|
60 void xdwmerge(const char* list, const char* output) {
|
|
61
|
|
62 FILE *fp;
|
|
63 if ((fp = fopen(list, "r")) == NULL) {
|
|
64 fprintf(stderr, "can't open file [%s]\n", list);
|
|
65 exit(1);
|
|
66 }
|
|
67
|
|
68 char *all_path = (char*)malloc(MAXLINE * sizeof(char) * _MAX_PATH);
|
|
69 if (all_path == NULL) {
|
|
70 fprintf(stderr, "can't allocate memory\n");
|
|
71 exit(1);
|
|
72 }
|
|
73
|
|
74 int n = 0;
|
|
75 char *q;
|
|
76 char buf[_MAX_PATH];
|
|
77
|
|
78 while (fgets(buf, sizeof buf, fp)) {
|
|
79 if ((q = strchr(buf, '\n')) != NULL) {
|
|
80 *q = '\0';
|
|
81 }
|
|
82 _fullpath(buf, buf, _MAX_PATH);
|
|
83 strncpy(&all_path[n * _MAX_PATH], buf, _MAX_PATH);
|
|
84 n++;
|
|
85 }
|
|
86 fclose(fp);
|
|
87
|
|
88 char *blk_path = (char*)malloc(BLOCKSZ * sizeof(char) * _MAX_PATH);
|
|
89 const char **blk_path_addr = (const char**)malloc((n / BLOCKSZ + 1) * sizeof(char*) * _MAX_PATH);
|
|
90 if (blk_path == NULL || blk_path_addr == NULL) {
|
|
91 fprintf(stderr, "can't allocate memory\n");
|
|
92 exit(1);
|
|
93 }
|
|
94
|
|
95 // process by block
|
|
96 int api_result;
|
|
97 int bn = 0;
|
|
98 for (int p = 0, m = 0; p < n; p++) {
|
|
99 m = p % BLOCKSZ;
|
|
100 if (m == 0 && p > 0) {
|
|
101 sprintf(buf, "fwtmp_b%04d.xdw", ++bn);
|
|
102 _fullpath(buf, buf, _MAX_PATH);
|
|
103 api_result = XDW_MergeXdwFiles(blk_path_addr, BLOCKSZ, buf, NULL);
|
|
104 if (api_result < 0) {
|
|
105 fprintf(stderr, "can't merge [1] (p = %d, m = %d)\n", p, m);
|
|
106 exit(1);
|
|
107 }
|
|
108 }
|
|
109 strncpy(&blk_path[m * _MAX_PATH], &all_path[p * _MAX_PATH], _MAX_PATH);
|
|
110 blk_path_addr[m] = &blk_path[m * _MAX_PATH];
|
|
111 }
|
|
112
|
|
113 sprintf(buf, "fwtmp_b%04d.xdw", ++bn);
|
|
114 _fullpath(buf, buf, _MAX_PATH);
|
|
115 int mod = n % BLOCKSZ;
|
|
116 if (mod == 0) mod = BLOCKSZ;
|
|
117 api_result = XDW_MergeXdwFiles(blk_path_addr, mod, buf, NULL);
|
|
118 if (api_result < 0) {
|
|
119 fprintf(stderr, "can't merge [2]\n");
|
|
120 exit(1);
|
|
121 }
|
|
122
|
|
123 // merge blocks
|
|
124 for (int b = 0; b < bn; b++) {
|
|
125 sprintf(buf, "fwtmp_b%04d.xdw", b + 1);
|
|
126 _fullpath(buf, buf, _MAX_PATH);
|
|
127 strncpy(&blk_path[b * _MAX_PATH], buf, _MAX_PATH);
|
|
128 blk_path_addr[b] = &blk_path[b * _MAX_PATH];
|
|
129 }
|
|
130 _fullpath(buf, output, _MAX_PATH );
|
|
131 api_result = XDW_MergeXdwFiles(blk_path_addr, bn, buf, NULL);
|
|
132 if (api_result < 0) {
|
|
133 fprintf(stderr, "can't merge [3]\n");
|
|
134 exit(1);
|
|
135 }
|
|
136
|
|
137 free(all_path);
|
|
138 free(blk_path);
|
|
139 free(blk_path_addr);
|
|
140 }
|
|
141
|
|
142 int xdwaddannotation(XDW_DOCUMENT_HANDLE h, int page, int x, int y, char* string, int* sz, int tr)
|
|
143 {
|
|
144 XDW_ANNOTATION_HANDLE annoation;
|
|
145 int api_result = XDW_AddAnnotation(h, XDW_AID_TEXT, page, x, y, NULL, &annoation, NULL);
|
|
146 if (api_result < 0) {
|
|
147 fprintf(stderr, "can't make annotation\n");
|
|
148 return -1;
|
|
149 }
|
|
150
|
|
151 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_Text, XDW_ATYPE_STRING, string, 0, NULL);
|
|
152 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_FontSize, XDW_ATYPE_INT, (char*)(sz), 0, NULL);
|
|
153 if (tr) {
|
|
154 int color = XDW_COLOR_NONE;
|
|
155 api_result = XDW_SetAnnotationAttribute(h, annoation, XDW_ATN_BackColor, XDW_ATYPE_INT, (char*)(&color), 0, NULL);
|
|
156 }
|
|
157 return 0;
|
|
158 }
|
|
159
|
|
160 void xdwaddpage(const char* file, int sp, int atena) {
|
|
161 XDW_DOCUMENT_HANDLE h = NULL;
|
|
162 XDW_OPEN_MODE_EX mode = {sizeof(XDW_OPEN_MODE_EX), XDW_OPEN_UPDATE, XDW_AUTH_NODIALOGUE};
|
|
163 int api_result = XDW_OpenDocumentHandle(file, &h, (XDW_OPEN_MODE*)&mode);
|
|
164 if (api_result < 0) {
|
|
165 fprintf(stderr, "can't open file\n");
|
|
166 exit(1);
|
|
167 }
|
|
168
|
|
169 XDW_DOCUMENT_INFO info = {sizeof(XDW_DOCUMENT_INFO), 0};
|
|
170 XDW_GetDocumentInformation(h, &info);
|
|
171 int last_page = info.nPages;
|
|
172
|
|
173 int sz = 80;
|
|
174 int tr = 1;
|
|
175 char pagenum[10];
|
|
176
|
|
177 for (int p = 0; p < last_page; p++) {
|
|
178 sprintf(pagenum, "FW-%05d", p + sp);
|
|
179 api_result = xdwaddannotation(h, p + 1, 8598, 335, pagenum, &sz, tr);
|
|
180 if (atena) api_result = xdwaddannotation(h, p + 1, 1270, 23615, pagenum, &sz, tr);
|
|
181 if (api_result < 0) break;
|
|
182 }
|
|
183
|
|
184 if (api_result >= 0) api_result = XDW_SaveDocument(h, NULL);
|
|
185
|
|
186 XDW_CloseDocumentHandle(h, NULL);
|
|
187 }
|
|
188
|