aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-30 02:00:12 +0000
committeryzrh <yzrh@noema.org>2022-12-30 02:00:12 +0000
commit5466a441dfad627063ae498ed7359f1af9fb8de7 (patch)
tree90aaf94a8cacfe58e9a9188fcabaa558a4ba92e9 /src
parent1ce3f89574fa7256ab019eefc96a7362165cca52 (diff)
downloadmelon-5466a441dfad627063ae498ed7359f1af9fb8de7.tar.gz
melon-5466a441dfad627063ae498ed7359f1af9fb8de7.tar.zst
Fix type casting when processing data.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r--src/cnki.h8
-rw-r--r--src/cnki_jbig.h4
-rw-r--r--src/cnki_pdf.c50
3 files changed, 31 insertions, 31 deletions
diff --git a/src/cnki.h b/src/cnki.h
index e9cc5d1..7d7d15e 100644
--- a/src/cnki.h
+++ b/src/cnki.h
@@ -58,10 +58,10 @@ typedef struct _hn_image_t {
int32_t format; /* hn_code */
int32_t address;
int32_t size;
- int16_t x;
- int16_t y;
- int16_t w;
- int16_t h;
+ uint16_t x;
+ uint16_t y;
+ uint16_t w;
+ uint16_t h;
char *image;
} hn_image_t;
diff --git a/src/cnki_jbig.h b/src/cnki_jbig.h
index 701b4df..2983607 100644
--- a/src/cnki_jbig.h
+++ b/src/cnki_jbig.h
@@ -27,8 +27,8 @@ typedef struct _dib_t {
uint16_t depth;
uint32_t compression; /* dib_compression_code */
uint32_t size;
- uint32_t resolution_h;
- uint32_t resolution_v;
+ int32_t resolution_h;
+ int32_t resolution_v;
uint32_t colour;
uint32_t colour_used;
} dib_t;
diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c
index 3d446e4..372c5da 100644
--- a/src/cnki_pdf.c
+++ b/src/cnki_pdf.c
@@ -793,15 +793,15 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "/F0 10 Tf\n");
for (int i = 0, j = 0; i < ptr->text_size - 1;) {
- switch ((uint16_t) (ptr->text[i + 1] << 8 | ptr->text[i])) {
- case 0x8001:
+ switch (ptr->text[i]) {
+ case 0x01:
if (ptr->address_next <= ptr->address) {
i += 2;
break;
}
strcat(dictionary, "T*\n");
- case 0x8070:
+ case 0x70:
if (ptr->address_next > ptr->address) {
i += 4;
@@ -867,21 +867,24 @@ cnki_pdf_hn(cnki_t **param)
i += 8;
break;
- case 0x800a:
+ case 0x0a:
if (i + 27 >= ptr->text_size || j >= ptr->image_length) {
i += 2;
break;
}
if (ptr->image_length > 0) {
- ptr->image_data[j].x =
- ptr->text[i + 5] << 8 | ptr->text[i + 4];
- ptr->image_data[j].y =
- ptr->text[i + 7] << 8 | ptr->text[i + 6];
- ptr->image_data[j].w =
- ptr->text[i + 9] << 8 | ptr->text[i + 8];
- ptr->image_data[j].h =
- ptr->text[i + 11] << 8 | ptr->text[i + 10];
+ ptr->image_data[j].x += (unsigned char) ptr->text[i + 5] << 8;
+ ptr->image_data[j].x += (unsigned char) ptr->text[i + 4];
+
+ ptr->image_data[j].y += (unsigned char) ptr->text[i + 7] << 8;
+ ptr->image_data[j].y += (unsigned char) ptr->text[i + 6];
+
+ ptr->image_data[j].w += (unsigned char) ptr->text[i + 9] << 8;
+ ptr->image_data[j].w += (unsigned char) ptr->text[i + 8];
+
+ ptr->image_data[j].h += (unsigned char) ptr->text[i + 11] << 8;
+ ptr->image_data[j].h += (unsigned char) ptr->text[i + 10];
if ((*param)->stat > 2)
printf("\tItem %d: origin (%4d, %4d), width %4d, height %4d\n",
@@ -908,7 +911,7 @@ cnki_pdf_hn(cnki_t **param)
}
if (ptr->image_length > 0) {
- char resize_str[64] = "0.25 0 0 0.25 0 0 cm\n";
+ char resize_str[64];
double resize_x = 1;
double resize_y = 1;
@@ -918,12 +921,13 @@ cnki_pdf_hn(cnki_t **param)
resize_y = 4 * 841.8898 / dim[1];
if (resize_y < resize_x)
- snprintf(buf, 64, "%f 0 0 %f 0 0 cm\n",
+ snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
resize_y, resize_y);
else
- snprintf(buf, 64, "%f 0 0 %f 0 0 cm\n",
+ snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
resize_x, resize_x);
- strcat(resize_str, buf);
+ } else {
+ memset(resize_str, 0, 64);
}
for (int i = 0; i < ptr->image_length; i++) {
@@ -932,7 +936,7 @@ cnki_pdf_hn(cnki_t **param)
strcat(dictionary, "q\n");
- strcat(dictionary, resize_str);
+ strcat(dictionary, "0.25 0 0 0.25 0 0 cm\n");
/* Rotate image */
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1) {
@@ -945,14 +949,8 @@ cnki_pdf_hn(cnki_t **param)
/* Translate figure */
if (i > 0) {
- double origin_x = 0.4043745 * ptr->image_data[i].x;
- double origin_y = 0.4043561 * ptr->image_data[i].y;
-
- if (origin_x < 0)
- origin_x += (2381.102 - dim[i * 2]) / 2;
-
- if (origin_y < 0)
- origin_y += (3367.559 + dim[i * 2 + 1]) / 2;
+ 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].format == JBIG || ptr->image_data[i].format == DCT_1)
origin_y = -3367.559 + origin_y + dim[i * 2 + 1];
@@ -967,6 +965,8 @@ cnki_pdf_hn(cnki_t **param)
dim[i * 2], dim[i * 2 + 1]);
strcat(dictionary, buf);
+ strcat(dictionary, resize_str);
+
snprintf(buf, 64, "/Im%d Do\n", i);
strcat(dictionary, buf);