Mercurial > octave
changeset 28315:768ae9b1a67c stable
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.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sat, 16 May 2020 15:53:42 +0200 |
parents | 8085ae13cc4a |
children | 7a1736f89c6b ac87763b1949 |
files | NEWS libinterp/corefcn/ft-text-renderer.cc src/octave-svgconvert.cc |
diffstat | 3 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Mon May 18 17:21:53 2020 +0900 +++ b/NEWS Sat May 16 15:53:42 2020 +0200 @@ -140,6 +140,10 @@ when using those devices, and the code for supporting those formats will eventually be removed from a future version of Octave. +- The placement of text subscripts and superscripts has been +re-engineered and now produces visually attractive results similar to +Latex. + ### Matlab compatibility - The function `unique` now returns column index vectors for the second
--- a/libinterp/corefcn/ft-text-renderer.cc Mon May 18 17:21:53 2020 +0900 +++ 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 ();
--- a/src/octave-svgconvert.cc Mon May 18 17:21:53 2020 +0900 +++ 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);