File: 0049-Revert-Podofo-wrapper-to-add-an-image-page.patch

package info (click to toggle)
calibre 7.23.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 422,900 kB
  • sloc: python: 438,056; ansic: 86,986; javascript: 57,190; cpp: 18,422; xml: 1,237; sh: 922; sql: 735; objc: 330; makefile: 69; sed: 6
file content (91 lines) | stat: -rw-r--r-- 4,028 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From: YOKOTA Hiroshi <yokota.hgml@gmail.com>
Date: Fri, 26 May 2023 21:26:53 +0900
Subject: Revert "Podofo wrapper to add an image page"

Forwarded: not-needed

This reverts commit cb1c6efd61241e04104bf7cdba5f340c09299702.
---
 src/calibre/utils/podofo/__init__.py | 17 -----------------
 src/calibre/utils/podofo/doc.cpp     | 33 ---------------------------------
 2 files changed, 50 deletions(-)

diff --git a/src/calibre/utils/podofo/__init__.py b/src/calibre/utils/podofo/__init__.py
index 95f7fbc..c57c943 100644
--- a/src/calibre/utils/podofo/__init__.py
+++ b/src/calibre/utils/podofo/__init__.py
@@ -166,23 +166,6 @@ def test_dedup_type3_fonts(src):
     print(f'Modified pdf with {num} glyphs removed saved to:', dest)
 
 
-def add_image_page(pdf_doc, image_data, page_size=None, page_num=1, preserve_aspect_ratio=True):
-    if page_size is None:
-        from qt.core import QPageSize
-        page_size = QPageSize(QPageSize.PageSizeId.A4)
-    page = page_size.rect(QPageSize.Unit.Point)
-    pdf_doc.add_image_page(
-        image_data, page.left(), page.top(), page.width(), page.height(), page.left(), page.top(), page.width(), page.height(), page_num, preserve_aspect_ratio)
-
-
-def test_add_image_page(image='/t/t.jpg', dest='/t/t.pdf', **kw):
-    image_data = open(image, 'rb').read()
-    podofo = get_podofo()
-    p = podofo.PDFDoc()
-    add_image_page(p, image_data, **kw)
-    p.save(dest)
-
-
 def test_list_fonts(src):
     podofo = get_podofo()
     p = podofo.PDFDoc()
diff --git a/src/calibre/utils/podofo/doc.cpp b/src/calibre/utils/podofo/doc.cpp
index 4b6a880..1f6afac 100644
--- a/src/calibre/utils/podofo/doc.cpp
+++ b/src/calibre/utils/podofo/doc.cpp
@@ -407,35 +407,6 @@ PDFDoc_get_xmp_metadata(PDFDoc *self, PyObject *args) {
     Py_RETURN_NONE;
 } // }}}
 
-// add_image_page() {{{
-static PyObject *
-PDFDoc_add_image_page(PDFDoc *self, PyObject *args) {
-    const char *image_data; Py_ssize_t image_data_sz;
-    double page_x, page_y, page_width, page_height;
-    double image_x, image_y, image_canvas_width, image_canvas_height;
-    unsigned int page_num = 1; int preserve_aspect_ratio = 1;
-    if (!PyArg_ParseTuple(args, "y#dddddddd|Ip", &image_data, &image_data_sz, &page_x, &page_y, &page_width, &page_height, &image_x, &image_y, &image_canvas_width, &image_canvas_height, &page_num, &preserve_aspect_ratio)) return NULL;
-    auto img = self->doc->CreateImage();
-    img->LoadFromBuffer(bufferview(image_data, image_data_sz));
-    auto &page = self->doc->GetPages().CreatePageAt(page_num-1, Rect(page_x, page_y, page_width, page_height));
-    PdfPainter painter;
-    painter.SetCanvas(page);
-    auto scaling_x = image_canvas_width, scaling_y = image_canvas_height;
-    if (preserve_aspect_ratio) {
-        auto page_ar = page_width / page_height, img_ar = img->GetRect().Width / img->GetRect().Height;
-        if (page_ar > img_ar) {
-            scaling_x = img_ar * image_canvas_height;
-            image_x = (image_canvas_width - scaling_x) / 2.;
-        } else if (page_ar < img_ar) {
-            scaling_y = image_canvas_width / img_ar;
-            image_y = (image_canvas_height - scaling_y) / 2.;
-        }
-    }
-    painter.DrawImage(*img, image_x, image_y, scaling_x / img->GetRect().Width, scaling_y / img->GetRect().Height);
-    return Py_BuildValue("dd", img->GetRect().Width, img->GetRect().Height);
-}
-// }}}
-
 // set_xmp_metadata() {{{
 static PyObject *
 PDFDoc_set_xmp_metadata(PDFDoc *self, PyObject *args) {
@@ -838,10 +809,6 @@ static PyMethodDef PDFDoc_methods[] = {
     {"set_xmp_metadata", (PyCFunction)PDFDoc_set_xmp_metadata, METH_VARARGS,
      "set_xmp_metadata(raw) -> Set the XMP metadata to the raw bytes (which must be a valid XML packet)"
     },
-    {"add_image_page", (PyCFunction)PDFDoc_add_image_page, METH_VARARGS,
-     "add_image_page(image_data, page_idx=0) -> Add the specified image as a full page image, will use the size of the first existing page as page size."
-    },
-
 
     {NULL}  /* Sentinel */
 };