1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
From: YOKOTA Hiroshi <yokota.hgml@gmail.com>
Date: Fri, 30 Jun 2023 17:10:21 +0900
Subject: Revert "Append all at once"
Forwarded: not-needed
This reverts commit 7469c920f22551d6a0b49b2224221be8c8991eed.
---
src/calibre/ebooks/pdf/html_writer.py | 11 +++++++----
src/calibre/utils/podofo/doc.cpp | 6 +-----
2 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/calibre/ebooks/pdf/html_writer.py b/src/calibre/ebooks/pdf/html_writer.py
index b95b1fc..cdf37d4 100644
--- a/src/calibre/ebooks/pdf/html_writer.py
+++ b/src/calibre/ebooks/pdf/html_writer.py
@@ -1155,7 +1155,7 @@ def convert(opf_path, opts, metadata=None, output_path=None, log=default_log, co
results = manager.convert_html_files(jobs, settle_time=1, has_maths=has_maths)
num_pages = 0
page_margins_map = []
- all_docs = []
+ log(f'Merging {len(margin_files)} PDF render results, this could take a while...')
for i, margin_file in enumerate(margin_files):
name = margin_file.name
data = results[name]
@@ -1166,10 +1166,13 @@ def convert(opf_path, opts, metadata=None, output_path=None, log=default_log, co
doc_pages = doc.page_count()
page_margins_map.extend(repeat(resolve_margins(margin_file.margins, page_layout), doc_pages))
num_pages += doc_pages
- all_docs.append(doc)
- pdf_doc = all_docs[0]
- pdf_doc.append(*all_docs[1:])
+ if pdf_doc is None:
+ pdf_doc = doc
+ else:
+ st = monotonic()
+ pdf_doc.append(doc)
+ log(f'Merged ({i}/{len(margin_files)-1}) in {monotonic()-st:.1f} seconds')
page_number_display_map = get_page_number_display_map(manager, opts, num_pages, log)
diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp
index 66a6499..6f1220c 100644
--- a/src/calibre/utils/podofo/doc.cpp
+++ b/src/calibre/utils/podofo/doc.cpp
@@ -11,7 +11,6 @@
#include <new>
#include <string_view>
#include <unordered_map>
-#include <vector>
using namespace pdf;
@@ -366,15 +365,12 @@ PDFDoc_append(PDFDoc *self, PyObject *args) {
PdfMemDocument *dest = self->doc;
try {
- std::vector<const PdfMemDocument*> docs(PyTuple_GET_SIZE(args));
for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(args); i++) {
PyObject *doc = PyTuple_GET_ITEM(args, i);
int typ = PyObject_IsInstance(doc, (PyObject*)&PDFDocType);
if (typ == -1) return NULL;
if (typ == 0) { PyErr_SetString(PyExc_TypeError, "You must pass a PDFDoc instance to this method"); return NULL; }
- docs[i] = ((PDFDoc*)doc)->doc;
- }
- for (auto src : docs) {
+ const PdfMemDocument *src = ((PDFDoc*)doc)->doc;
std::unordered_map<PdfReference, PdfObject*> ref_map;
std::unordered_map<PdfReference, PdfReference> page_parent_map;
const unsigned initial_page_count = dest->GetPages().GetCount();
|