aboutsummaryrefslogtreecommitdiffstats
path: root/src/cnki_pdf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cnki_pdf.c')
-rw-r--r--src/cnki_pdf.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c
index 372c5da..45f5324 100644
--- a/src/cnki_pdf.c
+++ b/src/cnki_pdf.c
@@ -218,7 +218,7 @@ cnki_pdf(cnki_t **param)
if ((*param)->stat > 0)
printf("Discovered %d parent object(s)\n", parent[0]);
- int *parent_missing = malloc(parent[0] * sizeof(int));
+ int8_t *parent_missing = malloc(parent[0] * sizeof(int8_t));
if (parent_missing == NULL)
return 1;
@@ -343,7 +343,7 @@ cnki_pdf(cnki_t **param)
strcat(dictionary, "[");
for (int i = 0, j = 0; i < parent[0]; i++) {
- if (parent_missing[i]) {
+ if (parent_missing[i] == 1) {
snprintf(buf, 64, "%d 0 R", parent[i + 1]);
strcat(dictionary, buf);
@@ -793,15 +793,11 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/F0 10 Tf\n");
for (int i = 0, j = 0; i < ptr->text_size - 1;) {
- switch (ptr->text[i]) {
- case 0x01:
- if (ptr->address_next <= ptr->address) {
- i += 2;
- break;
- }
-
- strcat(dictionary, "T*\n");
- case 0x70:
+ switch (((unsigned char) ptr->text[i + 1] << 8) + (unsigned char) ptr->text[i]) {
+ case 0x8001:
+ if (ptr->address_next > ptr->address)
+ strcat(dictionary, "T*\n");
+ case 0x8070:
if (ptr->address_next > ptr->address) {
i += 4;
@@ -867,9 +863,12 @@ cnki_pdf_hn(cnki_t **param)
i += 8;
break;
- case 0x0a:
+ case 0x800a:
if (i + 27 >= ptr->text_size || j >= ptr->image_length) {
i += 2;
+
+ if (j >= ptr->image_length)
+ i += 26;
break;
}
@@ -896,7 +895,9 @@ cnki_pdf_hn(cnki_t **param)
}
i += 28;
- j++;
+
+ if (j == 0 || ptr->image_data[j].x > 0 || ptr->image_data[j].y > 0)
+ j++;
break;
default:
i += 4;
@@ -915,10 +916,10 @@ cnki_pdf_hn(cnki_t **param)
double resize_x = 1;
double resize_y = 1;
- if (dim[0] > 0 && dim[1] > 0) {
+ if (ptr->image_data[0].x == 0 && ptr->image_data[0].y == 0 && dim[0] > 0 && dim[1] > 0) {
/* Scale within bound of A4 paper */
- resize_x = 4 * 595.2756 / dim[0];
- resize_y = 4 * 841.8898 / dim[1];
+ resize_x = 2381.102 / dim[0];
+ resize_y = 3367.559 / dim[1];
if (resize_y < resize_x)
snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
@@ -948,9 +949,9 @@ cnki_pdf_hn(cnki_t **param)
}
/* Translate figure */
- if (i > 0) {
- double origin_x = 0.4043339 * ptr->image_data[i].x;
- double origin_y = 0.4043273 * ptr->image_data[i].y;
+ if (ptr->image_data[i].x > 0 || ptr->image_data[i].y > 0) {
+ double origin_x = ptr->image_data[i].x * dim[i * 2] / ptr->image_data[i].w;
+ double origin_y = ptr->image_data[i].y * dim[i * 2 + 1] / ptr->image_data[i].h;
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1)
origin_y = -3367.559 + origin_y + dim[i * 2 + 1];