Blob Blame History Raw
From a92a4d26cfae9832e70bf8a8ef703f9fab02ed78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 14 Dec 2020 12:19:58 +0100
Subject: [PATCH] Keep using PDF::API2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

PDF::Builder has a license problem which prevents us from packaging it
<https://bugzilla.redhat.com/show_bug.cgi?id=1894911#add_comment>.

This patch revers most of the parts of an upstream "Switch from
PDF::API2 to PDF::Builder to improve TIFF handling and compression
options" commit 8107da73d9f40d3e816ea2465733b0b42d07e0f7.

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 History                               |  4 ---
 MANIFEST                              |  1 -
 Makefile.PL                           |  2 +-
 bin/gscan2pdf                         | 10 +++---
 debian/changelog                      |  4 ---
 debian/control                        |  6 ++--
 gscan2pdf.Suse.spec                   |  4 +--
 gscan2pdf.spec                        |  4 +--
 lib/Gscan2pdf/Dialog/Save.pm          |  6 ++--
 lib/Gscan2pdf/Document.pm             |  8 ++---
 t/101_Document.t                      |  4 +--
 t/1112_save_pdf_with_locale.t         |  2 +-
 t/1121_save_pdf_with_text.t           |  2 +-
 t/1122_save_pdf_with_hocr.t           |  2 +-
 t/1123_save_pdf_with_utf8.t           |  2 +-
 t/1124_save_pdf_with_non-utf8.t       |  2 +-
 t/1126_save_pdf_without_font.t        |  2 +-
 t/1127_save_pdf_g4.t                  | 51 ---------------------------
 t/1128_save_pdf_with_sbs_hocr.t       |  2 +-
 t/114_cancel_save_pdf.t               |  2 +-
 t/1161_save_multipage_pdf_with_utf8.t |  2 +-
 t/1162_save_multipage_pdf.t           |  2 +-
 22 files changed, 33 insertions(+), 91 deletions(-)
 delete mode 100644 t/1127_save_pdf_g4.t

diff --git a/History b/History
index b5e30cb6..c5a38f15 100644
--- a/History
+++ b/History
@@ -50,10 +50,6 @@
 
 2.10.0 (31.10.2020):
 
-* Switch from PDF::API2 to PDF::Builder to improve TIFF handling and compression
-  options.
-  Closes Debian bugs 602486 (heavily distored scans) and
-  703768 (parts of the page translated to the right, black border)
 * Switch from internal image viewer to Gtk3::ImageView
   (based on internal image viewer)
 * Update to German translation (thanks to Eugen Artus)
diff --git a/MANIFEST b/MANIFEST
index 97844c78..70302a2d 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -237,7 +237,6 @@ t/1123_save_pdf_with_utf8.t
 t/1124_save_pdf_with_non-utf8.t
 t/1125_save_pdf_with_1bpp.t
 t/1126_save_pdf_without_font.t
-t/1127_save_pdf_g4.t
 t/1128_save_pdf_with_sbs_hocr.t
 t/113_save_pdf_with_downsample.t
 t/114_cancel_save_pdf.t
diff --git a/Makefile.PL b/Makefile.PL
index 6502e12a..32e0c0dc 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -49,7 +49,7 @@ WriteMakefile(
         Image::Magick    => 0,
         Locale::gettext  => 1.05,
         Config::General  => 2.40,
-        PDF::Builder     => 0,
+        PDF::API2        => 0,
         Set::IntSpan     => 1.10,
         GooCanvas2       => 0,
         Readonly         => 0,
diff --git a/bin/gscan2pdf b/bin/gscan2pdf
index 49959ead..cd225a9f 100755
--- a/bin/gscan2pdf
+++ b/bin/gscan2pdf
@@ -92,7 +92,7 @@ use File::Copy;
 use File::Temp;                 # To create temporary files
 use File::Path qw(remove_tree);
 use Glib qw(TRUE FALSE);        # To get TRUE and FALSE
-use PDF::Builder;
+use PDF::API2;
 use Getopt::Long;
 use Set::IntSpan 1.10;          # For size method for page numbering issues
 use Proc::Killfam;
@@ -233,7 +233,7 @@ if ( $Gscan2pdf::Document::VERSION ne $VERSION ) {
 #$logger->info( 'Using GtkImageView version ',
 #    Gtk3::ImageView->library_version );
 $logger->info("Using Gtk3::ImageView version $Gtk3::ImageView::VERSION");
-$logger->info("Using PDF::Builder version $PDF::Builder::VERSION");
+$logger->info("Using PDF::API2 version $PDF::API2::VERSION");
 $logger->info( 'Using Sane version ' . join $DOT, Image::Sane->get_version );
 $logger->info("Using libimage-sane-perl version $Image::Sane::VERSION");
 
@@ -1044,7 +1044,7 @@ sub check_dependencies {
                     [ 'convert', 'rose:', $tempimg ] );
                 my $temppdf =
                   File::Temp->new( DIR => $session, SUFFIX => '.pdf' );
-                my $pdfobj = PDF::Builder->new( -file => $temppdf );
+                my $pdfobj = PDF::API2->new( -file => $temppdf );
                 my $page   = $pdfobj->page;
                 my $size   = $Gscan2pdf::Document::POINTS_PER_INCH;
                 $page->mediabox( $size, $size );
@@ -7514,7 +7514,7 @@ Displays the program version and exits.
 =back
 
 Scanning is handled with SANE via scanimage.
-PDF conversion is done by PDF::Builder.
+PDF conversion is done by PDF::API2.
 TIFF export is handled by libtiff (faster and smaller memory footprint for
 multipage files).
 
@@ -7630,7 +7630,7 @@ A simple interface to Gtk3's complex MVC list widget
 
 Using libc functions for internationalisation in Perl
 
-=item libpdf-builder-perl
+=item libpdf-api2-perl
 
 provides the functions for creating PDF documents in Perl
 
diff --git a/debian/changelog b/debian/changelog
index 5d4235ed..c6e35a76 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -25,10 +25,6 @@ gscan2pdf (2.10.0-1) unstable; urgency=low
   * New upstream release
   * Make dependency liblocale-codes-perl versioned
     Closes: #972218 (gscan2pdf should depend on liblocale-codes-perl)
-  * Removed dependency libpdf-api2-perl
-  * Added new dependency libpdf-builder-perl.
-    Closes: #602486 (heavily distored scans)
-    Closes: #703768 (parts of the page translated to the right, black border)
   * Added new build dependency fonts-noto-extra to ensure non-ascii fonts
     available for tests.
 
diff --git a/debian/control b/debian/control
index 931b711e..13e8a404 100644
--- a/debian/control
+++ b/debian/control
@@ -22,7 +22,7 @@ Build-Depends-Indep: fonts-noto-extra,
                      liblog-log4perl-perl,
                      liblist-moreutils-perl,
                      libossp-uuid-perl | libdata-uuid-perl,
-                     libpdf-builder-perl,
+                     libpdf-api2-perl,
                      libproc-processtable-perl,
                      libreadonly-perl,
                      librsvg2-common,
@@ -62,7 +62,7 @@ Depends: imagemagick,
          liblocale-gettext-perl (>= 1.05),
          liblog-log4perl-perl,
          libossp-uuid-perl | libdata-uuid-perl,
-         libpdf-builder-perl,
+         libpdf-api2-perl,
          libproc-processtable-perl,
          libreadonly-perl,
          librsvg2-common,
@@ -88,7 +88,7 @@ Description: GUI to produce PDFs or DjVus from scanned documents
  OCR can be used to recognise text in the scans, and the output
  embedded in the PDF or DjVu.
  .
- PDF conversion is done by PDF::Builder.
+ PDF conversion is done by PDF::API2.
  .
  The resulting document may be saved as a PDF, DjVu, multipage TIFF file, or
  single page image file.
diff --git a/gscan2pdf.Suse.spec b/gscan2pdf.Suse.spec
index 8f9a2c93..6bf6f9b6 100644
--- a/gscan2pdf.Suse.spec
+++ b/gscan2pdf.Suse.spec
@@ -19,7 +19,7 @@ Requires:       perl(Gtk3::ImageView)
 Requires:       perl(Image::Magick)
 Requires:       perl(List::MoreUtils)
 Requires:       perl(Log::Log4perl)
-Requires:       perl(PDF::Builder)
+Requires:       perl(PDF::API2)
 Requires:       perl(Proc::Killfam)
 Requires:       perl(Readonly)
 Requires:       perl(Sane)
@@ -43,7 +43,7 @@ scanimage or scanadf, and can scan multiple pages at once. It presents a
 thumbnail view of scanned pages, and permits simple operations such as rotating
 and deleting pages. 
 
-PDF conversion is done by PDF::Builder.
+PDF conversion is done by PDF::API2.
 
 The resulting document may be saved as a PDF, DjVu or a multipage TIFF file.
 
diff --git a/gscan2pdf.spec b/gscan2pdf.spec
index 4915cc5d..3716209d 100644
--- a/gscan2pdf.spec
+++ b/gscan2pdf.spec
@@ -15,7 +15,7 @@ BuildRequires: gettext, desktop-file-utils
 Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
 Requires: perl(Gtk3::ImageView), perl-Gtk2-Ex-Simple-List
 Requires: perl-Sane, perl-Locale-gettext
-Requires: sane-utils, libtiff-tools, perl(PDF::Builder)
+Requires: sane-utils, libtiff-tools, perl(PDF::API2)
 Requires: perl(Config::General), ImageMagick-perl, ImageMagick
 Requires: librsvg-2-2, perl(Set::Intspan), perl(List::MoreUtils)
 Requires: perl-HTML-Parser, perl(Goo::Canvas), perl-Proc-ProcessTable
@@ -33,7 +33,7 @@ scanimage or scanadf, and can scan multiple pages at once. It presents a
 thumbnail view of scanned pages, and permits simple operations such as rotating
 and deleting pages. 
 
-PDF conversion is done by PDF::Builder.
+PDF conversion is done by PDF::API2.
 
 The resulting document may be saved as a PDF or a multipage TIFF file.
 
diff --git a/lib/Gscan2pdf/Dialog/Save.pm b/lib/Gscan2pdf/Dialog/Save.pm
index fd95c3fa..dd1e4341 100644
--- a/lib/Gscan2pdf/Dialog/Save.pm
+++ b/lib/Gscan2pdf/Dialog/Save.pm
@@ -807,8 +807,10 @@ sub add_pdf_options {
             'packbits', __('Packbits'),
             __('Compress output with Packbits encoding.')
         ],
-        [ 'g3', __('G3'), __('Compress output with CCITT Group 3 encoding.') ],
-        [ 'g4', __('G4'), __('Compress output with CCITT Group 4 encoding.') ],
+
+      # g3 and 4 give an error message
+      #  [ 'g3', __('G3'), __('Compress output with CCITT Group 3 encoding.') ],
+      #  [ 'g4', __('G4'), __('Compress output with CCITT Group 4 encoding.') ],
         [ 'png',  __('PNG'),  __('Compress output with PNG encoding.') ],
         [ 'jpg',  __('JPEG'), __('Compress output with JPEG encoding.') ],
         [ 'none', __('None'), __('Use no compression algorithm on output.') ],
diff --git a/lib/Gscan2pdf/Document.pm b/lib/Gscan2pdf/Document.pm
index 8570a466..73b4ebf4 100644
--- a/lib/Gscan2pdf/Document.pm
+++ b/lib/Gscan2pdf/Document.pm
@@ -31,7 +31,7 @@ use IPC::Open3 'open3';
 use Symbol;            # for gensym
 use Try::Tiny;
 use Set::IntSpan 1.10;    # For size method for page numbering issues
-use PDF::Builder;
+use PDF::API2;
 use English qw( -no_match_vars );    # for $PROCESS_ID, $INPUT_RECORD_SEPARATOR
                                      # $CHILD_ERROR
 use POSIX qw(:sys_wait_h strftime);
@@ -3414,7 +3414,7 @@ EOS
     return;
 }
 
-# return if the given PDF::Builder font can encode the given character
+# return if the given PDF::API2 font can encode the given character
 
 sub font_can_char {
     my ( $font, $char ) = @_;
@@ -3427,14 +3427,14 @@ sub _thread_save_pdf {
     my $pagenr = 0;
     my ( $cache, $pdf, $error, $message );
 
-    # Create PDF with PDF::Builder
+    # Create PDF with PDF::API2
     $self->{message} = __('Setting up PDF');
     my $filename = $options{path};
     if ( _need_temp_pdf(%options) ) {
         $filename = File::Temp->new( DIR => $options{dir}, SUFFIX => '.pdf' );
     }
     try {
-        $pdf = PDF::Builder->new( -file => $filename );
+        $pdf = PDF::API2->new( -file => $filename );
     }
     catch {
         $logger->error("Caught error creating PDF $filename: $_");
diff --git a/t/101_Document.t b/t/101_Document.t
index 703f01a3..0942e9a5 100644
--- a/t/101_Document.t
+++ b/t/101_Document.t
@@ -5,7 +5,7 @@ use Test::More tests => 67;
 use Glib 1.210 qw(TRUE FALSE);
 use Gtk3 -init;    # Could just call init separately
 use Encode;
-use PDF::Builder;
+use PDF::API2;
 use File::stat;
 use Date::Calc qw(Time_to_Date);
 
@@ -513,7 +513,7 @@ is(
     'stderr open3 running unknown command'
 );
 
-my $pdf  = PDF::Builder->new;
+my $pdf  = PDF::API2->new;
 my $font = $pdf->corefont('Times-Roman');
 is( Gscan2pdf::Document::font_can_char( $font, decode_utf8('a') ),
     TRUE, '_font_can_char a' );
diff --git a/t/1112_save_pdf_with_locale.t b/t/1112_save_pdf_with_locale.t
index 4993b03e..28d6dce3 100644
--- a/t/1112_save_pdf_with_locale.t
+++ b/t/1112_save_pdf_with_locale.t
@@ -7,7 +7,7 @@ use POSIX qw(locale_h);
 
 BEGIN {
     use Gscan2pdf::Document;
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1121_save_pdf_with_text.t b/t/1121_save_pdf_with_text.t
index 10fa6e37..9ac3a6da 100644
--- a/t/1121_save_pdf_with_text.t
+++ b/t/1121_save_pdf_with_text.t
@@ -6,7 +6,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1122_save_pdf_with_hocr.t b/t/1122_save_pdf_with_hocr.t
index 731d52d1..92a58e50 100644
--- a/t/1122_save_pdf_with_hocr.t
+++ b/t/1122_save_pdf_with_hocr.t
@@ -6,7 +6,7 @@ use Test::More tests => 2;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1123_save_pdf_with_utf8.t b/t/1123_save_pdf_with_utf8.t
index b7ae9cdd..4d8d173b 100644
--- a/t/1123_save_pdf_with_utf8.t
+++ b/t/1123_save_pdf_with_utf8.t
@@ -7,7 +7,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1124_save_pdf_with_non-utf8.t b/t/1124_save_pdf_with_non-utf8.t
index fdc8f63e..60c9b8ce 100644
--- a/t/1124_save_pdf_with_non-utf8.t
+++ b/t/1124_save_pdf_with_non-utf8.t
@@ -6,7 +6,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1126_save_pdf_without_font.t b/t/1126_save_pdf_without_font.t
index 859ec1bb..258617e0 100644
--- a/t/1126_save_pdf_without_font.t
+++ b/t/1126_save_pdf_without_font.t
@@ -7,7 +7,7 @@ use Test::More tests => 3;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1127_save_pdf_g4.t b/t/1127_save_pdf_g4.t
deleted file mode 100644
index b4ae7376..00000000
--- a/t/1127_save_pdf_g4.t
+++ /dev/null
@@ -1,51 +0,0 @@
-use warnings;
-use strict;
-use IPC::System::Simple qw(system capture);
-use Test::More tests => 1;
-
-BEGIN {
-    use Gscan2pdf::Document;
-    use Gtk3 -init;    # Could just call init separately
-}
-
-#########################
-
-Gscan2pdf::Translation::set_domain('gscan2pdf');
-use Log::Log4perl qw(:easy);
-Log::Log4perl->easy_init($WARN);
-my $logger = Log::Log4perl::get_logger;
-Gscan2pdf::Document->setup($logger);
-
-# Create test image
-system(qw(convert rose: test.png));
-
-my $slist = Gscan2pdf::Document->new;
-
-# dir for temporary files
-my $dir = File::Temp->newdir;
-$slist->set_dir($dir);
-
-$slist->import_files(
-    paths             => ['test.png'],
-    finished_callback => sub {
-        $slist->save_pdf(
-            path          => 'test.pdf',
-            list_of_pages => [ $slist->{data}[0][2]{uuid} ],
-            options       => {
-                compression => 'g4',
-            },
-            finished_callback => sub { Gtk3->main_quit }
-        );
-    }
-);
-Gtk3->main;
-
-is
-  capture("pdfinfo test.pdf | grep 'Page size:'"),
-  "Page size:      70 x 46 pts\n",
-  'valid PDF created';
-
-#########################
-
-unlink 'test.pdf', 'test.png';
-Gscan2pdf::Document->quit();
diff --git a/t/1128_save_pdf_with_sbs_hocr.t b/t/1128_save_pdf_with_sbs_hocr.t
index fdad84c5..835f6b1a 100644
--- a/t/1128_save_pdf_with_sbs_hocr.t
+++ b/t/1128_save_pdf_with_sbs_hocr.t
@@ -6,7 +6,7 @@ use Test::More tests => 2;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/114_cancel_save_pdf.t b/t/114_cancel_save_pdf.t
index 2b271899..01ef30f0 100644
--- a/t/114_cancel_save_pdf.t
+++ b/t/114_cancel_save_pdf.t
@@ -6,7 +6,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
 }
 
 #########################
diff --git a/t/1161_save_multipage_pdf_with_utf8.t b/t/1161_save_multipage_pdf_with_utf8.t
index 23ed652e..633d4538 100644
--- a/t/1161_save_multipage_pdf_with_utf8.t
+++ b/t/1161_save_multipage_pdf_with_utf8.t
@@ -7,7 +7,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
     use File::Copy;
 }
 
diff --git a/t/1162_save_multipage_pdf.t b/t/1162_save_multipage_pdf.t
index 5f0dc77c..2a9bbf63 100644
--- a/t/1162_save_multipage_pdf.t
+++ b/t/1162_save_multipage_pdf.t
@@ -6,7 +6,7 @@ use Test::More tests => 1;
 BEGIN {
     use Gscan2pdf::Document;
     use Gtk3 -init;    # Could just call init separately
-    use PDF::Builder;
+    use PDF::API2;
     use File::Copy;
     use utf8;
 }
-- 
2.26.2