Fix HN image compositing.
Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
parent
1d899d934d
commit
220a81c2ad
1 changed files with 49 additions and 26 deletions
|
@ -496,10 +496,10 @@ cnki_pdf_hn(cnki_t **param)
|
||||||
int stream_size;
|
int stream_size;
|
||||||
char *stream;
|
char *stream;
|
||||||
|
|
||||||
int *dim;
|
double *dim;
|
||||||
|
|
||||||
if (ptr->image_length > 0) {
|
if (ptr->image_length > 0) {
|
||||||
dim = malloc(2 * ptr->image_length * sizeof(int));
|
dim = malloc(2 * ptr->image_length * sizeof(double));
|
||||||
|
|
||||||
if (dim == NULL) {
|
if (dim == NULL) {
|
||||||
free(root_kid);
|
free(root_kid);
|
||||||
|
@ -911,24 +911,35 @@ cnki_pdf_hn(cnki_t **param)
|
||||||
strcat(dictionary, "\n");
|
strcat(dictionary, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME: Use the text somehow? */
|
||||||
|
memset(dictionary, 0, dictionary_size);
|
||||||
|
|
||||||
if (ptr->image_length > 0) {
|
if (ptr->image_length > 0) {
|
||||||
char resize_str[64];
|
|
||||||
double resize_x = 1;
|
double resize_x = 1;
|
||||||
double resize_y = 1;
|
double resize_y = 1;
|
||||||
|
|
||||||
|
double margin_x = 0;
|
||||||
|
double margin_y = 0;
|
||||||
|
|
||||||
if (ptr->image_data[0].x == 0 && ptr->image_data[0].y == 0 && 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 */
|
/* Scale within bound of A4 paper */
|
||||||
resize_x = 2381.102 / dim[0];
|
resize_x = 2480.315 / dim[0];
|
||||||
resize_y = 3367.559 / dim[1];
|
resize_y = 3507.874 / dim[1];
|
||||||
|
|
||||||
if (resize_y < resize_x)
|
if (resize_y < resize_x) {
|
||||||
snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
|
for (int i = 0; i < ptr->image_length; i++) {
|
||||||
resize_y, resize_y);
|
dim[i * 2] *= resize_y;
|
||||||
else
|
dim[i * 2 + 1] *= resize_y;
|
||||||
snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
|
}
|
||||||
resize_x, resize_x);
|
} else {
|
||||||
} else {
|
for (int i = 0; i < ptr->image_length; i++) {
|
||||||
memset(resize_str, 0, 64);
|
dim[i * 2] *= resize_x;
|
||||||
|
dim[i * 2 + 1] *= resize_x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
margin_x = (2480.315 - dim[0]) / 2;
|
||||||
|
margin_y = (3507.874 - dim[1]) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < ptr->image_length; i++) {
|
for (int i = 0; i < ptr->image_length; i++) {
|
||||||
|
@ -937,36 +948,48 @@ cnki_pdf_hn(cnki_t **param)
|
||||||
|
|
||||||
strcat(dictionary, "q\n");
|
strcat(dictionary, "q\n");
|
||||||
|
|
||||||
strcat(dictionary, "0.25 0 0 0.25 0 0 cm\n");
|
strcat(dictionary, "0.24 0 0 0.24 0 0 cm\n");
|
||||||
|
|
||||||
/* Rotate image */
|
/* Rotate image */
|
||||||
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1) {
|
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1) {
|
||||||
snprintf(buf, 64, "1 0 0 1 0 %d cm\n",
|
snprintf(buf, 64, "1 0 0 -1 0 %f cm\n", dim[i * 2 + 1]);
|
||||||
dim[i * 2 + 1]);
|
|
||||||
strcat(dictionary, buf);
|
strcat(dictionary, buf);
|
||||||
|
|
||||||
strcat(dictionary, "1 0 0 -1 0 0 cm\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate figure */
|
/* Translate figure */
|
||||||
if (ptr->image_data[i].x > 0 || ptr->image_data[i].y > 0) {
|
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_x = ptr->image_data[i].x * 0.40433;
|
||||||
double origin_y = ptr->image_data[i].y * dim[i * 2 + 1] / ptr->image_data[i].h;
|
double origin_y = ptr->image_data[i].y * 0.40433;
|
||||||
|
|
||||||
|
if (resize_y < resize_x) {
|
||||||
|
origin_x *= resize_y;
|
||||||
|
origin_y *= resize_y;
|
||||||
|
} else {
|
||||||
|
origin_x *= resize_x;
|
||||||
|
origin_y *= resize_x;
|
||||||
|
}
|
||||||
|
|
||||||
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1)
|
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1)
|
||||||
origin_y = -3367.559 + origin_y + dim[i * 2 + 1];
|
origin_y = -3507.874 + origin_y + dim[i * 2 + 1];
|
||||||
else
|
else
|
||||||
origin_y = 3367.559 - origin_y - dim[i * 2 + 1];
|
origin_y = 3507.874 - origin_y - dim[i * 2 + 1];
|
||||||
|
|
||||||
snprintf(buf, 64, "1 0 0 1 %f %f cm\n", origin_x, origin_y);
|
snprintf(buf, 64, "1 0 0 1 %f %f cm\n", origin_x, origin_y);
|
||||||
strcat(dictionary, buf);
|
strcat(dictionary, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, 64, "%d 0 0 %d 0 0 cm\n",
|
if (margin_x > 0 || margin_y > 0) {
|
||||||
dim[i * 2], dim[i * 2 + 1]);
|
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1) {
|
||||||
strcat(dictionary, buf);
|
snprintf(buf, 64, "1 0 0 1 %f %f cm\n", margin_x, -margin_y);
|
||||||
|
strcat(dictionary, buf);
|
||||||
|
} else {
|
||||||
|
snprintf(buf, 64, "1 0 0 1 %f %f cm\n", margin_x, margin_y);
|
||||||
|
strcat(dictionary, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
strcat(dictionary, resize_str);
|
snprintf(buf, 64, "%f 0 0 %f 0 0 cm\n", dim[i * 2], dim[i * 2 + 1]);
|
||||||
|
strcat(dictionary, buf);
|
||||||
|
|
||||||
snprintf(buf, 64, "/Im%d Do\n", i);
|
snprintf(buf, 64, "/Im%d Do\n", i);
|
||||||
strcat(dictionary, buf);
|
strcat(dictionary, buf);
|
||||||
|
|
Loading…
Reference in a new issue