[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Setting the fontname and size of text
From: |
David Bateman |
Subject: |
Re: Setting the fontname and size of text |
Date: |
Tue, 13 Nov 2007 15:57:45 +0100 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Shai Ayal wrote:
> David,
>
> I wish you would use the radio_value class for these properties. That
> way you would gain automatic validity checks. I'll try to submit a
> patch tonight if you don't beat me to it
>
> Shai
>
>
Ok, then what about the attached..
D.
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
*** ./scripts/plot/__go_draw_axes__.m.orig3 2007-11-13 10:21:50.106992986
+0100
--- ./scripts/plot/__go_draw_axes__.m 2007-11-13 11:13:47.990435630 +0100
***************
*** 60,68 ****
fputs (plot_stream, "unset title;\n");
else
if (isempty (t.fontname))
! f = "Helvetica";
else
! f = t.fontname;
endif
if (isempty (t.fontsize))
s = 10;
--- 60,82 ----
fputs (plot_stream, "unset title;\n");
else
if (isempty (t.fontname))
! f = "helvetica";
else
! 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;
***************
*** 81,89 ****
fputs (plot_stream, "unset xlabel;\n");
else
if (isempty (t.fontname))
! f = "Helvetica";
else
! f = t.fontname;
endif
if (isempty (t.fontsize))
s = 10;
--- 95,117 ----
fputs (plot_stream, "unset xlabel;\n");
else
if (isempty (t.fontname))
! f = "helvetica";
else
! 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;
***************
*** 108,116 ****
fputs (plot_stream, "unset ylabel;\n");
else
if (isempty (t.fontname))
! f = "Helvetica";
else
! f = t.fontname;
endif
if (isempty (t.fontsize))
s = 10;
--- 136,158 ----
fputs (plot_stream, "unset ylabel;\n");
else
if (isempty (t.fontname))
! f = "helvetica";
else
! 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;
***************
*** 853,861 ****
endif
if (isempty (obj.fontname))
! f = "Helvetica";
else
! f = obj.fontname;
endif
if (isempty (obj.fontsize))
s = 10;
--- 895,917 ----
endif
if (isempty (obj.fontname))
! f = "helvetica";
else
! f = tolower(obj.fontname);
! endif
! if (! isempty(obj.fontweight) &&
! strcmp (tolower (obj.fontweight), "bold"))
! if (! isempty(obj.fontangle) &&
! (strcmp (tolower (obj.fontangle), "italic") ||
! strcmp (tolower (obj.fontangle), "oblique")))
! f = strcat (f, "-bolditalic");
! else
! f = strcat (f, "-bold");
! endif
! elseif (! isempty(obj.fontangle) &&
! (strcmp (tolower (obj.fontangle), "italic") ||
! strcmp (tolower (obj.fontangle), "oblique")))
! f = strcat (f, "-italic");
endif
if (isempty (obj.fontsize))
s = 10;
*** ./src/graphics.h.in.orig3 2007-11-13 10:18:08.677130836 +0100
--- ./src/graphics.h.in 2007-11-13 15:36:50.836464962 +0100
***************
*** 351,356 ****
--- 351,463 ----
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,1417 ****
--- 1519,1526 ----
color_property color
octave_value fontname
octave_value fontsize
+ string_property fontangle a
+ string_property fontweight a
END_PROPERTIES
static std::string go_name;
*** ./src/graphics.cc.orig3 2007-11-13 10:18:01.541511035 +0100
--- ./src/graphics.cc 2007-11-13 15:09:57.708124850 +0100
***************
*** 1919,1925 ****
horizontalalignment ("left"),
color (Matrix (1, 3, 0.0)),
fontname ("Helvetica"),
! fontsize (10)
{ }
void
--- 1919,1927 ----
horizontalalignment ("left"),
color (Matrix (1, 3, 0.0)),
fontname ("Helvetica"),
! fontsize (10),
! fontangle (radio_values ("{normal}|italic|oblique")),
! fontweight (radio_values ("{normal}|bold|demi|light"))
{ }
void
***************
*** 1952,1957 ****
--- 1954,1963 ----
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,1984 ****
--- 1985,1992 ----
m.assign ("color", color);
m.assign ("fontname", fontname);
m.assign ("fontsize", fontsize);
+ m.assign ("fontangle", fontangle);
+ m.assign ("fontweight", fontweight);
return m;
}
***************
*** 2012,2017 ****
--- 2020,2029 ----
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,2036 ****
--- 2043,2052 ----
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;
}
2007-11-13 David Bateman <address@hidden>
* plot/__go_draw_axes.m: Allow the fontangle and fontweight to be
specified for the title, xlabel, ylabel and text objects.
2007-11-12 David Bateman <address@hidden>
* graphics.h.in, graphics.cc (class text): Add the fontangle and
fontweight properties. Add string_property class to handle the
string radio values.
- Setting the fontname and size of text, David Bateman, 2007/11/12
- Setting the fontname and size of text, John W. Eaton, 2007/11/12
- Re: Setting the fontname and size of text, David Bateman, 2007/11/13
- Re: Setting the fontname and size of text, John W. Eaton, 2007/11/13
- Re: Setting the fontname and size of text, Shai Ayal, 2007/11/13
- Re: Setting the fontname and size of text, Shai Ayal, 2007/11/14
- Re: Setting the fontname and size of text, David Bateman, 2007/11/19
Re: Setting the fontname and size of text, Daniel J Sebald, 2007/11/13