Handle HN page with figure only.

Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
yzrh 2022-12-30 12:20:49 +00:00
parent 9646ee61c3
commit 226f16ddf4
4 changed files with 28 additions and 27 deletions

View file

@ -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;
}
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 0x70:
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,6 +895,8 @@ cnki_pdf_hn(cnki_t **param)
}
i += 28;
if (j == 0 || ptr->image_data[j].x > 0 || ptr->image_data[j].y > 0)
j++;
break;
default:
@ -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];

View file

@ -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;

View file

@ -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) {

View file

@ -6,5 +6,5 @@
#define VERSION "0"
#define RELEASE "2"
#define PATCH "3"
#define PATCH "4"
#define EXTRA ""