aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2022-12-30 12:20:49 +0000
committeryzrh <yzrh@noema.org>2022-12-30 15:04:32 +0000
commit226f16ddf41619caea347228322851835b4d1045 (patch)
tree3ebe081c6e603c2471d542dac871130fba271179 /src
parent9646ee61c355a97ad47d20ec3e3d77bceee34b07 (diff)
downloadmelon-226f16ddf41619caea347228322851835b4d1045.tar.gz
melon-226f16ddf41619caea347228322851835b4d1045.tar.zst
Handle HN page with figure only.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r--src/cnki_pdf.c39
-rw-r--r--src/jbig.c10
-rw-r--r--src/pdf_get.c4
-rw-r--r--src/version.h2
4 files changed, 28 insertions, 27 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];
diff --git a/src/jbig.c b/src/jbig.c
index fce8e02..b466411 100644
--- a/src/jbig.c
+++ b/src/jbig.c
@@ -108,7 +108,7 @@ static void
_bytein(void)
{
if (_ret_pos < _scd_size)
- _reg_c += *(_scd + _ret_pos++) << 8;
+ _reg_c += _scd[_ret_pos++] << 8;
_ct = 8;
}
@@ -215,19 +215,19 @@ _procline(int line, char *a, char *b, char *c)
cx >>= 1;
if (_pix == 1) {
- *(_ret + _width_padded * (_height - line - 1) + i / 8) |= _pix << (7 - (i & 0x07));
- *(c + i) = 1;
+ _ret[_width_padded * (_height - line - 1) + i / 8] |= _pix << (7 - (i & 0x07));
+ c[i] = 1;
cx |= 0x0200;
} else {
cx &= 0xfdff;
}
- if (i + 2 < _width && *(a + i + 2) == 1)
+ if (i + 2 < _width && a[i + 2] == 1)
cx |= 0x0004;
else
cx &= 0xfffb;
- if (i + 3 < _width && *(b + i + 3) == 1)
+ if (i + 3 < _width && b[i + 3] == 1)
cx |= 0x0080;
else
cx &= 0xff7f;
diff --git a/src/pdf_get.c b/src/pdf_get.c
index a72c68d..bde5bf2 100644
--- a/src/pdf_get.c
+++ b/src/pdf_get.c
@@ -89,7 +89,7 @@ pdf_get_free_id(pdf_object_t **pdf)
int id = 0;
- for (int i = 1; i < 99999999; i++) {
+ for (int i = 1; i < 100000000; i++) {
ptr = (*pdf)->next;
while (ptr != NULL) {
if (ptr->id == i) {
@@ -123,7 +123,7 @@ pdf_get_free_ids(pdf_object_t **pdf, int **ids, int count)
int id = 0;
pdf_object_t *ptr;
- for (int i = 1; i < 99999999; i++) {
+ for (int i = 1; i < 100000000; i++) {
ptr = (*pdf)->next;
while (ptr != NULL) {
if (ptr->id == i) {
diff --git a/src/version.h b/src/version.h
index 08b70ea..53be5ba 100644
--- a/src/version.h
+++ b/src/version.h
@@ -6,5 +6,5 @@
#define VERSION "0"
#define RELEASE "2"
-#define PATCH "3"
+#define PATCH "4"
#define EXTRA ""