Fix type casting when processing data.
Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
parent
1ce3f89574
commit
5466a441df
3 changed files with 31 additions and 31 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue