Handle missing root object which is parent of others.

Signed-off-by: yzrh <yzrh@noema.org>
This commit is contained in:
yzrh 2022-12-29 02:49:05 +00:00
parent 8083b30530
commit 988a751c15
2 changed files with 8 additions and 5 deletions

View file

@ -1,6 +1,7 @@
0.3.0 (2023-XX-XX) 0.3.0 (2023-XX-XX)
================== ==================
* Handle missing but referenced root object.
* Support JPEG 2000 for HN. * Support JPEG 2000 for HN.
* Support HN figure placement. * Support HN figure placement.
* Support HN text overlay. * Support HN text overlay.

View file

@ -309,7 +309,9 @@ cnki_pdf(cnki_t **param)
if (parent_missing[i] == 1) if (parent_missing[i] == 1)
root_kid++; root_kid++;
if (root_kid <= 1) { if (root_kid > 1) {
root = pdf_get_free_id(&pdf);
} else {
if (root_kid == 0) { if (root_kid == 0) {
for (int i = 1; i <= parent[0]; i++) for (int i = 1; i <= parent[0]; i++)
if (root == 0 || root < parent[i]) if (root == 0 || root < parent[i])
@ -323,15 +325,15 @@ cnki_pdf(cnki_t **param)
if ((*param)->stat > 0) if ((*param)->stat > 0)
printf("Root object is %d.\n", printf("Root object is %d.\n",
root); root);
} else { }
if (pdf_get_kid_count(&pdf, root) == 0) {
if ((*param)->stat > 0) if ((*param)->stat > 0)
printf("Root object is missing\n"); printf("Root object is missing\n");
if ((*param)->stat > 1) if ((*param)->stat > 1)
printf("Generating root object\n"); printf("Generating root object\n");
root = pdf_get_free_id(&pdf);
snprintf(buf, 64, snprintf(buf, 64,
"<<\n/Type /Pages\n/Kids "); "<<\n/Type /Pages\n/Kids ");
strcat(dictionary, buf); strcat(dictionary, buf);
@ -886,7 +888,7 @@ cnki_pdf_hn(cnki_t **param)
free(dictionary); free(dictionary);
} }
dictionary_size = 64 + 128 * ptr->image_length; dictionary_size = 128 + 128 * ptr->image_length;
dictionary = malloc(dictionary_size); dictionary = malloc(dictionary_size);
if (dictionary == NULL) { if (dictionary == NULL) {