changeset 27142:8a07083c8cfc stable

Use replacement characters to display non UTF-8 strings in figures (bug #55974) * contributors.in: Add Imad-Eddine Srairi who found the origin of the bug and provided the fix. * ft-text-renderer.cc (ft_text_renderer::visit): Use replacement character for unhandled (non-UTF-8) characters. * gl2ps-print.cc (gl2ps_renderer::strlist_to_ps): Use question mark for multibyte and non-ascii characters.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 04 Jun 2019 00:26:12 +0200
parents 8854d65e3bcc
children 961b76f59fa2 ecc16b72bfb3
files doc/interpreter/contributors.in libinterp/corefcn/ft-text-renderer.cc libinterp/corefcn/gl2ps-print.cc
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/contributors.in	Thu May 30 11:35:51 2019 +0200
+++ b/doc/interpreter/contributors.in	Tue Jun 04 00:26:12 2019 +0200
@@ -373,6 +373,7 @@
 Quentin H. Spencer
 Christoph Spiel
 David Spies
+Imad-Eddine Srairi
 Andreas Stahel
 Richard Stallman
 Russell Standish
--- a/libinterp/corefcn/ft-text-renderer.cc	Thu May 30 11:35:51 2019 +0200
+++ b/libinterp/corefcn/ft-text-renderer.cc	Tue Jun 04 00:26:12 2019 +0200
@@ -902,6 +902,13 @@
             // Retrieve the length and the u32 representation of the current
             // character
             int mblen = octave_u8_strmbtouc_wrapper (&u32_c, c + icurr);
+            if (mblen < 1)
+              {
+                // This is not an UTF-8 character, use a replacement character
+                mblen = 1;
+                u32_c = 0xFFFD;
+              }
+                
             n -= mblen;
 
             if (m_do_strlist && mode == MODE_RENDER)
--- a/libinterp/corefcn/gl2ps-print.cc	Thu May 30 11:35:51 2019 +0200
+++ b/libinterp/corefcn/gl2ps-print.cc	Tue Jun 04 00:26:12 2019 +0200
@@ -928,9 +928,10 @@
               {
                 int mblen = octave_u8_strmblen_wrapper (c + i);
 
+                // Replace multibyte or non ascii characters by a question mark
                 if (mblen > 1)
                   {
-                    str += " ";
+                    str += "?";
                     if (! warned)
                       {
                         warning_with_id ("Octave:print:unsupported-multibyte",
@@ -940,6 +941,19 @@
                         warned = true;
                       }
                   }
+                else if (mblen < 1)
+                  {
+                    mblen = 1;
+                    str += "?";
+                    if (! warned)
+                      {
+                        warning_with_id ("Octave:print:unhandled-character",
+                                         "print: only ASCII characters are "
+                                         "supported for EPS and derived "
+                                         "formats.");
+                        warned = true;
+                      }
+                  }
                 else
                   str += tmpstr.at (i);