texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Line length using counter for @listoffloats


From: Gavin D. Smith
Subject: branch master updated: Line length using counter for @listoffloats
Date: Fri, 08 Dec 2023 16:10:09 -0500

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

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 4be941d369 Line length using counter for @listoffloats
4be941d369 is described below

commit 4be941d369ca166e783911a276514e844736934a
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Fri Dec 8 21:10:01 2023 +0000

    Line length using counter for @listoffloats
    
    * tp/Texinfo/Convert/Plaintext.pm (_convert) <@listoffloats>:
    Eliminate call to convert_line, followed by call to
    Texinfo::Convert::Unicode::string_width.  Instead, format the entry
    using a line formatter object, followed by a call to
    Texinfo::Convert::Paragraph::counter to get the line length.
    
    This is needed for future plans for this code, where convert_line
    will return an already-encoded string which can't be passed
    to string_width.
---
 ChangeLog                       | 14 ++++++++++++++
 tp/Texinfo/Convert/Plaintext.pm | 39 +++++++++++++++++++++++++++++++--------
 2 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 168a0f33f8..a861a68c1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2023-12-08  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Line length using counter for @listoffloats
+
+       * tp/Texinfo/Convert/Plaintext.pm (_convert) <@listoffloats>:
+       Eliminate call to convert_line, followed by call to
+       Texinfo::Convert::Unicode::string_width.  Instead, format the entry
+       using a line formatter object, followed by a call to
+       Texinfo::Convert::Paragraph::counter to get the line length.
+
+       This is needed for future plans for this code, where convert_line
+       will return an already-encoded string which can't be passed
+       to string_width.
+
 2023-12-08  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/XS/Makefile.am (main/accent_tables_8bit_codepoints.c)
diff --git a/tp/Texinfo/Convert/Plaintext.pm b/tp/Texinfo/Convert/Plaintext.pm
index 4fc36349a0..2ccbbb6def 100644
--- a/tp/Texinfo/Convert/Plaintext.pm
+++ b/tp/Texinfo/Convert/Plaintext.pm
@@ -2978,23 +2978,46 @@ sub _convert($$)
 
           my $float_entry = $self->float_type_number($float);
           next if !defined($float_entry);
+
+          my $formatter = $self->new_formatter('line');
+          my $container = $formatter->{'container'};
+          push @{$self->{'formatters'}}, $formatter;
+
+          # Output in format "* $float_entry_text: $float_label_text.".
+
+          $result .= _count_added($self, $container,
+                                  add_next($container, '* '));
+
           $float_entry->{'type'} = 'frenchspacing';
-          my $float_entry_text = $self->convert_line($float_entry);
+          $result .= $self->_convert($float_entry);
 
-          my $float_label_text = $self->convert_line({'type' => '_code',
-             'contents' => [$float->{'args'}->[1]]});
+          $result .= _count_added($self, $container,
+                                  add_next($container, ': '));
 
-          # no translation here, this is required Info format.
-          my $float_line = "* $float_entry_text: $float_label_text.";
+          $result .= $self->_convert({'type' => '_code',
+                          'contents' => [$float->{'args'}->[1]]});
+          $result .= _count_added($self, $container,
+                                  add_next($container, '.'));
+          $result .= _count_added($self, $container,
+            Texinfo::Convert::Paragraph::end($container));
+
+          # NB we trust that only $container was used to format text
+          # inside the call to convert_line so that all output text is
+          # counted.
           my $line_width
-             = Texinfo::Convert::Unicode::string_width($float_line);
+             = Texinfo::Convert::Paragraph::counter($formatter->{'container'});
+
+          pop @{$self->{'formatters'}};
+
           if ($line_width > $listoffloat_entry_length) {
-            $float_line .= "\n" . ' ' x $listoffloat_entry_length;
+            $result .= "\n" . ' ' x $listoffloat_entry_length;
             $lines_count++;
           } else {
-            $float_line .= ' ' x ($listoffloat_entry_length - $line_width);
+            $result .= ' ' x ($listoffloat_entry_length - $line_width);
           }
           $line_width = $listoffloat_entry_length;
+
+          my $float_line = '';
           my $caption;
           if ($float->{'extra'}->{'shortcaption'}) {
             $caption = $float->{'extra'}->{'shortcaption'};



reply via email to

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