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;
|
||||
char *stream;
|
||||
|
||||
int *dim;
|
||||
double *dim;
|
||||
|
||||
if (ptr->image_length > 0) {
|
||||
dim = malloc(2 * ptr->image_length * sizeof(int));
|
||||
dim = malloc(2 * ptr->image_length * sizeof(double));
|
||||
|
||||
if (dim == NULL) {
|
||||
free(root_kid);
|
||||
|
@ -911,24 +911,35 @@ cnki_pdf_hn(cnki_t **param)
|
|||
strcat(dictionary, "\n");
|
||||
}
|
||||
|
||||
/* FIXME: Use the text somehow? */
|
||||
memset(dictionary, 0, dictionary_size);
|
||||
|
||||
if (ptr->image_length > 0) {
|
||||
char resize_str[64];
|
||||
double resize_x = 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) {
|
||||
/* Scale within bound of A4 paper */
|
||||
resize_x = 2381.102 / dim[0];
|
||||
resize_y = 3367.559 / dim[1];
|
||||
resize_x = 2480.315 / dim[0];
|
||||
resize_y = 3507.874 / dim[1];
|
||||
|
||||
if (resize_y < resize_x)
|
||||
snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
|
||||
resize_y, resize_y);
|
||||
else
|
||||
snprintf(resize_str, 64, "%f 0 0 %f 0 0 cm\n",
|
||||
resize_x, resize_x);
|
||||
if (resize_y < resize_x) {
|
||||
for (int i = 0; i < ptr->image_length; i++) {
|
||||
dim[i * 2] *= resize_y;
|
||||
dim[i * 2 + 1] *= resize_y;
|
||||
}
|
||||
} else {
|
||||
memset(resize_str, 0, 64);
|
||||
for (int i = 0; i < ptr->image_length; i++) {
|
||||
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++) {
|
||||
|
@ -937,36 +948,48 @@ cnki_pdf_hn(cnki_t **param)
|
|||
|
||||
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 */
|
||||
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",
|
||||
dim[i * 2 + 1]);
|
||||
snprintf(buf, 64, "1 0 0 -1 0 %f cm\n", dim[i * 2 + 1]);
|
||||
strcat(dictionary, buf);
|
||||
|
||||
strcat(dictionary, "1 0 0 -1 0 0 cm\n");
|
||||
}
|
||||
|
||||
/* Translate figure */
|
||||
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;
|
||||
double origin_x = ptr->image_data[i].x * 0.40433;
|
||||
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)
|
||||
origin_y = -3367.559 + origin_y + dim[i * 2 + 1];
|
||||
origin_y = -3507.874 + origin_y + dim[i * 2 + 1];
|
||||
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);
|
||||
strcat(dictionary, buf);
|
||||
}
|
||||
|
||||
snprintf(buf, 64, "%d 0 0 %d 0 0 cm\n",
|
||||
dim[i * 2], dim[i * 2 + 1]);
|
||||
if (margin_x > 0 || margin_y > 0) {
|
||||
if (ptr->image_data[i].format == JBIG || ptr->image_data[i].format == DCT_1) {
|
||||
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);
|
||||
strcat(dictionary, buf);
|
||||
|
|
Loading…
Reference in a new issue