+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] == _T('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(_T("size"), 12);
+
+ wxString style = GetParamValue(_T("style"));
+ wxString weight = GetParamValue(_T("weight"));
+ int istyle = wxNORMAL, iweight = wxNORMAL;
+ if (style == _T("italic")) istyle = wxITALIC;
+ else if (style == _T("slant")) istyle = wxSLANT;
+ if (weight == _T("bold")) iweight = wxBOLD;
+ else if (weight == _T("light")) iweight = wxLIGHT;
+
+ wxString family = GetParamValue(_T("family"));
+ int ifamily = wxDEFAULT;
+ if (family == _T("decorative")) ifamily = wxDECORATIVE;
+ else if (family == _T("roman")) ifamily = wxROMAN;
+ else if (family == _T("script")) ifamily = wxSCRIPT;
+ else if (family == _T("swiss")) ifamily = wxSWISS;
+ else if (family == _T("modern")) ifamily = wxMODERN;
+
+ bool underlined = GetBool(_T("underlined"), FALSE);
+
+ wxString encoding = GetParamValue(_T("encoding"));
+ wxFontMapper mapper;
+ wxFontEncoding enc = wxFONTENCODING_DEFAULT;
+ if (!encoding.IsEmpty()) enc = mapper.CharsetToEncoding(encoding);
+ if (enc == wxFONTENCODING_SYSTEM) enc = wxFONTENCODING_SYSTEM;
+
+ wxString faces = GetParamValue(_T("face"));
+ wxString facename = wxEmptyString;
+ wxFontEnumerator enu;
+ enu.EnumerateFacenames();
+ wxStringTokenizer tk(faces, _T(","));
+ 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;
+}
+
+