Commit 0c56cec6c32e9b81fc42f1ed791e90005bf716bb

Authored by m-holger
1 parent 88fd7ca9

Refactor QPDF::createFromJSON

libqpdf/QPDF.cc
... ... @@ -495,6 +495,14 @@ QPDF::Xref_table::initialize_empty()
495 495 }
496 496  
497 497 void
  498 +QPDF::Xref_table::initialize_json()
  499 +{
  500 + initialized_ = true;
  501 + trailer_ = QPDFObjectHandle::newDictionary();
  502 + trailer_.replaceKey("/Size", QPDFObjectHandle::newInteger(1));
  503 +}
  504 +
  505 +void
498 506 QPDF::Xref_table::initialize()
499 507 {
500 508 // PDF spec says %%EOF must be found within the last 1024 bytes of/ the file. We add an extra
... ...
libqpdf/QPDF_json.cc
... ... @@ -51,17 +51,6 @@
51 51 // ] | <- st_top
52 52 // } |
53 53  
54   -static char const* JSON_PDF = (
55   - // force line break
56   - "%PDF-1.3\n"
57   - "xref\n"
58   - "0 1\n"
59   - "0000000000 65535 f \n"
60   - "trailer << /Size 1 >>\n"
61   - "startxref\n"
62   - "9\n"
63   - "%%EOF\n");
64   -
65 54 // Validator methods -- these are much more performant than std::regex.
66 55 static bool
67 56 is_indirect_object(std::string const& v, int& obj, int& gen)
... ... @@ -785,7 +774,9 @@ QPDF::createFromJSON(std::string const&amp; json_file)
785 774 void
786 775 QPDF::createFromJSON(std::shared_ptr<InputSource> is)
787 776 {
788   - processMemoryFile(is->getName().c_str(), JSON_PDF, strlen(JSON_PDF));
  777 + m->pdf_version = "1.3";
  778 + m->no_input_name = is->getName();
  779 + m->xref_table.initialize_json();
789 780 importJSON(is, true);
790 781 }
791 782  
... ...
libqpdf/qpdf/QPDF_private.hh
... ... @@ -16,6 +16,7 @@ class QPDF::Xref_table
16 16  
17 17 void initialize();
18 18 void initialize_empty();
  19 + void initialize_json();
19 20 void reconstruct(QPDFExc& e);
20 21 void show();
21 22 bool resolve();
... ...