Package: gscan2pdf
Version: 2.11.0-1
Severity: wishlist
Tags: upstream patch

Hi,

the attached patches fix the display of rotated text
(which seems to have got lost in some of the recent refactoring ;-)

The patches are agains upstream's 2.11.2

Please consider including them into a future version of gscan2pdf
Peter


-- System Information:
Debian Release: bullseye/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (500, 'stable'), (1, 
'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-5-amd64 (SMP w/12 CPU threads)
Kernel taint flags: TAINT_CRAP
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages gscan2pdf depends on:
ii  imagemagick                            8:6.9.11.60+dfsg-1
ii  imagemagick-6.q16 [imagemagick]        8:6.9.11.60+dfsg-1
ii  libconfig-general-perl                 2.63-1
ii  libdate-calc-perl                      6.4-1.1
ii  libfilesys-df-perl                     0.92-6+b6
ii  libgoocanvas2-perl                     0.06-2
ii  libgtk3-imageview-perl                 6-1
ii  libgtk3-perl                           0.038-1
ii  libgtk3-simplelist-perl                0.21-1
ii  libhtml-parser-perl                    3.75-1+b1
ii  libimage-magick-perl                   8:6.9.11.60+dfsg-1
ii  libimage-sane-perl                     5-1+b1
ii  liblist-moreutils-perl                 0.430-2
ii  liblocale-codes-perl                   3.66-1
ii  liblocale-gettext-perl                 1.07-4+b1
ii  liblog-log4perl-perl                   1.54-1
ii  libossp-uuid-perl [libdata-uuid-perl]  1.6.2-1.5+b9
ii  libpdf-builder-perl                    3.021-2
ii  libproc-processtable-perl              0.59-2+b1
ii  libreadonly-perl                       2.050-3
ii  librsvg2-common                        2.50.3+dfsg-1
ii  libset-intspan-perl                    1.19-1.1
ii  libtiff-tools                          4.2.0-1
ii  libtry-tiny-perl                       0.30-1
hi  sane-utils                             1.0.31-4pm1

Versions of packages gscan2pdf recommends:
ii  djvulibre-bin       3.5.28-1
ii  gocr                0.52-3
ii  pdftk-java [pdftk]  3.2.2-1
ii  tesseract-ocr       4.1.1-2.1
ii  unpaper             6.1-2+b2
ii  xdg-utils           1.1.3-4

gscan2pdf suggests no packages.

-- no debconf information
>From d65fef2ac5821e0f1e449bd0667de17614e8112b Mon Sep 17 00:00:00 2001
From: Peter Marschall <pe...@adpm.de>
Date: Wed, 14 Apr 2021 20:08:29 +0200
Subject: [PATCH 1/2] Canvas: make sure rotated text is displayed correctly

Inherit textangle from superior object.

Teseract seems to add the 'textangle' attribute only to line-like elements
(like 'ocrx_line', 'ocrx_header', 'ocrx_footer') but not to the individual
words (i.e. 'ocr_word').

If the words have a 'textangle' attribute themselves, its value gets added to
the the inherited one.

Signed-off-by: Peter Marschall <pe...@adpm.de>
---
 lib/Gscan2pdf/Canvas.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/Gscan2pdf/Canvas.pm b/lib/Gscan2pdf/Canvas.pm
index 962ecffc..ba7a6d4a 100644
--- a/lib/Gscan2pdf/Canvas.pm
+++ b/lib/Gscan2pdf/Canvas.pm
@@ -483,7 +483,8 @@ sub add_box {
     my @transformation = ( 0, 0, 0 );
     if ( $parent->isa('Gscan2pdf::Canvas::Bbox') ) {
         my $parent_box = $parent->get('bbox');
-        @transformation = ( 0, $parent_box->{x}, $parent_box->{y} );
+        my $parent_textangle = $parent->get('textangle');
+        @transformation = ( $parent_textangle, $parent_box->{x}, 
$parent_box->{y} );
     }
     my %options2 = (
         parent         => $parent,
-- 
2.30.2

>From 8cecfcd009575de090ef05218a171fed893d1cc9 Mon Sep 17 00:00:00 2001
From: Peter Marschall <pe...@adpm.de>
Date: Wed, 14 Apr 2021 21:11:09 +0200
Subject: [PATCH 2/2] Bbox: show updated rotated text correctly

Scale & rotate the updated text same way it is done when creating the box.

Skip scaling & rotating if the updated text has no width to avoid dividing by 
zero.

Signed-off-by: Peter Marschall <pe...@adpm.de>
---
 lib/Gscan2pdf/Canvas/Bbox.pm | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/Gscan2pdf/Canvas/Bbox.pm b/lib/Gscan2pdf/Canvas/Bbox.pm
index 6175639a..778b5adb 100644
--- a/lib/Gscan2pdf/Canvas/Bbox.pm
+++ b/lib/Gscan2pdf/Canvas/Bbox.pm
@@ -480,12 +480,18 @@ sub update_box {
             $self->set( bbox => $selection );
             $text_w->set_simple_transform( 0, 0, 1, 0 );
             my $bounds    = $text_w->get_bounds;
+            my @transformation = @{ $self->get('transformation') };
+            my $rotation = (@transformation) ? $transformation[0] : 0;
             my $textangle = $self->get('textangle');
-            my $scale =
-              ( $textangle ? $selection->{height} : $selection->{width} ) /
-              ( $bounds->x2 - $bounds->x1 );
-
-            $self->transform_text( $scale, $textangle );
+            my $angle  = -( $textangle + $rotation ) % $_360_DEGREES;
+            # don't scale & rotate if text has no width
+            if ( $bounds->x1 != $bounds->x2 ) {
+                my $scale =
+                  ( $angle ? $selection->{height} : $selection->{width} ) /
+                  ( $bounds->x2 - $bounds->x1 );
+
+                $self->transform_text( $scale, $angle );
+            }
         }
 
         my $new_conf = $self->get('confidence');
-- 
2.30.2

Reply via email to