Fix root object dictionary generation.

This commit is contained in:
yzrh 2021-01-11 22:53:12 +00:00
parent 1994f122cc
commit 2aab394684
2 changed files with 23 additions and 10 deletions

View file

@ -77,7 +77,11 @@ cnki_pdf(cnki_t **param)
if ((*param)->stat > 0)
printf("Discovered %d parent object(s)\n", parent[0]);
int parent_missing[parent[0]];
int *parent_missing = malloc(parent[0] * sizeof(int));
if (parent_missing == NULL)
return 1;
int *kid;
for (int i = 1; i <= parent[0]; i++) {
@ -89,7 +93,7 @@ cnki_pdf(cnki_t **param)
if (kid[0] != 0) {
if ((*param)->stat > 0)
printf("Object is missing\n");
printf("Object %d is missing\n", parent[i]);
if ((*param)->stat > 1)
printf("Generating object\n");
@ -97,8 +101,11 @@ cnki_pdf(cnki_t **param)
dictionary_size = 64 + 12 * kid[0];
dictionary = malloc(dictionary_size);
if (dictionary == NULL)
if (dictionary == NULL) {
free(parent);
free(parent_missing);
return 1;
}
memset(dictionary, 0, dictionary_size);
@ -134,7 +141,7 @@ cnki_pdf(cnki_t **param)
parent_missing[i - 1] = 0;
if ((*param)->stat > 0)
printf("Object exists\n");
printf("Object %d exists\n", parent[i]);
}
free(kid);
@ -146,8 +153,11 @@ cnki_pdf(cnki_t **param)
dictionary_size = 128;
dictionary = malloc(dictionary_size);
if (dictionary == NULL)
if (dictionary == NULL) {
free(parent);
free(parent_missing);
return 1;
}
memset(dictionary, 0, dictionary_size);
@ -155,7 +165,7 @@ cnki_pdf(cnki_t **param)
int root_kid = 0;
for (int i = 0; i < parent[0]; i++)
if (parent_missing[i])
if (parent_missing[i] == 1)
root_kid++;
if (root_kid <= 1) {
@ -165,7 +175,7 @@ cnki_pdf(cnki_t **param)
root = parent[i];
} else {
for (int i = 0; i < parent[0]; i++)
if (parent_missing[i])
if (parent_missing[i] == 1)
root = i;
}
@ -188,12 +198,12 @@ cnki_pdf(cnki_t **param)
if (parent[0] > 1)
strcat(dictionary, "[");
for (int i = 0; i < parent[0]; i++) {
for (int i = 0, j = 0; i < parent[0]; i++) {
if (parent_missing[i]) {
snprintf(buf, 64, "%d 0 R", parent[i + 1]);
strcat(dictionary, buf);
if (i < root_kid)
if (++j < root_kid)
strcat(dictionary, " ");
}
}
@ -217,6 +227,9 @@ cnki_pdf(cnki_t **param)
root);
}
free(parent);
free(parent_missing);
int *ids = NULL;
if ((*param)->file_stat->outline > 0) {

View file

@ -24,7 +24,7 @@ strdec_jbig(char **bitmap, int *bitmap_size,
int ret;
if ((ret = jbg_dec_in(&sd, (unsigned char *) data_ptr,
data_size, NULL)) != JBG_EOK) {
printf("%s", jbg_strerror(ret));
printf("%s\n", jbg_strerror(ret));
jbg_dec_free(&sd);
return 1;
}