From 0c56cec6c32e9b81fc42f1ed791e90005bf716bb Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 13 Aug 2024 16:47:25 +0100 Subject: [PATCH] Refactor QPDF::createFromJSON --- libqpdf/QPDF.cc | 8 ++++++++ libqpdf/QPDF_json.cc | 15 +++------------ libqpdf/qpdf/QPDF_private.hh | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index b09a86a..357ee3e 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -495,6 +495,14 @@ QPDF::Xref_table::initialize_empty() } void +QPDF::Xref_table::initialize_json() +{ + initialized_ = true; + trailer_ = QPDFObjectHandle::newDictionary(); + trailer_.replaceKey("/Size", QPDFObjectHandle::newInteger(1)); +} + +void QPDF::Xref_table::initialize() { // PDF spec says %%EOF must be found within the last 1024 bytes of/ the file. We add an extra diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index b767c00..32af3f9 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -51,17 +51,6 @@ // ] | <- st_top // } | -static char const* JSON_PDF = ( - // force line break - "%PDF-1.3\n" - "xref\n" - "0 1\n" - "0000000000 65535 f \n" - "trailer << /Size 1 >>\n" - "startxref\n" - "9\n" - "%%EOF\n"); - // Validator methods -- these are much more performant than std::regex. static bool is_indirect_object(std::string const& v, int& obj, int& gen) @@ -785,7 +774,9 @@ QPDF::createFromJSON(std::string const& json_file) void QPDF::createFromJSON(std::shared_ptr is) { - processMemoryFile(is->getName().c_str(), JSON_PDF, strlen(JSON_PDF)); + m->pdf_version = "1.3"; + m->no_input_name = is->getName(); + m->xref_table.initialize_json(); importJSON(is, true); } diff --git a/libqpdf/qpdf/QPDF_private.hh b/libqpdf/qpdf/QPDF_private.hh index 421d166..32b1d12 100644 --- a/libqpdf/qpdf/QPDF_private.hh +++ b/libqpdf/qpdf/QPDF_private.hh @@ -16,6 +16,7 @@ class QPDF::Xref_table void initialize(); void initialize_empty(); + void initialize_json(); void reconstruct(QPDFExc& e); void show(); bool resolve(); -- libgit2 0.21.4