aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoryzrh <yzrh@noema.org>2023-01-04 17:07:57 +0000
committeryzrh <yzrh@noema.org>2023-01-04 17:07:57 +0000
commit8cd8a8fbbadaeee6563d6cb5d7c648570d78b2fc (patch)
tree8cadbd4b6e318cc597d803c1db58073cacbcccf5 /src
parent8276423eb8395eae3e3002442307272eff1c9e8f (diff)
downloadmelon-8cd8a8fbbadaeee6563d6cb5d7c648570d78b2fc.tar.gz
melon-8cd8a8fbbadaeee6563d6cb5d7c648570d78b2fc.tar.zst
Replace catalog object if found.
Signed-off-by: yzrh <yzrh@noema.org>
Diffstat (limited to 'src')
-rw-r--r--src/cnki_pdf.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/cnki_pdf.c b/src/cnki_pdf.c
index 76931ea..87fe3f6 100644
--- a/src/cnki_pdf.c
+++ b/src/cnki_pdf.c
@@ -244,10 +244,6 @@ cnki_pdf(cnki_t **param)
printf("Loaded %d object(s)\n",
pdf_get_count(&pdf));
- pdf_obj_sort(&pdf);
-
- _pdf_obj_dedup(param, &pdf);
-
int dictionary_size;
char *dictionary;
@@ -262,6 +258,10 @@ cnki_pdf(cnki_t **param)
if ((*param)->stat > 0)
printf("Discovered %d parent object(s)\n", parent[0]);
+ pdf_obj_sort(&pdf);
+
+ _pdf_obj_dedup(param, &pdf);
+
int8_t *parent_missing;
int *kid;
@@ -419,6 +419,20 @@ cnki_pdf(cnki_t **param)
int outline = _pdf_cnki_outline(param, &pdf);
+ snprintf(buf, 64,
+ "<<\n/Type /Catalog\n/Pages %d 0 R\n",
+ root);
+ strcat(dictionary, buf);
+
+ if (outline != -1) {
+ snprintf(buf, 64,
+ "/Outlines %d 0 R\n/PageMode /UseOutlines\n",
+ outline);
+ strcat(dictionary, buf);
+ }
+
+ strcat(dictionary, ">>");
+
if ((*param)->stat > 1)
printf("Searching for catalog object\n");
@@ -427,6 +441,14 @@ cnki_pdf(cnki_t **param)
if (catalog != 0) {
if ((*param)->stat > 0)
printf("Catalog object is %d.\n", catalog);
+
+ if ((*param)->stat > 1)
+ printf("Replacing catalog object\n");
+
+ pdf_obj_replace(&pdf, catalog, NULL, dictionary, NULL, 0);
+
+ if ((*param)->stat > 0)
+ printf("Replaced catalog object\n");
} else {
if ((*param)->stat > 0)
printf("Catalog object is missing\n");
@@ -434,20 +456,6 @@ cnki_pdf(cnki_t **param)
if ((*param)->stat > 1)
printf("Generating catalog object\n");
- snprintf(buf, 64,
- "<<\n/Type /Catalog\n/Pages %d 0 R\n",
- root);
- strcat(dictionary, buf);
-
- if (outline != -1) {
- snprintf(buf, 64,
- "/Outlines %d 0 R\n/PageMode /UseOutlines\n",
- outline);
- strcat(dictionary, buf);
- }
-
- strcat(dictionary, ">>");
-
pdf_obj_append(&pdf, 0, NULL, dictionary, NULL, 0);
if ((*param)->stat > 0)