1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/msw/font.h 3 // Purpose: wxFont class 4 // Author: Julian Smart 5 // Modified by: 6 // Created: 01/02/97 7 // Copyright: (c) Julian Smart 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_FONT_H_ 12 #define _WX_FONT_H_ 13 14 #include "wx/gdicmn.h" 15 16 // ---------------------------------------------------------------------------- 17 // wxFont 18 // ---------------------------------------------------------------------------- 19 20 class WXDLLIMPEXP_CORE wxFont : public wxFontBase 21 { 22 public: 23 // ctors and such wxFont()24 wxFont() { } 25 26 wxFont(const wxFontInfo& info); 27 28 wxFont(int size, 29 wxFontFamily family, 30 wxFontStyle style, 31 wxFontWeight weight, 32 bool underlined = false, 33 const wxString& face = wxEmptyString, 34 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 35 { 36 Create(size, family, style, weight, underlined, face, encoding); 37 } 38 39 bool Create(int size, 40 wxFontFamily family, 41 wxFontStyle style, 42 wxFontWeight weight, 43 bool underlined = false, 44 const wxString& face = wxEmptyString, 45 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 46 { 47 return DoCreate(InfoFromLegacyParams(size, 48 family, 49 style, 50 weight, 51 underlined, 52 face, 53 encoding)); 54 } 55 56 wxFont(const wxSize& pixelSize, 57 wxFontFamily family, 58 wxFontStyle style, 59 wxFontWeight weight, 60 bool underlined = false, 61 const wxString& face = wxEmptyString, 62 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 63 { 64 (void)Create(pixelSize, family, style, weight, 65 underlined, face, encoding); 66 } 67 68 wxFont(const wxNativeFontInfo& info, WXHFONT hFont = NULL) 69 { 70 Create(info, hFont); 71 } 72 73 wxFont(const wxString& fontDesc); 74 75 76 bool Create(const wxSize& pixelSize, 77 wxFontFamily family, 78 wxFontStyle style, 79 wxFontWeight weight, 80 bool underlined = false, 81 const wxString& face = wxEmptyString, 82 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 83 { 84 return DoCreate(InfoFromLegacyParams(pixelSize, 85 family, 86 style, 87 weight, 88 underlined, 89 face, 90 encoding)); 91 } 92 93 bool Create(const wxNativeFontInfo& info, WXHFONT hFont = NULL); 94 95 virtual ~wxFont(); 96 97 // implement base class pure virtuals 98 virtual double GetFractionalPointSize() const wxOVERRIDE; 99 virtual wxSize GetPixelSize() const wxOVERRIDE; 100 virtual bool IsUsingSizeInPixels() const wxOVERRIDE; 101 virtual wxFontStyle GetStyle() const wxOVERRIDE; 102 virtual int GetNumericWeight() const wxOVERRIDE; 103 virtual bool GetUnderlined() const wxOVERRIDE; 104 virtual bool GetStrikethrough() const wxOVERRIDE; 105 virtual wxString GetFaceName() const wxOVERRIDE; 106 virtual wxFontEncoding GetEncoding() const wxOVERRIDE; 107 virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE; 108 109 virtual void SetFractionalPointSize(double pointSize) wxOVERRIDE; 110 virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE; 111 virtual void SetFamily(wxFontFamily family) wxOVERRIDE; 112 virtual void SetStyle(wxFontStyle style) wxOVERRIDE; 113 virtual void SetNumericWeight(int weight) wxOVERRIDE; 114 virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE; 115 virtual void SetUnderlined(bool underlined) wxOVERRIDE; 116 virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE; 117 virtual void SetEncoding(wxFontEncoding encoding) wxOVERRIDE; 118 119 wxDECLARE_COMMON_FONT_METHODS(); 120 121 virtual bool IsFixedWidth() const wxOVERRIDE; 122 123 // MSW needs to modify the font object when the DPI of the window it 124 // is used with changes, this function can be used to do it. 125 // 126 // This method is not considered to be part of wxWidgets public API. 127 void WXAdjustToPPI(const wxSize& ppi); 128 129 wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants ie: wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD") 130 wxFont(int size, 131 int family, 132 int style, 133 int weight, 134 bool underlined = false, 135 const wxString& face = wxEmptyString, 136 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 137 { 138 (void)Create(size, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding); 139 } 140 141 wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants ie: wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD") 142 wxFont(const wxSize& pixelSize, 143 int family, 144 int style, 145 int weight, 146 bool underlined = false, 147 const wxString& face = wxEmptyString, 148 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 149 { 150 (void)Create(pixelSize, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, 151 underlined, face, encoding); 152 } 153 154 // implementation only from now on 155 // ------------------------------- 156 157 virtual bool IsFree() const wxOVERRIDE; 158 virtual bool RealizeResource() wxOVERRIDE; 159 virtual WXHANDLE GetResourceHandle() const wxOVERRIDE; 160 virtual bool FreeResource(bool force = false) wxOVERRIDE; 161 162 // for consistency with other wxMSW classes 163 WXHFONT GetHFONT() const; 164 165 protected: 166 // Common helper of overloaded Create() methods. 167 bool DoCreate(const wxFontInfo& info); 168 169 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE; 170 virtual wxFontFamily DoGetFamily() const wxOVERRIDE; 171 172 // implement wxObject virtuals which are used by AllocExclusive() 173 virtual wxGDIRefData *CreateGDIRefData() const wxOVERRIDE; 174 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const wxOVERRIDE; 175 176 private: 177 wxDECLARE_DYNAMIC_CLASS(wxFont); 178 }; 179 180 #endif // _WX_FONT_H_ 181