diff libinterp/corefcn/ft-text-renderer.cc @ 24076:1b7e49a72c62

improve text rendering in svg printout (bug #48567) * text-renderer.h (text_renderer::string::family, text_renderer::string::xdata): New data members to hold the actual font family chosen by fontconfig and the x position of each character. Provide accessor functions. * ft-text-renderer.cc (ft_renderer::visit (text_element_string&), ft_renderer::visit (text_element_symbol&)): Add family and xdata imformation in the strlist. * gl2ps-print.cc (gl2ps_renderer::strlist_to_svg): New private method to write an svg text element from the data in an strlist. (gl2ps_renderer::strlist_to_ps): Likewise, for ps output. (gl2ps_renderer::render_text): For svg and epsformat, directly dump a formatted text element in the gl2ps output. (gl2ps_renderer::draw): When copying the output file to pipe, insert manually a procedure in the prolog of eps files.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 11 Oct 2016 15:20:35 +0200
parents 336f89b6208b
children 2390079a8aed
line wrap: on
line diff
--- a/libinterp/corefcn/ft-text-renderer.cc	Tue Sep 05 17:38:51 2017 -0700
+++ b/libinterp/corefcn/ft-text-renderer.cc	Tue Oct 11 15:20:35 2016 +0200
@@ -857,8 +857,9 @@
         mbstate_t ps;
         memset (&ps, 0, sizeof (ps));  // Initialize state to 0.
         wchar_t wc;
-
+        std::string fname = font.get_face ()->family_name;
         text_renderer::string fs (str, font, xoffset, yoffset);
+        std::vector<double> xdata;
 
         while (n > 0)
           {
@@ -873,7 +874,7 @@
 
                 if (wc == L'\n')
                   {
-                    // Finish previous string in srtlist before processing
+                    // Finish previous string in strlist before processing
                     // the newline character
                     fs.set_y (line_yoffset + yoffset);
                     fs.set_color (color);
@@ -881,9 +882,13 @@
                     if (! s.empty ())
                       {
                         fs.set_string (s);
+                        fs.set_xdata (xdata);
+                        fs.set_family (fname);
                         strlist.push_back (fs);
                       }
                   }
+                else
+                  xdata.push_back (xoffset);
 
                 glyph_index = process_character (wc, previous);
 
@@ -892,9 +897,9 @@
                     previous = 0;
                     // Start a new string in strlist
                     idx = curr;
+                    xdata.clear ();
                     fs = text_renderer::string (str.substr (idx), font,
                                                 line_xoffset, yoffset);
-
                   }
                 else
                   previous = glyph_index;
@@ -913,6 +918,8 @@
           {
             fs.set_y (line_yoffset + yoffset);
             fs.set_color (color);
+            fs.set_xdata (xdata);
+            fs.set_family (fname);
             strlist.push_back (fs);
           }
       }
@@ -1056,12 +1063,14 @@
   {
     uint32_t code = e.get_symbol_code ();
 
+    std::vector<double> xdata (1, xoffset);
     text_renderer::string fs ("-", font, xoffset, yoffset);
 
     if (code != text_element_symbol::invalid_code && font.is_valid ())
       {
         process_character (code);
         fs.set_code (code);
+        fs.set_xdata (xdata);
       }
     else if (font.is_valid ())
       ::warning ("ignoring unknown symbol: %d", e.get_symbol ());
@@ -1070,6 +1079,7 @@
       {
         fs.set_y (line_yoffset + yoffset);
         fs.set_color (color);
+        fs.set_family (font.get_face ()->family_name);
         strlist.push_back (fs);
       }
   }