changeset 16201:2338a92e9782

Fix spacing between ylabel and y-axis (bug #38461) * libinterp/interp-core/txt-eng-ft.cc: Add comment about how get_extent calculates the x and y extents differently. * libinterp/interpfcn/graphics.cc(update_ylabel_position): Add padding to x-extent because it is caluclated differently than y-extent which already includes some padding.
author Rik <rik@octave.org>
date Wed, 06 Mar 2013 10:56:12 -0800
parents 743b895259e0
children 7ce484126bb2
files libinterp/interp-core/txt-eng-ft.cc libinterp/interpfcn/graphics.cc
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interp-core/txt-eng-ft.cc	Tue Mar 05 18:01:24 2013 -0500
+++ b/libinterp/interp-core/txt-eng-ft.cc	Wed Mar 06 10:56:12 2013 -0800
@@ -564,6 +564,11 @@
   return pixels;
 }
 
+// Note:
+// x-extent accurately measures width of glyphs.
+// y-extent is overly large because it is measured from baseline-to-baseline.
+// Calling routines, such as ylabel, may need to account for this mismatch.
+
 Matrix
 ft_render::get_extent (text_element *elt, double rotation)
 {
--- a/libinterp/interpfcn/graphics.cc	Tue Mar 05 18:01:24 2013 -0500
+++ b/libinterp/interpfcn/graphics.cc	Wed Mar 06 10:56:12 2013 -0800
@@ -5194,11 +5194,20 @@
       graphics_xform xform = get_transform ();
 
       Matrix ext (1, 2, 0.0);
+
+      // The underlying get_extents() from FreeType produces mismatched values.
+      // x-extent accurately measures the width of the glyphs.
+      // y-extent instead measures from baseline-to-baseline.
+      // Pad x-extent (+4) so that it approximately matches y-extent.
+      // This keeps ylabels about the same distance from y-axis as
+      // xlabels are from x-axis.
+      // ALWAYS use an even number for padding or horizontal alignment
+      // will be off.
       ext = get_ticklabel_extents (get_ytick ().matrix_value (),
                                    get_yticklabel ().all_strings (),
                                    get_ylim ().matrix_value ());
 
-      double wmax = ext(0), hmax = ext(1), angle = 0;
+      double wmax = ext(0)+4, hmax = ext(1), angle = 0;
       ColumnVector p =
         graphics_xform::xform_vector (xpTick, (ypTickN+ypTick)/2, zpTick);