wxfonta font is an object which determines the appearance of text. fonts are used for drawing text to a device context, and setting the appearance of a window's text. this class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. you can therefore use actual objects instead of pointers without efficiency problems. if an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected. you can retrieve the current system font settings with wxsystemsettings. derived from include files <wx/font.h> constants the possible values for the family parameter of wxfont constructor are (the old names are for compatibility only):
enum wxfontfamily { wxfontfamily_default = wxdefault, wxfontfamily_decorative = wxdecorative, wxfontfamily_roman = wxroman, wxfontfamily_script = wxscript, wxfontfamily_swiss = wxswiss, wxfontfamily_modern = wxmodern, wxfontfamily_teletype = wxteletype, wxfontfamily_max };the possible values for the weight parameter are (the old names are for compatibility only):
enum wxfontweight { wxfontweight_normal = wxnormal, wxfontweight_light = wxlight, wxfontweight_bold = wxbold, wxfontweight_max };the font flags which can be used during the font creation are:
enum { // no special flags: font with default weight/slant/anti-aliasing wxfontflag_default = 0, // slant flags (default: no slant) wxfontflag_italic = 1 << 0, wxfontflag_slant = 1 << 1, // weight flags (default: medium) wxfontflag_light = 1 << 2, wxfontflag_bold = 1 << 3, // anti-aliasing flag: force on or off (default: the current system default) wxfontflag_antialiased = 1 << 4, wxfontflag_not_antialiased = 1 << 5, // underlined/strikethrough flags (default: no lines) wxfontflag_underlined = 1 << 6, wxfontflag_strikethrough = 1 << 7, };the known font encodings are:
enum wxfontencoding { wxfontencoding_system = -1, // system default wxfontencoding_default, // current default encoding // iso8859 standard defines a number of single-byte charsets wxfontencoding_iso8859_1, // west european (latin1) wxfontencoding_iso8859_2, // central and east european (latin2) wxfontencoding_iso8859_3, // esperanto (latin3) wxfontencoding_iso8859_4, // baltic (old) (latin4) wxfontencoding_iso8859_5, // cyrillic wxfontencoding_iso8859_6, // arabic wxfontencoding_iso8859_7, // greek wxfontencoding_iso8859_8, // hebrew wxfontencoding_iso8859_9, // turkish (latin5) wxfontencoding_iso8859_10, // variation of latin4 (latin6) wxfontencoding_iso8859_11, // thai wxfontencoding_iso8859_12, // doesn't exist currently, but put it // here anyhow to make all iso8859 // consecutive numbers wxfontencoding_iso8859_13, // baltic (latin7) wxfontencoding_iso8859_14, // latin8 wxfontencoding_iso8859_15, // latin9 (a.k.a. latin0, includes euro) wxfontencoding_iso8859_max, // cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.php) wxfontencoding_koi8, // we don't support any of koi8 variants wxfontencoding_alternative, // same as ms-dos cp866 wxfontencoding_bulgarian, // used under linux in bulgaria // what would we do without microsoft? they have their own encodings // for dos wxfontencoding_cp437, // original ms-dos codepage wxfontencoding_cp850, // cp437 merged with latin1 wxfontencoding_cp852, // cp437 merged with latin2 wxfontencoding_cp855, // another cyrillic encoding wxfontencoding_cp866, // and another one // and for windows wxfontencoding_cp874, // winthai wxfontencoding_cp1250, // winlatin2 wxfontencoding_cp1251, // wincyrillic wxfontencoding_cp1252, // winlatin1 wxfontencoding_cp1253, // wingreek (8859-7) wxfontencoding_cp1254, // winturkish wxfontencoding_cp1255, // winhebrew wxfontencoding_cp1256, // winarabic wxfontencoding_cp1257, // winbaltic (same as latin 7) wxfontencoding_cp12_max, wxfontencoding_utf7, // utf-7 unicode encoding wxfontencoding_utf8, // utf-8 unicode encoding wxfontencoding_unicode, // unicode - currently used only by // wxencodingconverter class wxfontencoding_max };predefined objects objects: wxnullfont pointers:
wxnormal_font see also wxfont overview, wxdc::setfont, wxdc::drawtext, wxdc::gettextextent, wxfontdialog, wxsystemsettings members
wxfont::wxfont
wxfont::wxfontwxfont() default constructor. wxfont(const wxfont& font) copy constructor, uses reference counting. wxfont(int pointsize, wxfontfamily family, int style, wxfontweight weight, const bool underline = false, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) wxfont(const wxsize& pixelsize, wxfontfamily family, int style, wxfontweight weight, const bool underline = false, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) creates a font object with the specified attributes. parameters pointsize
pixelsize
family
style
weight
underline
facename
encoding
remarks if the desired font does not exist, the closest match will be chosen. under windows, only scalable truetype fonts are used. see also wxdc::setfont, wxdc::drawtext and wxdc::gettextextent.
wxfont::~wxfont~wxfont() destructor. see reference-counted object destruction for more info. remarks although all remaining fonts are deleted when the application exits, the application should try to clean up all fonts itself. this is because wxwidgets cannot know if a pointer to the font object is stored in an application data structure, and there is a risk of double deletion.
wxfont::isfixedwidthbool isfixedwidth() const returns true if the font is a fixed width (or monospaced) font, false if it is a proportional one or font is invalid.
wxfont::getdefaultencodingstatic wxfontencoding getdefaultencoding() returns the current application's default encoding. see also font encoding overview, setdefaultencoding
wxfont::getfacenamewxstring getfacename() const returns the typeface name associated with the font, or the empty string if there is no typeface information. see also
wxfont::getfamilywxfontfamily getfamily() const gets the font family. see wxfont::setfamily for a list of valid family identifiers. see also
wxfont::getnativefontinfodescwxstring getnativefontinfodesc() const returns the platform-dependent string completely describing this font. returned string is always non-empty. note that the returned string is not meant to be shown or edited by the user: a typical use of this function is for serializing in string-form a wxfont object. see also wxfont::setnativefontinfo,wxfont::getnativefontinfouserdesc
wxfont::getnativefontinfouserdescwxstring getnativefontinfouserdesc() returns a user-friendly string for this font object. returned string is always non-empty. some examples of the formats of returned strings (which are platform-dependent) are in setnativefontinfouserdesc. see also
wxfont::getpointsizeint getpointsize() const gets the point size. see also
wxfont::getstyleint getstyle() const gets the font style. see wxfont::wxfont for a list of valid styles. see also
wxfont::getunderlinedbool getunderlined() const returns true if the font is underlined, false otherwise. see also
wxfont::getweightwxfontweight getweight() const gets the font weight. see wxfont::wxfont for a list of valid weight identifiers. see also
wxfont::newstatic wxfont * new(int pointsize, wxfontfamily family, int style, wxfontweight weight, const bool underline = false, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) static wxfont * new(int pointsize, wxfontfamily family, int flags = wxfontflag_default, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) static wxfont * new(const wxsize& pixelsize, wxfontfamily family, int style, wxfontweight weight, const bool underline = false, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) static wxfont * new(const wxsize& pixelsize, wxfontfamily family, int flags = wxfontflag_default, const wxstring& facename = "", wxfontencoding encoding = wxfontencoding_default) these functions take the same parameters as wxfont constructor and return a new font object allocated on the heap. using new() is currently the only way to directly create a font with the given size in pixels on platforms other than wxmsw.
wxfont::isokbool isok() const returns true if this object is a valid font, false otherwise.
wxfont::setdefaultencodingstatic void setdefaultencoding(wxfontencoding encoding) sets the default font encoding. see also font encoding overview, getdefaultencoding
wxfont::setfacenamebool setfacename(const wxstring& facename) sets the facename for the font. returns true if the given face name exists; false otherwise. parameters facename
remarks to avoid portability problems, don't rely on a specific face, but specify the font family instead or as well. a suitable font will be found on the end-user's system. if both the family and the facename are specified, wxwidgets will first search for the specific face, and then for a font belonging to the same family. see also wxfont::getfacename, wxfont::setfamily
wxfont::setfamilyvoid setfamily(wxfontfamily family) sets the font family. parameters family
see also wxfont::getfamily, wxfont::setfacename
wxfont::setnativefontinfobool setnativefontinfo(const wxstring& info) creates the font corresponding to the given native font description string and returns true if the creation was successful. which must have been previously returned by getnativefontinfodesc. if the string is invalid, font is unchanged. this function is typically used for de-serializing a wxfont object previously saved in a string-form. see also wxfont::setnativefontinfouserdesc
wxfont::setnativefontinfouserdescbool setnativefontinfouserdesc(const wxstring& info) creates the font corresponding to the given native font description string and returns true if the creation was successful. unlike setnativefontinfo, this function accepts strings which are user-friendly. examples of accepted string formats are:
for more detailed information about the allowed syntaxes you can look at the documentation of the native api used for font-rendering (e.g. pango_font_description_from_string). see also
wxfont::setpointsizevoid setpointsize(int pointsize) sets the point size. parameters pointsize
see also
wxfont::setstylevoid setstyle(int style) sets the font style. parameters style
see also
wxfont::setunderlinedvoid setunderlined(const bool underlined) sets underlining. parameters underlining
see also
wxfont::setweightvoid setweight(wxfontweight weight) sets the font weight. parameters weight
see also
wxfont::operator =wxfont& operator =(const wxfont& font) assignment operator, using reference counting.
wxfont::operator ==bool operator ==(const wxfont& font) equality operator. see reference-counted object comparison for more info.
wxfont::operator !=bool operator !=(const wxfont& font) inequality operator. see reference-counted object comparison for more info.
|