Debian Codegraph @

CodeLite/clFontHelper.cpp

raw
1 #include "clFontHelper.h"
2 #if wxUSE_GUI
3 #include <wx/tokenzr.h>
4
5 wxFont clFontHelper::FromString(const wxString& str)
6 {
7 wxArrayString parts = ::wxStringTokenize(str, ";", wxTOKEN_STRTOK);
8 if(parts.size() != 5) return wxNullFont;
9
10 long iPointSize, iFamily, iWeight, iStyle;
11 wxString facename = parts.Item(0);
12 parts.Item(1).ToCLong(&iPointSize);
13 parts.Item(2).ToCLong(&iFamily);
14 parts.Item(3).ToCLong(&iWeight);
15 parts.Item(4).ToCLong(&iStyle);
16
17 bool bold = (iWeight == wxFONTWEIGHT_BOLD);
18 bool italic = (iStyle == wxFONTSTYLE_ITALIC);
19 wxFont font(wxFontInfo(iPointSize).Bold(bold).Italic(italic).FaceName(facename).Family((wxFontFamily)iFamily));
20 return font;
21 }
22
23 wxString clFontHelper::ToString(const wxFont& font)
24 {
25 if(!font.IsOk()) {
26 return "";
27 }
28 wxString str;
29 str << font.GetFaceName() << ";" << font.GetPointSize() << ";" << (int)font.GetFamily() << ";"
30 << (int)font.GetWeight() << ";" << (int)font.GetStyle();
31 return str;
32 }
33 #endif