texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * tp/Texinfo/Convert/Converter.pm (txt_image_text


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/Converter.pm (txt_image_text), tp/Texinfo/Convert/Plaintext.pm (_image_text), tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/Info.pm: move _image_text() from Texinfo::Convert::Plaintext to Texinfo::Convert::Converter and rename as txt_image_text().
Date: Sat, 04 Sep 2021 11:06:35 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new e9272d9  * tp/Texinfo/Convert/Converter.pm (txt_image_text), 
tp/Texinfo/Convert/Plaintext.pm (_image_text), tp/Texinfo/Convert/DocBook.pm, 
tp/Texinfo/Convert/Info.pm: move _image_text() from Texinfo::Convert::Plaintext 
to Texinfo::Convert::Converter and rename as txt_image_text().
e9272d9 is described below

commit e9272d9ea2bfb5ee65a6d9e9ba29527b0b105879
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Sep 4 17:06:27 2021 +0200

    * tp/Texinfo/Convert/Converter.pm (txt_image_text),
    tp/Texinfo/Convert/Plaintext.pm (_image_text),
    tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/Info.pm:
    move _image_text() from Texinfo::Convert::Plaintext to
    Texinfo::Convert::Converter and rename as txt_image_text().
---
 ChangeLog                       |  8 ++++++++
 tp/TODO                         |  4 ----
 tp/Texinfo/Convert/Converter.pm | 42 ++++++++++++++++++++++++++++++++++++++++-
 tp/Texinfo/Convert/DocBook.pm   |  3 +--
 tp/Texinfo/Convert/Info.pm      |  2 +-
 tp/Texinfo/Convert/Plaintext.pm | 41 +---------------------------------------
 6 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 966ef4c..40bb4e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2021-09-04  Patrice Dumas  <pertusus@free.fr>
 
+       * tp/Texinfo/Convert/Converter.pm (txt_image_text),
+       tp/Texinfo/Convert/Plaintext.pm (_image_text),
+       tp/Texinfo/Convert/DocBook.pm, tp/Texinfo/Convert/Info.pm:
+       move _image_text() from Texinfo::Convert::Plaintext to
+       Texinfo::Convert::Converter and rename as txt_image_text().
+
+2021-09-04  Patrice Dumas  <pertusus@free.fr>
+
        * tp/Texinfo/Convert/Converter.pm, tp/Texinfo/Convert/DocBook.pm,
        tp/Texinfo/Convert/HTML.pm, tp/Texinfo/Convert/IXIN.pm,
        tp/Texinfo/Convert/IXINSXML.pm, tp/Texinfo/Convert/Info.pm,
diff --git a/tp/TODO b/tp/TODO
index 331d2d5..37db4c8 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -27,10 +27,6 @@ use Texinfo::Convert::Converter;
 
 complete_indices, gdt, some code in Text: add documentlanguage arg to gdt
 
-Texinfo/Convert/DocBook.pm
-use Texinfo::Convert::Plaintext;
-# FIXME use _image_text
-
 not internal (maybe move?)
 Texinfo::Common::_convert_text_options
 
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 0519fd3..d66ffc5 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -930,6 +930,46 @@ sub _create_destination_directory($)
   return 1;
 }
 
+sub txt_image_text($$$)
+{
+  my ($self, $root, $basefile) = @_;
+
+  my $txt_file = Texinfo::Common::locate_include_file($self, $basefile.'.txt');
+  if (!defined($txt_file)) {
+    return undef;
+  } else {
+    my $filehandle = do { local *FH };
+    if (open ($filehandle, $txt_file)) {
+      my $enc = $root->{'extra'}->{'input_perl_encoding'};
+      binmode($filehandle, ":encoding($enc)")
+        if ($enc);
+      my $result = '';
+      my $max_width = 0;
+      while (<$filehandle>) {
+        my $width = Texinfo::Convert::Unicode::string_width($_);
+        if ($width > $max_width) {
+          $max_width = $width;
+        }
+        $result .= $_;
+      }
+      # remove last end of line
+      chomp ($result);
+      if (!close ($filehandle)) {
+        $self->document_warn($self,
+           sprintf(__("error on closing image text file %s: %s"),
+                                     $txt_file, $!));
+      }
+      return ($result, $max_width);
+    } else {
+      $self->line_warn($self,
+                  sprintf(__("\@image file `%s' unreadable: %s"),
+                               $txt_file, $!), $root->{'line_nr'});
+    }
+  }
+  return undef;
+}
+
+
 sub float_type_number($$)
 {
   my $self = shift;
@@ -942,7 +982,7 @@ sub float_type_number($$)
   }
 
   my $tree;
-  if ($type) {            
+  if ($type) {
     if (defined($float->{'number'})) {
       $tree = $self->gdt("{float_type} {float_number}",
           {'float_type' => $type,
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 216722f..d16cdaa 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -1002,8 +1002,7 @@ sub _convert($$;$)
                .$self->xml_protect_text($file->[0])
                ."\" format=\"$file->[1]\"></imagedata></imageobject>";
           }
-          my ($image_text, $image_width)
-            = $self->Texinfo::Convert::Plaintext::_image_text($root, 
$basefile);
+          my ($image_text, $image_width) = $self->txt_image_text($root, 
$basefile);
           if (defined($image_text)) {
             $result .= "<textobject><literallayout>"
                .$self->_protect_text($image_text)
diff --git a/tp/Texinfo/Convert/Info.pm b/tp/Texinfo/Convert/Info.pm
index 1e88a6a..da952c8 100644
--- a/tp/Texinfo/Convert/Info.pm
+++ b/tp/Texinfo/Convert/Info.pm
@@ -505,7 +505,7 @@ sub _image($$)
         last; 
       }
     }
-    my ($text, $width) = $self->_image_text($root, $basefile);
+    my ($text, $width) = $self->txt_image_text($root, $basefile);
     my $alt;
     if (defined($root->{'args'}->[3])
         and @{$root->{'args'}->[3]->{'contents'}}) {
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 2e184d1..080a020 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -1426,45 +1426,6 @@ sub ensure_end_of_line($$)
   return $text;
 }
 
-sub _image_text($$$)
-{
-  my ($self, $root, $basefile) = @_;
-
-  my $txt_file = $self->Texinfo::Common::locate_include_file($basefile.'.txt');
-  if (!defined($txt_file)) {
-    return undef;
-  } else {
-    my $filehandle = do { local *FH };
-    if (open ($filehandle, $txt_file)) {
-      my $enc = $root->{'extra'}->{'input_perl_encoding'};
-      binmode($filehandle, ":encoding($enc)")
-        if ($enc);
-      my $result = '';
-      my $max_width = 0;
-      while (<$filehandle>) {
-        my $width = Texinfo::Convert::Unicode::string_width($_);
-        if ($width > $max_width) {
-          $max_width = $width;
-        }
-        $result .= $_;
-      }
-      # remove last end of line
-      chomp ($result);
-      if (!close ($filehandle)) {
-        $self->document_warn($self,
-           sprintf(__("error on closing image text file %s: %s"),
-                                     $txt_file, $!));
-      }
-      return ($result, $max_width);
-    } else {
-      $self->line_warn($self,
-                  sprintf(__("\@image file `%s' unreadable: %s"),
-                               $txt_file, $!), $root->{'line_nr'});
-    }
-  }
-  return undef;
-}
-
 sub _image_formatted_text($$$$)
 {
   my ($self, $root, $basefile, $text) = @_;
@@ -1495,7 +1456,7 @@ sub _image($$)
     my $basefile = Texinfo::Convert::Text::convert_to_text(
      {'contents' => $root->{'args'}->[0]->{'contents'}},
      {'code' => 1, %{$self->{'convert_text_options'}}});
-    my ($text, $width) = $self->_image_text($root, $basefile);
+    my ($text, $width) = $self->txt_image_text($root, $basefile);
     my $result = $self->_image_formatted_text($root, $basefile, $text);
     my $lines_count = ($result =~ tr/\n/\n/);
     if (!defined($width)) {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]