From 4bbcd26e7cb1908fb98bb318bfaa13ea9e32d860 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Mon, 10 Apr 2023 05:36:05 +0100 Subject: gentoo auto-resync : 10:04:2023 - 05:36:05 --- app-text/krop/Manifest | 5 +- app-text/krop/files/krop-0.6.0-links.patch | 64 ++++++++++++ app-text/krop/files/krop-0.6.0-pikepdf.patch | 150 +++++++++++++++++++++++++++ app-text/krop/krop-0.6.0-r2.ebuild | 47 +++++++++ app-text/krop/metadata.xml | 3 + 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 app-text/krop/files/krop-0.6.0-links.patch create mode 100644 app-text/krop/files/krop-0.6.0-pikepdf.patch create mode 100644 app-text/krop/krop-0.6.0-r2.ebuild (limited to 'app-text/krop') diff --git a/app-text/krop/Manifest b/app-text/krop/Manifest index 9061a6fe2d58..6fe077b1c04e 100644 --- a/app-text/krop/Manifest +++ b/app-text/krop/Manifest @@ -1,4 +1,7 @@ +AUX krop-0.6.0-links.patch 2327 BLAKE2B 5bae0df80ac0e68845b5b231306bf1ca92452b6f43ada5dc539561480ea887542a39ba7927bec5b2b0b208a852d18d43da5c8a9d866aea686ac3ac01ff908386 SHA512 5e091d2381965d104b661273876b58ba2217be4d99d2d39b8ffad79b1909f2d84ff4b2fa829703d305d708282849a438f07dc55aa4ef7557b79fc5b7efac2ed5 +AUX krop-0.6.0-pikepdf.patch 5691 BLAKE2B 4cae2438ec89197616ab5a680d6cc1a391207c44396d0699fac264a39f0e642541e2c1047b86f1def842ef19d15158408ef6496a8dc956ec699db52a7b89c452 SHA512 c6a47582e8821d987e11fce3ae8de5e59383d1bca37328f8ab24aee590bf5f9b21dcc3d64cf20150026fd4a38beb653161804fc828da07b5bb265a2703ca86ae DIST krop-0.6.0.tar.gz 48331 BLAKE2B ca6a00a410ed4e18a401fab3a21bc49c86f73165f68b192ab83c8fad74111ba9a9941f464a2646faa5a3317bbb45cdc89bed19c901999c0b11db353ac2997a65 SHA512 51a988e4fcb65d11cc26cf5b0c808e79097a66ef8ec4751a6c051289cd77b3328ebc8ecd9829adc466f87330beb8bc715d290cc20be415a7b8f179378b7bcb4f EBUILD krop-0.6.0-r1.ebuild 945 BLAKE2B a3c4e6820cc0595dfbd61a2e76761b6f614c170bd2e990b51d3c55e9f1025ba7a4b9abab2ef3c66f200bbe032b4cc7908b79663082f1c5e7a7ab883e12c803ca SHA512 57beb5d0364398d4a3e407ee62aac125f1264c084983b6f7a851dff048577fd6644ffce0c0194a220484b1ef267ca69a1706d263e0ac31233f4d146420ba9e40 +EBUILD krop-0.6.0-r2.ebuild 1026 BLAKE2B 7d6426e80ef9cb2b1ae5d0ae55f51a75a5a608a31f6a95078052fa96b78a6c17aa09af6fb80c8eb664ffab98ffe4090c9b06815604055befb9168dfd5f68d652 SHA512 b92fb1892a0ae4d0060b2b8c57067dab8bf93983257ff5b70317ab6312dca6ed17deb4614b913bfa64d8923de19d66777a164da1bad6790d4a02534ef385e3df EBUILD krop-9999.ebuild 946 BLAKE2B 5f71943de56f191ebf29d82e6249b5953ba390e564e1bbc820698cc4e04b83381fa8b44aa3912f05ad5088fb1c68a9ef2af9b2338d053d6e869bd52483805248 SHA512 6bd37e5c7b387563783d2423ac0de3640e668126134010f55cf0f7ff7da0998395bfe2a409a4b378f320c10d0cd4bfad5806ec5f73b06ebc70b52e26c12afcfe -MISC metadata.xml 334 BLAKE2B b848b73cedb8a26432461c3a43e097ba4e6e29447014644add41afff8e545ee57983b9c181813b483dc5a79a5071f1de067292c7becbca16e41859d08e870bda SHA512 96f05cf00639a69f2a9aca1bae11a37c5cf39458265b79d8020778e8838452f1a45f95b7329e5cc49de3a946d72205fb5f1c47f4b47a71977f0d21958acba4ea +MISC metadata.xml 412 BLAKE2B cf7adf888afec0389c32bf0ebbb83a0723168970203742a5564872471eb05700cc387ace750b0606deb337e9e0e3d109ff56e650c8c617e516d1196d6ef1f52b SHA512 bc6dd57f76f5ac0468e15f31062d302cc4a7815eb6bd323a610657f02ce46524520652b2125512bb40d50e18b37369b8e1911debd3116a644f3c6ed2c099d62d diff --git a/app-text/krop/files/krop-0.6.0-links.patch b/app-text/krop/files/krop-0.6.0-links.patch new file mode 100644 index 000000000000..c311b10cf88e --- /dev/null +++ b/app-text/krop/files/krop-0.6.0-links.patch @@ -0,0 +1,64 @@ +From a39f8328cf59492e68643f499c0d0fbda910444c Mon Sep 17 00:00:00 2001 +From: Armin Straub <31167361+arminstraub@users.noreply.github.com> +Date: Sun, 17 Jan 2021 15:50:49 -0600 +Subject: [PATCH] Preserve links within a PDF (thanks to chrthi) + +--- + ChangeLog | 4 ++++ + krop/mainwindow.py | 1 + + krop/pdfcropper.py | 11 +++++++++++ + 3 files changed, 16 insertions(+) + +diff --git a/ChangeLog b/ChangeLog +index eb7dbb1..4ffbedb 100644 +--- a/ChangeLog ++++ b/ChangeLog +@@ -1,3 +1,7 @@ ++krop (0.6.1) 2021-00-00 -- Armin Straub ++ ++ * Preserve links within a PDF (thanks to chrthi for doing this). ++ + krop (0.6.0) 2020-06-09 -- Armin Straub + + + Fixed aspect ratios, like letter size, can be chosen for selections. +diff --git a/krop/mainwindow.py b/krop/mainwindow.py +index fd1ae32..e8adadf 100644 +--- a/krop/mainwindow.py ++++ b/krop/mainwindow.py +@@ -413,6 +413,7 @@ def slotKrop(self): + pdf = PdfFile() + pdf.loadFromFile(inputFileName) + cropper = PdfCropper() ++ cropper.copyDocumentRoot(pdf) + for nr in pages: + c = self.viewer.cropValues(nr) + cropper.addPageCropped(pdf, nr, c, alwaysinclude, rotation) +diff --git a/krop/pdfcropper.py b/krop/pdfcropper.py +index 679c6fc..db30646 100644 +--- a/krop/pdfcropper.py ++++ b/krop/pdfcropper.py +@@ -55,6 +55,8 @@ def writeToFile(self, filename): + stream.close() + def addPageCropped(self, pdffile, pagenumber, croplist, rotate=0): + pass ++ def copyDocumentRoot(self, pdffile): ++ pass + + + class PyPdfFile(AbstractPdfFile): +@@ -110,6 +112,15 @@ def cropPage(self, page, crop, rotate): + if rotate != 0: + page.rotateClockwise(rotate) + ++ def copyDocumentRoot(self, pdffile): ++ # Sounds promising in PyPDF2 (see PdfFileWriter.cloneDocumentFromReader), ++ # but doesn't seem to produce a readable PDF: ++ # self.output.cloneReaderDocumentRoot(pdffile.reader) ++ # Instead, this copies at least the named destinations for links: ++ for dest in pdffile.reader.namedDestinations.values(): ++ self.output.addNamedDestinationObject(dest) ++ ++ + def optimizePdfGhostscript(oldfilename, newfilename): + import subprocess + subprocess.check_call(('gs', '-sDEVICE=pdfwrite', '-sOutputFile=' + newfilename, diff --git a/app-text/krop/files/krop-0.6.0-pikepdf.patch b/app-text/krop/files/krop-0.6.0-pikepdf.patch new file mode 100644 index 000000000000..17f59f2f72b3 --- /dev/null +++ b/app-text/krop/files/krop-0.6.0-pikepdf.patch @@ -0,0 +1,150 @@ +From b1d17b605088e118a8799fd027a892310e00d29e Mon Sep 17 00:00:00 2001 +From: Hongzhuo Liang +Date: Fri, 27 Jan 2023 17:57:04 +0100 +Subject: [PATCH] support pikepdf instead of pypdf2 + +--- + krop/mainwindow.py | 1 - + krop/pdfcropper.py | 79 ++++++++++++++-------------------------------- + 2 files changed, 24 insertions(+), 56 deletions(-) + +diff --git a/krop/mainwindow.py b/krop/mainwindow.py +index e8adadf..fd1ae32 100644 +--- a/krop/mainwindow.py ++++ b/krop/mainwindow.py +@@ -413,7 +413,6 @@ def slotKrop(self): + pdf = PdfFile() + pdf.loadFromFile(inputFileName) + cropper = PdfCropper() +- cropper.copyDocumentRoot(pdf) + for nr in pages: + c = self.viewer.cropValues(nr) + cropper.addPageCropped(pdf, nr, c, alwaysinclude, rotation) +diff --git a/krop/pdfcropper.py b/krop/pdfcropper.py +index db30646..42500de 100644 +--- a/krop/pdfcropper.py ++++ b/krop/pdfcropper.py +@@ -15,23 +15,8 @@ + + import copy + import sys ++from pikepdf import Pdf + +-# Unless specified otherwise, use PyPDF2 instead of pyPdf if available. +-usepypdf2 = '--no-PyPDF2' not in sys.argv +-if usepypdf2: +- try: +- from PyPDF2 import PdfFileReader, PdfFileWriter +- except ImportError: +- usepypdf2 = False +-if not usepypdf2: +- try: +- from pyPdf import PdfFileReader, PdfFileWriter +- except ImportError: +- _msg = "Please install PyPDF2 (or its predecessor pyPdf) first."\ +- "\n\tOn recent versions of Ubuntu, the following should do the trick:"\ +- "\n\tsudo apt-get install python-pypdf2"\ +- "\n\t(or, if using python3) sudo apt-get install python3-pypdf2" +- raise RuntimeError(_msg) + + class PdfEncryptedError(Exception): + pass +@@ -55,8 +40,6 @@ def writeToFile(self, filename): + stream.close() + def addPageCropped(self, pdffile, pagenumber, croplist, rotate=0): + pass +- def copyDocumentRoot(self, pdffile): +- pass + + + class PyPdfFile(AbstractPdfFile): +@@ -64,23 +47,16 @@ class PyPdfFile(AbstractPdfFile): + def __init__(self): + self.reader = None + def loadFromStream(self, stream): +- if usepypdf2: +- self.reader = PdfFileReader(stream, strict=False) +- else: +- self.reader = PdfFileReader(stream) +- if self.reader.isEncrypted: +- try: +- if not self.reader.decrypt(''): +- raise PdfEncryptedError +- except: +- raise PdfEncryptedError +- def getPage(self, nr): +- page = self.reader.getPage(nr-1) ++ self.reader = Pdf.open(stream) ++ if self.reader.is_encrypted: ++ raise PdfEncryptedError ++ + + class PyPdfCropper(AbstractPdfCropper): + """Implementation of PdfCropper using pyPdf""" + def __init__(self): +- self.output = PdfFileWriter() ++ self.pdf = Pdf.new() ++ + def writeToStream(self, stream): + # For certain large pdf files, PdfFileWriter.write() causes the error: + # maximum recursion depth exceeded while calling a Python object +@@ -88,37 +64,31 @@ def writeToStream(self, stream): + # We therefore temporarily increase the recursion limit. + old_reclimit = sys.getrecursionlimit() + sys.setrecursionlimit(10000) +- self.output.write(stream) ++ self.pdf.save(stream) + sys.setrecursionlimit(old_reclimit) ++ + def addPageCropped(self, pdffile, pagenumber, croplist, alwaysinclude, rotate=0): +- page = pdffile.reader.getPage(pagenumber) ++ page = pdffile.reader.pages[pagenumber] + if not croplist and alwaysinclude: +- self.output.addPage(page) ++ self.pdf.pages.append(page) + for c in croplist: +- newpage = copy.copy(page) +- self.cropPage(newpage, c, rotate) +- self.output.addPage(newpage) +- def cropPage(self, page, crop, rotate): ++ new_box = self.getCropPageParm(page, c) ++ # Update the various PDF boxes ++ new_page = copy.copy(page) ++ new_page.mediabox = new_box ++ new_page.cropbox = new_box ++ new_page.trimbox = new_box ++ if rotate != 0: ++ new_page.rotate(rotate, True) ++ self.pdf.pages.append(new_page) ++ ++ def getCropPageParm(self, page, crop): + # Note that the coordinate system is up-side down compared with Qt. +- x0, y0 = page.cropBox.lowerLeft +- x1, y1 = page.cropBox.upperRight ++ x0, y0, x1, y1 = page.cropbox + x0, y0, x1, y1 = float(x0), float(y0), float(x1), float(y1) + x0, x1 = x0+crop[0]*(x1-x0), x1-crop[2]*(x1-x0) + y0, y1 = y0+crop[3]*(y1-y0), y1-crop[1]*(y1-y0) +- # Update the various PDF boxes +- for box in (page.artBox, page.bleedBox, page.cropBox, page.mediaBox, page.trimBox): +- box.lowerLeft = (x0, y0) +- box.upperRight = (x1, y1) +- if rotate != 0: +- page.rotateClockwise(rotate) +- +- def copyDocumentRoot(self, pdffile): +- # Sounds promising in PyPDF2 (see PdfFileWriter.cloneDocumentFromReader), +- # but doesn't seem to produce a readable PDF: +- # self.output.cloneReaderDocumentRoot(pdffile.reader) +- # Instead, this copies at least the named destinations for links: +- for dest in pdffile.reader.namedDestinations.values(): +- self.output.addNamedDestinationObject(dest) ++ return [x0, y0, x1, y1] + + + def optimizePdfGhostscript(oldfilename, newfilename): +@@ -128,4 +98,3 @@ def optimizePdfGhostscript(oldfilename, newfilename): + + PdfFile = PyPdfFile + PdfCropper = PyPdfCropper +- diff --git a/app-text/krop/krop-0.6.0-r2.ebuild b/app-text/krop/krop-0.6.0-r2.ebuild new file mode 100644 index 000000000000..830a5e54f24d --- /dev/null +++ b/app-text/krop/krop-0.6.0-r2.ebuild @@ -0,0 +1,47 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=7 +PYTHON_COMPAT=( python3_{9,10} ) +DISTUTILS_USE_SETUPTOOLS=rdepend + +inherit desktop distutils-r1 xdg-utils + +if [[ ${PV} == 9999 ]] ; then + inherit git-r3 + EGIT_REPO_URI="https://github.com/arminstraub/krop.git" +else + SRC_URI="https://github.com/arminstraub/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz" + KEYWORDS="~amd64 ~x86" +fi + +DESCRIPTION="A tool to crop PDF files" +HOMEPAGE="http://arminstraub.com/software/krop" + +LICENSE="GPL-3" +SLOT="0" +IUSE="" + +PATCHES=( + "${FILESDIR}/${P}-links.patch" + "${FILESDIR}/${P}-pikepdf.patch" +) + +RDEPEND="dev-python/python-poppler-qt5[${PYTHON_USEDEP}] + dev-python/pikepdf[${PYTHON_USEDEP}] + dev-python/PyQt5[${PYTHON_USEDEP},gui,widgets]" + +src_install() { + distutils-r1_src_install + domenu "${WORKDIR}/${P}/${PN}.desktop" +} + +pkg_postinst() { + xdg_mimeinfo_database_update + xdg_desktop_database_update +} + +pkg_postrm() { + xdg_mimeinfo_database_update + xdg_desktop_database_update +} diff --git a/app-text/krop/metadata.xml b/app-text/krop/metadata.xml index cb675f253c1d..0581997322f1 100644 --- a/app-text/krop/metadata.xml +++ b/app-text/krop/metadata.xml @@ -8,4 +8,7 @@ printing@gentoo.org Gentoo Printing Project + + arminstraub/krop + -- cgit v1.2.3