# HG changeset patch # User Pantxo Diribarne # Date 1589637222 -7200 # Node ID 6e8d5c99263ccf244354600da367d70399092b26 # Parent 144d77f3f8296ab076bd017a0c751674d8514be8 Produce better looking TeX superscript and subscripts (bug #58376). * NEWS: Announce changes. * ft-text-renderer.cc (visit (text_element_superscript& e)): Scale down font size 70% of the parent font size. Shift baseline +40% of the parent font size. * ft-text-renderer.cc (visit (text_element_subscript& e)): Scale down font size 70% of the parent font size. Shift baseline -15% of the parent font size. * octave-svgconvert.cc (draw): Translate font-size string to double rather than to int. diff -r 144d77f3f829 -r 6e8d5c99263c NEWS --- a/NEWS Sun May 17 14:01:42 2020 -0700 +++ b/NEWS Sat May 16 15:53:42 2020 +0200 @@ -39,6 +39,10 @@ - Support for Qt4 for graphics and the GUI has been removed. +- The placement of text subscripts and superscripts has been +re-engineered and now produces visually attractive results similar to +Latex. + ### Matlab compatibility - The function `griddata` now implements the "v4" Biharmonic Spline diff -r 144d77f3f829 -r 6e8d5c99263c libinterp/corefcn/ft-text-renderer.cc --- a/libinterp/corefcn/ft-text-renderer.cc Sun May 17 14:01:42 2020 -0700 +++ b/libinterp/corefcn/ft-text-renderer.cc Sat May 16 15:53:42 2020 +0200 @@ -1099,16 +1099,16 @@ int saved_line_yoffset = line_yoffset; int saved_yoffset = yoffset; + double sz = font.get_size (); + + // Reducing font size by 70% produces decent results. set_font (font.get_name (), font.get_weight (), font.get_angle (), - font.get_size () - 2); + std::max (5.0, sz * 0.7)); if (font.is_valid ()) { - int h = font.get_face ()->size->metrics.height >> 6; - - // Shifting the baseline by 2/3 the font height seems to produce - // decent result. - yoffset -= (h * 2) / 3; + // Shifting the baseline by 15% of the font size gives decent results. + yoffset -= std::ceil (sz * 0.15); if (mode == MODE_BBOX) update_line_bbox (); @@ -1130,16 +1130,16 @@ int saved_line_yoffset = line_yoffset; int saved_yoffset = yoffset; + double sz = font.get_size (); + + // Reducing font size by 70% produces decent results. set_font (font.get_name (), font.get_weight (), font.get_angle (), - font.get_size () - 2); + std::max (5.0, sz * 0.7)); if (saved_font.is_valid ()) { - int s_asc = saved_font.get_face ()->size->metrics.ascender >> 6; - - // Shifting the baseline by 2/3 base font ascender seems to produce - // decent result. - yoffset += (s_asc * 2) / 3; + // Shifting the baseline by 40% of the font size gives decent results. + yoffset += std::ceil (sz * 0.4); if (mode == MODE_BBOX) update_line_bbox (); diff -r 144d77f3f829 -r 6e8d5c99263c src/octave-svgconvert.cc --- a/src/octave-svgconvert.cc Sun May 17 14:01:42 2020 -0700 +++ b/src/octave-svgconvert.cc Sat May 16 15:53:42 2020 +0200 @@ -396,9 +396,9 @@ if (! str.isEmpty () && str != "normal") font.setStyle (QFont::StyleItalic); - int sz = elt.attribute ("font-size").toInt (); - if (sz > 0) - font.setPixelSize (sz); + str = elt.attribute ("font-size"); + if (! str.isEmpty ()) + font.setPixelSize (str.toDouble ()); painter.setFont (font); @@ -459,9 +459,9 @@ font.setStyle (QFont::StyleNormal); } - int sz = elt.attribute ("font-size").toInt (); - if (sz > 0) - font.setPixelSize (sz); + str = elt.attribute ("font-size"); + if (! str.isEmpty ()) + font.setPixelSize (str.toDouble ()); painter.setFont (font);