texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp/Texinfo Parser.pm Convert/Info.pm Co...


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Parser.pm Convert/Info.pm Co...
Date: Fri, 31 Dec 2010 12:14:07 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        10/12/31 12:14:07

Modified files:
        tp/Texinfo     : Parser.pm 
        tp/Texinfo/Convert: Info.pm Plaintext.pm 

Log message:
        Accept and undef encoding.
        Update anchor bytes count when aligning in @flushright or @center.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.171&r2=1.172
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Info.pm?cvsroot=texinfo&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.41&r2=1.42

Patches:
Index: Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -b -r1.171 -r1.172
--- Parser.pm   30 Dec 2010 17:36:51 -0000      1.171
+++ Parser.pm   31 Dec 2010 12:14:06 -0000      1.172
@@ -96,7 +96,7 @@
 {
   my $string = shift;
   my $encoding = shift;
-  if ($encoding ne 'us-ascii' and Encode::resolve_alias($encoding)) {
+  if (Encode::resolve_alias($encoding)) {
     return Encode::decode($encoding, $string);
   }
   return $string;
@@ -118,9 +118,9 @@
   my $saved_LANGUAGE = $ENV{'LANGUAGE'};
   Locale::Messages::textdomain($strings_textdomain);
   Locale::Messages::bind_textdomain_codeset($strings_textdomain, $encoding)
-    if ($encoding ne 'us-ascii');
+    if ($encoding and $encoding ne 'us-ascii');
   Locale::Messages::bind_textdomain_filter($strings_textdomain,
-    \&encode_i18n_string, $encoding);
+    \&encode_i18n_string, $encoding) if ($encoding and $encoding ne 
'us-ascii');
 
   # FIXME do that in the converters when @documentlanguage is found.
   my $lang = $self->{'documentlanguage'};
@@ -134,11 +134,15 @@
   my $locales = '';
 
   foreach my $language (@langs) {
+    if ($encoding) {
     $locales .= "$language.$encoding:";
+    } else {
+      $locales .= "$language:";
+    }
     # always try us-ascii, the charset should always be a subset of
     # all charset, and should resort to @-commands if needed for non
     # ascii characters
-    if ($encoding ne 'us-ascii') {
+    if ($encoding and $encoding ne 'us-ascii') {
       $locales .= "$language.us-ascii:";
     }
   }

Index: Convert/Info.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Info.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Convert/Info.pm     30 Dec 2010 17:36:51 -0000      1.5
+++ Convert/Info.pm     31 Dec 2010 12:14:07 -0000      1.6
@@ -229,7 +229,7 @@
   my $self = shift;
   my $string = shift;
 
-  if ($self->{'output_encoding'} ne 'us-ascii') {
+  if ($self->{'output_encoding'} and $self->{'output_encoding'} ne 'us-ascii') 
{
     return length(Encode::encode($self->{'output_encoding'}, $string));
   } else {
     return length($string);
@@ -481,17 +481,6 @@
           [{'bytes' => 0, 'root' => $node}]);
 }
 
-sub _anchor($$)
-{
-  my $self = shift;
-  my $anchor = shift;
-
-  # 'lines_count' is in fact only needed when in @flush and @multitable
-  my $locations = [ {'lines' => 0, 'bytes' => 0,
-                     'root' => $anchor} ];
-  return ('', undef, $locations);
-}
-
 my @image_files_extensions = ('png', 'jpg');
 sub _image($$)
 {

Index: Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- Convert/Plaintext.pm        30 Dec 2010 17:36:51 -0000      1.41
+++ Convert/Plaintext.pm        31 Dec 2010 12:14:07 -0000      1.42
@@ -233,9 +233,12 @@
   'enable_encoding'      => 1,
   'footnotestyle'        => 'end',
   'fillcolumn'           => 72,
-  'documentencoding'     => 'us-ascii',
-  'encoding'             => 'us-ascii',
-  'output_encoding'      => 'us-ascii',
+#  'documentencoding'     => 'us-ascii',
+#  'encoding'             => 'us-ascii',
+#  'output_encoding'      => 'us-ascii',
+  'documentencoding'     => undef,
+  'encoding'             => undef,
+  'output_encoding'      => undef,
   'output_file'          => undef,
   'documentlanguage'     => 'en',
   'number_footnotes'     => 1,
@@ -461,7 +464,8 @@
   my $text = $command->{'text'};
 
   $text = uc($text) if ($self->{'upper_case'});
-  if ($self->{'enable_encoding'} and $self->{'documentencoding'} eq 'utf-8') {
+  if ($self->{'enable_encoding'} and $self->{'documentencoding'} 
+      and $self->{'documentencoding'} eq 'utf-8') {
     return Texinfo::Convert::Unicode($self, $command);
   } elsif (!$context->{'code'} and !$context->{'preformatted'}) {
     $text =~ s/---/\x{1F}/g;
@@ -587,7 +591,7 @@
   my $self = shift;
   my $string = shift;
 
-  if ($self->{'output_encoding'} ne 'us-ascii') {
+  if ($self->{'output_encoding'} and $self->{'output_encoding'} ne 'us-ascii') 
{
     return length(Encode::encode($self->{'output_encoding'}, $string));
   } else {
     return length($string);
@@ -692,19 +696,44 @@
           $locations);
 }
 
-sub _align_lines($$$)
+sub _align_lines($$$$$)
 {
+  my $self = shift;
   my $text = shift;
   my $max_column = shift;
   my $direction = shift;
+  my $locations = shift;
+
   my $result = '';
+
+  my $updated_locations = {};
+  if ($locations and @$locations) {
+    foreach my $location (@$locations) {
+      next unless (defined($location->{'bytes'}) and 
defined($location->{'lines'}));
+      #print STDERR "L anchor $location->{'root'}->{'extra'}->{'normalized'}: 
$location->{'lines'} ($location->{'bytes'})\n";
+      push @{$updated_locations->{$location->{'lines'}}}, $location;
+    }
+  }
+
+  my $bytes_count = 0;
+  my $delta_bytes = 0;
+  my $line_index = 0;
   foreach my $line (split /^/, $text) {
-    chomp($line);
-    $line =~ s/^\s*//;
-    $line =~ s/\s*$//;
+    my $line_bytes_begin = 0;
+    my $line_bytes_end = 0;
+    my $chomped = chomp($line);
+    # for debugging.
+    my $orig_line = $line;
+    $line_bytes_end -= $self->count_bytes($chomped);
+    $line =~ s/^(\s*)//;
+    $line_bytes_begin -= $self->count_bytes($1);
+    $line =~ s/(\s*)$//;
+    $line_bytes_end -= $self->count_bytes($1);
     my $line_width = Texinfo::Convert::Unicode::string_width($line);
     if ($line_width == 0) {
       $result .= "\n";
+      $line_bytes_end += $self->count_bytes("\n");
+      $bytes_count += $self->count_bytes("\n");
     } else {
       my $spaces_prepended;
       if ($line_width > $max_column) {
@@ -715,25 +744,22 @@
         $spaces_prepended = ($max_column -1 - $line_width);
       }
       $result .= ' ' x$spaces_prepended . $line ."\n";
+      $line_bytes_begin += $self->count_bytes(' ' x$spaces_prepended);
+      $line_bytes_end += $self->count_bytes("\n");
+      if ($updated_locations->{$line_index}) {
+        foreach my $location (@{$updated_locations->{$line_index}}) {
+          $location->{'bytes'} += $line_bytes_begin + $delta_bytes;
+          #print STDERR "UPDATE ALIGN: 
$location->{'root'}->{'extra'}->{'normalized'}: ($location->{'bytes'})\n";
+        }
+      }
+      $bytes_count += $line_bytes_begin + $line_bytes_end 
+                      + $self->count_bytes($line);
+    }
+    $delta_bytes += $line_bytes_begin + $line_bytes_end;
+    #print STDERR "ALIGN $orig_line ($line_index. lbb $line_bytes_begin, lbe 
$line_bytes_end, delta $delta_bytes, bytes_count $bytes_count)\n";
+    $line_index++;
     }
-  }
-  return $result;
-}
-
-sub _flush_paragraph($$)
-{
-  my $self = shift;
-  my $text = shift;
-
-  my $index = -1;
-  $index--
-    while (!$flush_commands{$self->{'format_context'}->[$index]->{'cmdname'}});
-  # nothing to do in case of flushleft
-  if ($self->{'format_context'}->[$index]->{'cmdname'} eq 'flushleft') {
-    return $text;
-  }
-  return _align_lines($text, $self->{'format_context'}->[$index]->{'max'},
-                          'right');
+  return ($result, $bytes_count);
 }
 
 sub _contents($$$)
@@ -805,7 +831,12 @@
 {
   my $self = shift;
   my $anchor = shift;
-  return '';
+
+  # 'lines_count' is in fact only needed when in @flush and @multitable
+  my $locations = 
+   [ {'lines' => $self->{'formatters'}->[-1]->{'container'}->{'lines_counter'},
+      'bytes' => 0, 'root' => $anchor} ];
+  return ('', undef, $locations);
 }
 
 my $listoffloat_entry_length = 41;
@@ -1381,22 +1412,16 @@
     } elsif ($root->{'cmdname'} eq 'center') {
       #my ($counts, $new_locations);
       $self->advance_count_text(\$result, \$bytes_count, \$lines_count,
-               $locations, 0,
+               $locations, 1,
                $self->convert_line (
                        {'contents' => $root->{'extra'}->{'misc_content'}},
                        {'indent_length' => 0}));
-      $result = _align_lines ($result, 
$self->{'format_context'}->[-1]->{'max'},
-                                  'center');
-      # only take care of lines count since the whole is recounted
-      # anyway.
-      if (chomp ($result)) {
-        $lines_count--;
-      }
+      ($result, $bytes_count) 
+         = $self->_align_lines ($result, 
+             $self->{'format_context'}->[-1]->{'max'}, 'center', $locations);
       $self->{'empty_lines_count'} = 0 unless ($result eq '');
-      $result .= "\n";
-      $lines_count++;
       $self->{'format_context'}->[-1]->{'paragraph_count'}++;
-      return ($result, {'bytes' => $self->count_bytes($result), 
+      return ($result, {'bytes' => $bytes_count, 
                         'lines' => $lines_count}, $locations);
     } elsif ($root->{'cmdname'} eq 'exdent') {
       
@@ -1534,7 +1559,8 @@
       if ($root->{'cmdname'} eq 'item' or $root->{'cmdname'} eq 'itemx') {
         $index_entry = 0;
       }
-      push @{$locations}, {'lines' => $lines_count, 
+      push @{$locations}, {'lines' => $lines_count
+              + $self->{'formatters'}->[-1]->{'container'}->{'lines_counter'}, 
                            'index_entry' => $root};
     } elsif ($unknown_command) {
       die "Unhandled $root->{'cmdname'}\n";
@@ -1743,7 +1769,15 @@
     $bytes_count += $self->count_bytes($end);
     $lines_count += $paragraph->{'container'}->{'lines_counter'};
     if ($self->{'context'}->[-1] eq 'flush') {
-      $result = $self->_flush_paragraph ($result);
+      my $index = -1;
+      $index--
+        while 
(!$flush_commands{$self->{'format_context'}->[$index]->{'cmdname'}});
+      # nothing to do in case of flushleft
+      if ($self->{'format_context'}->[$index]->{'cmdname'} eq 'flushright') {
+        ($result, $bytes_count) = $self->_align_lines($result, 
+                        $self->{'format_context'}->[$index]->{'max'},
+                        'right', $locations);
+      }
     }
     pop @{$self->{'formatters'}};
     delete $self->{'format_context'}->[-1]->{'counter'};



reply via email to

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