+wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaultv)
+{
+ wxString s = GetParamValue(param);
+ if (s.IsEmpty()) return defaultv;
+ bool is_dlg;
+ long sx;
+
+ is_dlg = s[s.Length()-1] == wxT('d');
+ if (is_dlg) s.RemoveLast();
+
+ if (!s.ToLong(&sx))
+ {
+ wxLogError(_("Cannot parse dimension from '%s'."), s.mb_str());
+ return defaultv;
+ }
+
+ if (is_dlg)
+ {
+ if (m_instanceAsWindow)
+ return wxDLG_UNIT(m_instanceAsWindow, wxSize(sx, 0)).x;
+ else if (m_parentAsWindow)
+ return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, 0)).x;
+ else
+ {
+ wxLogError(_("Cannot convert dialog units: dialog unknown."));
+ return defaultv;
+ }
+ }
+ else return sx;
+}
+
+
+
+wxFont wxXmlResourceHandler::GetFont(const wxString& param)
+{
+ wxXmlNode *font_node = GetParamNode(param);
+ if (font_node == NULL)
+ {
+ wxLogError(_("Cannot find font node '%s'."), param.mb_str());
+ return wxNullFont;
+ }
+
+ wxXmlNode *oldnode = m_node;
+ m_node = font_node;
+
+ long size = GetLong(wxT("size"), 12);
+
+ wxString style = GetParamValue(wxT("style"));
+ wxString weight = GetParamValue(wxT("weight"));
+ int istyle = wxNORMAL, iweight = wxNORMAL;
+ if (style == wxT("italic")) istyle = wxITALIC;
+ else if (style == wxT("slant")) istyle = wxSLANT;
+ if (weight == wxT("bold")) iweight = wxBOLD;
+ else if (weight == wxT("light")) iweight = wxLIGHT;
+
+ wxString family = GetParamValue(wxT("family"));
+ int ifamily = wxDEFAULT;
+ if (family == wxT("decorative")) ifamily = wxDECORATIVE;
+ else if (family == wxT("roman")) ifamily = wxROMAN;
+ else if (family == wxT("script")) ifamily = wxSCRIPT;
+ else if (family == wxT("swiss")) ifamily = wxSWISS;
+ else if (family == wxT("modern")) ifamily = wxMODERN;
+
+ bool underlined = GetBool(wxT("underlined"), FALSE);
+
+ wxString encoding = GetParamValue(wxT("encoding"));
+ wxFontMapper mapper;
+ wxFontEncoding enc = wxFONTENCODING_DEFAULT;
+ if (!encoding.IsEmpty()) enc = mapper.CharsetToEncoding(encoding);
+ if (enc == wxFONTENCODING_SYSTEM) enc = wxFONTENCODING_SYSTEM;
+
+ wxString faces = GetParamValue(wxT("face"));
+ wxString facename = wxEmptyString;
+ wxFontEnumerator enu;
+ enu.EnumerateFacenames();
+ wxStringTokenizer tk(faces, wxT(","));
+ while (tk.HasMoreTokens())
+ {
+ int index = enu.GetFacenames()->Index(tk.GetNextToken(), FALSE);
+ if (index != wxNOT_FOUND)
+ {
+ facename = (*enu.GetFacenames())[index];
+ break;
+ }
+ }
+
+ m_node = oldnode;
+
+ wxFont font(size, ifamily, istyle, iweight, underlined, facename, enc);
+ return font;
+}
+
+