# HG changeset patch # User Rik # Date 1372286997 25200 # Node ID 359ac80ecb303c963d16caf4d698d4add54e3560 # Parent 563f8f0a7e29e24e4c026a6f9f0de8c8e854dfb9 Trim ticklabel strings and repeat them as necessary to fill tick marks (bug #39344) * libinterp/interp-core/gl-render.cc(render_ticktexts): Trim spaces from labels. Use % operator to repeat labels as necessary to fill number of ticks. * libinterp/interpfcn/graphics.cc(get_ticklabel_extents): Trim spaces from labels before calculating extent of text. diff -r 563f8f0a7e29 -r 359ac80ecb30 libinterp/interp-core/gl-render.cc --- a/libinterp/interp-core/gl-render.cc Wed Jun 26 14:29:15 2013 -0700 +++ b/libinterp/interp-core/gl-render.cc Wed Jun 26 15:49:57 2013 -0700 @@ -754,28 +754,37 @@ int xyz, int ha, int va, int& wmax, int& hmax) { - int n = std::min (ticklabels.numel (), ticks.numel ()); - - for (int i = 0; i < n; i++) + int nticks = ticks.numel (); + int nlabels = ticklabels.numel (); + + if (nlabels == 0) + return; + + for (int i = 0; i < nticks; i++) { double val = ticks(i); if (lim1 <= val && val <= lim2) { Matrix b; - // FIXME: as tick text is transparent, shouldn't be + + std::string label (ticklabels(i % nlabels)); + label.erase (0, label.find_first_not_of (" ")); + label = label.substr (0, label.find_last_not_of (" ")+1); + + // FIXME: as tick text is transparent, shouldn't it be // drawn after axes object, for correct rendering? if (xyz == 0) // X { - b = render_text (ticklabels(i), val, p1, p2, ha, va); + b = render_text (label, val, p1, p2, ha, va); } else if (xyz == 1) // Y { - b = render_text (ticklabels(i), p1, val, p2, ha, va); + b = render_text (label, p1, val, p2, ha, va); } else if (xyz == 2) // Z { - b = render_text (ticklabels(i), p1, p2, val, ha, va); + b = render_text (label, p1, p2, val, ha, va); } wmax = std::max (wmax, static_cast (b(2))); diff -r 563f8f0a7e29 -r 359ac80ecb30 libinterp/interpfcn/graphics.cc --- a/libinterp/interpfcn/graphics.cc Wed Jun 26 14:29:15 2013 -0700 +++ b/libinterp/interpfcn/graphics.cc Wed Jun 26 15:49:57 2013 -0700 @@ -6348,13 +6348,16 @@ double val = ticks(i); if (limits(0) <= val && val <= limits(1)) { + std::string label (ticklabels(i)); + label.erase (0, label.find_first_not_of (" ")); + label = label.substr (0, label.find_last_not_of (" ")+1); #ifdef HAVE_FREETYPE - ext = text_renderer.get_extent (ticklabels(i)); + ext = text_renderer.get_extent (label); wmax = std::max (wmax, ext(0)); hmax = std::max (hmax, ext(1)); #else - //FIXME: find a better approximation - int len = ticklabels(i).length (); + // FIXME: find a better approximation + int len = label.length (); wmax = std::max (wmax, 0.5*fontsize*len); hmax = fontsize; #endif