Mercurial > octave
changeset 22723:03cebe1fb0e3
Update labels and title font according to axes font properties (bug #49469)
* graphics.in.h (axes::properties::update_font): change signature to accept a
string argument
* graphics.in.h (axes::properties::update_fontsize/weight/name/angle): add
string argument to update_font to specify which property to update
* graphics.in.h (axes::properties::labelfontsizemultiplier/
titlefontsizemultiplier/titlefontweight): add update methods
* graphics.cc (axes::properties::update_font): update x/y/zlabel and title font
according to axes font properties
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 13:24:21 +0100 |
parents | e6fac42c8d56 |
children | dd2f547c21a0 |
files | libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h scripts/plot/appearance/title.m |
diffstat | 3 files changed, 60 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc Fri Nov 04 08:14:44 2016 -0700 +++ b/libinterp/corefcn/graphics.cc Thu Nov 03 13:24:21 2016 +0100 @@ -6259,8 +6259,29 @@ } void -axes::properties::update_font (void) -{ +axes::properties::update_font (std::string prop) +{ + if (! prop.empty ()) + { + octave_value val = get (prop); + octave_value tval = val; + if (prop == "fontsize") + { + tval = octave_value (val.double_value () * + get_titlefontsizemultiplier ()); + val = octave_value (val.double_value () * + get_labelfontsizemultiplier ()); + } + else if (prop == "fontweight") + tval = get ("titlefontweight"); + + gh_manager::get_object (get_xlabel ()).set (prop, val); + gh_manager::get_object (get_ylabel ()).set (prop, val); + gh_manager::get_object (get_zlabel ()).set (prop, val); + gh_manager::get_object (get_title ()).set (prop, tval); + + } + txt_renderer.set_font (get ("fontname").string_value (), get ("fontweight").string_value (), get ("fontangle").string_value (),
--- a/libinterp/corefcn/graphics.in.h Fri Nov 04 08:14:44 2016 -0700 +++ b/libinterp/corefcn/graphics.in.h Thu Nov 03 13:24:21 2016 +0100 @@ -3843,7 +3843,7 @@ color_property gridcolor , color_property (color_values (0.15, 0.15, 0.15), radio_values ("none")) radio_property gridcolormode , "{auto}|manual" radio_property gridlinestyle , "{-}|--|:|-.|none" - double_property labelfontsizemultiplier , 1.1 + double_property labelfontsizemultiplier u , 1.1 radio_property layer u , "{bottom}|top" // FIXME: should be kind of string array. any_property linestyleorder S , "-" @@ -3869,8 +3869,8 @@ array_property ticklength u , default_axes_ticklength () array_property tightinset r , Matrix (1, 4, 0.0) handle_property title SOf , gh_manager::make_graphics_handle ("text", __myhandle__, false, false, false) - double_property titlefontsizemultiplier , 1.1 - radio_property titlefontweight , "{bold}|normal" + double_property titlefontsizemultiplier u , 1.1 + radio_property titlefontweight u , "{bold}|normal" // FIXME: uicontextmenu should be moved here. radio_property units SU , "{normalized}|inches|centimeters|points|pixels|characters" array_property view u , default_axes_view () @@ -4070,25 +4070,43 @@ calc_ticklabels (ztick, zticklabel, zscale.is ("log")); } - void update_font (void); + void update_font (std::string prop = ""); void update_fontname (void) { - update_font (); + update_font ("fontname"); sync_positions (); } void update_fontsize (void) { - update_font (); + update_font ("fontsize"); sync_positions (); } void update_fontangle (void) { - update_font (); + update_font ("fontangle"); sync_positions (); } void update_fontweight (void) { - update_font (); + update_font ("fontweight"); + sync_positions (); + } + + void update_titlefontsizemultiplier (void) + { + update_font ("fontsize"); + sync_positions (); + } + + void update_labelfontsizemultiplier (void) + { + update_font ("fontsize"); + sync_positions (); + } + + void update_titlefontweight (void) + { + update_font ("fontweight"); sync_positions (); }
--- a/scripts/plot/appearance/title.m Fri Nov 04 08:14:44 2016 -0700 +++ b/scripts/plot/appearance/title.m Thu Nov 03 13:24:21 2016 +0100 @@ -122,3 +122,14 @@ %! close (hf); %! end_unwind_protect +%!test <49469> +%! hf = figure ("visible", "off"); +%! unwind_protect +%! ht = title ("Test FontSize Property"); +%! set (gca, "fontname", "Liberation Serif") +%! set (gca, "fontsize", 13) +%! assert (get (ht, "fontname"), "Liberation Serif"); +%! assert (get (ht, "fontsize"), 13 * get (gca, "titlefontsizemultiplier")); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect