# HG changeset patch # User jwe # Date 1194967012 0 # Node ID f345eb60f9414d3dff83cb94d1174fa6c95aeb85 # Parent 1f1969db6e6569bb44dcb0267183fb31b9108f44 [project @ 2007-11-13 15:16:52 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2007-11-13 David Bateman + + * plot/__go_draw_axes__.m (get_fontname_and_size): + Handle fontweight and fontangle properties. + 2007-11-12 Kai Habel * plot/spinmap.m, plot/ribbon.m: New functions. diff --git a/scripts/plot/__go_draw_axes__.m b/scripts/plot/__go_draw_axes__.m --- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -1380,9 +1380,22 @@ function [f, s] = get_fontname_and_size (t) if (isempty (t.fontname)) - f = "Helvetica"; + f = "helvetica"; else - f = t.fontname; + f = tolower (t.fontname); + endif + if (! isempty (t.fontweight) && strcmp (tolower (t.fontweight), "bold")) + if (! isempty(t.fontangle) + && (strcmp (tolower (t.fontangle), "italic") + || strcmp (tolower (t.fontangle), "oblique"))) + f = strcat (f, "-bolditalic"); + else + f = strcat (f, "-bold"); + endif + elseif (! isempty(t.fontangle) + && (strcmp (tolower (t.fontangle), "italic") + || strcmp (tolower (t.fontangle), "oblique"))) + f = strcat (f, "-italic"); endif if (isempty (t.fontsize)) s = 10; diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2007-11-12 David Bateman + + * graphics.h.in, graphics.cc (class text): Add the fontangle and + fontweight properties. Add string_property class to handle the + string radio values. + 2007-11-12 John W. Eaton * version.h (OCTAVE_VERSION): Now 2.9.17+. diff --git a/src/graphics.cc b/src/graphics.cc --- a/src/graphics.cc +++ b/src/graphics.cc @@ -1919,7 +1919,9 @@ horizontalalignment ("left"), color (Matrix (1, 3, 0.0)), fontname ("Helvetica"), - fontsize (10) + fontsize (10), + fontangle (radio_values ("{normal}|italic|oblique")), + fontweight (radio_values ("{normal}|bold|demi|light")) { } void @@ -1952,6 +1954,10 @@ set_fontname (val); else if (name.compare ("fontsize")) set_fontsize (val); + else if (name.compare ("fontangle")) + set_fontangle (val); + else if (name.compare ("fontweight")) + set_fontweight (val); else { modified = false; @@ -1979,6 +1985,8 @@ m.assign ("color", color); m.assign ("fontname", fontname); m.assign ("fontsize", fontsize); + m.assign ("fontangle", fontangle); + m.assign ("fontweight", fontweight); return m; } @@ -2012,6 +2020,10 @@ retval = fontname; else if (name.compare ("fontsize")) retval = fontsize; + else if (name.compare ("fontangle")) + retval = fontangle; + else if (name.compare ("fontweight")) + retval = fontweight; else warning ("get: invalid property `%s'", name.c_str ()); @@ -2031,6 +2043,10 @@ m["color"] = Matrix (1, 3, 1.0); m["fontname"] = "Helvetica"; m["fontsize"] = 10; + m["fontangle"] = + string_property ("normal", radio_values ("{normal}|italic|oblique")); + m["fontweight"] = + string_property ("normal", radio_values ("{normal}|bold|demi|light")); return m; } diff --git a/src/graphics.h.in b/src/graphics.h.in --- a/src/graphics.h.in +++ b/src/graphics.h.in @@ -44,6 +44,7 @@ { public: radio_values (const std::string& opt_string = std::string ()); + radio_values (const radio_values& a) : default_val (a.default_val), possible_vals (a.possible_vals) { } @@ -351,6 +352,108 @@ Matrix cmap; }; +class +string_property +{ +public: + string_property (const octave_value& c = octave_value (std::string ()), + const radio_values& v = radio_values ()) + : radio_val (v) + { + if (c.is_defined ()) + { + std::string newval = c.string_value (); + + std::transform (newval.begin (), newval.end (), + newval.begin (), tolower); + + if (! error_state) + { + if (radio_val.validate (newval)) + current_val = newval; + } + } + else + current_val = v.default_value (); + } + + string_property (const radio_values& v) + : current_val (v.default_value()), radio_val (v) + { } + + string_property (const radio_values& v, const std::string& initial_value) + : radio_val (v) + { + current_val = initial_value; + std::transform (current_val.begin (), current_val.end (), + current_val.begin (), tolower); + } + + operator octave_value (void) const { return current_val; } + + string_property& operator = (const string_property& a) + { + if (&a != this) + { + current_val = a.current_val; + radio_val = a.radio_val; + } + + return *this; + } + + string_property& operator = (const std::string& s) + { + std::string newval = s; + + std::transform (newval.begin (), newval.end (), + newval.begin (), tolower); + + if (! newval.empty ()) + { + if (radio_val.contains (newval)) + current_val = newval; + else + error ("invalid string specification"); + } + else + error ("invalid string specification"); + + return *this; + } + + string_property& operator = (const octave_value& val) + { + if (val.is_string ()) + { + std::string newval = val.string_value (); + + std::transform (newval.begin (), newval.end (), + newval.begin (), tolower); + + if (! newval.empty ()) + { + if (radio_val.contains (newval)) + current_val = newval; + else + error ("invalid string specification"); + } + else + error ("invalid string specification"); + } + else + error ("invalid string specification"); + + return *this; + } + + const std::string& current_value (void) const { return current_val; } + +private: + std::string current_val; + radio_values radio_val; +}; + // --------------------------------------------------------------------- class property_name : public std::string @@ -1412,6 +1515,8 @@ color_property color octave_value fontname octave_value fontsize + string_property fontangle a + string_property fontweight a END_PROPERTIES static std::string go_name;