]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: font.h | |
3 | // Purpose: wxFont class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_FONT_H_ | |
13 | #define _WX_FONT_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "font.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/gdiobj.h" | |
20 | #include "wx/list.h" | |
21 | ||
22 | class WXDLLEXPORT wxFont; | |
23 | ||
24 | // For every wxFont, there must be a font for each display and scale requested. | |
25 | // So these objects are stored in wxFontRefData::m_fonts | |
26 | class WXDLLEXPORT wxXFont: public wxObject | |
27 | { | |
28 | public: | |
29 | wxXFont(); | |
30 | ~wxXFont(); | |
31 | ||
32 | WXFontStructPtr m_fontStruct; // XFontStruct | |
33 | WXFontList m_fontList; // Motif XmFontList | |
34 | WXDisplay* m_display; // XDisplay | |
35 | int m_scale; // Scale * 100 | |
36 | }; | |
37 | ||
38 | class WXDLLEXPORT wxFontRefData: public wxGDIRefData | |
39 | { | |
40 | friend class WXDLLEXPORT wxFont; | |
41 | public: | |
42 | wxFontRefData(); | |
43 | wxFontRefData(const wxFontRefData& data); | |
44 | ~wxFontRefData(); | |
45 | protected: | |
46 | int m_pointSize; | |
47 | int m_family; | |
48 | int m_style; | |
49 | int m_weight; | |
50 | bool m_underlined; | |
51 | wxString m_faceName; | |
52 | ||
53 | // A list of wxXFonts | |
54 | wxList m_fonts; | |
55 | }; | |
56 | ||
57 | #define M_FONTDATA ((wxFontRefData *)m_refData) | |
58 | ||
59 | WXDLLEXPORT_DATA(extern const char*) wxEmptyString; | |
60 | ||
61 | // Font | |
62 | class WXDLLEXPORT wxFont: public wxGDIObject | |
63 | { | |
64 | DECLARE_DYNAMIC_CLASS(wxFont) | |
65 | public: | |
66 | wxFont(); | |
67 | wxFont(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString); | |
68 | inline wxFont(const wxFont& font) { Ref(font); } | |
69 | ||
70 | ~wxFont(); | |
71 | ||
72 | bool Create(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString); | |
73 | ||
74 | virtual bool Ok() const { return (m_refData != NULL) ; } | |
75 | ||
76 | inline int GetPointSize() const { return M_FONTDATA->m_pointSize; } | |
77 | inline int GetFamily() const { return M_FONTDATA->m_family; } | |
78 | inline int GetStyle() const { return M_FONTDATA->m_style; } | |
79 | inline int GetWeight() const { return M_FONTDATA->m_weight; } | |
80 | wxString GetFamilyString() const ; | |
81 | wxString GetFaceName() const ; | |
82 | wxString GetStyleString() const ; | |
83 | wxString GetWeightString() const ; | |
84 | inline bool GetUnderlined() const { return M_FONTDATA->m_underlined; } | |
85 | ||
86 | void SetPointSize(int pointSize); | |
87 | void SetFamily(int family); | |
88 | void SetStyle(int style); | |
89 | void SetWeight(int weight); | |
90 | void SetFaceName(const wxString& faceName); | |
91 | void SetUnderlined(bool underlined); | |
92 | ||
93 | inline wxFont& operator = (const wxFont& font) { if (*this == font) return (*this); Ref(font); return *this; } | |
94 | inline bool operator == (const wxFont& font) { return m_refData == font.m_refData; } | |
95 | inline bool operator != (const wxFont& font) { return m_refData != font.m_refData; } | |
96 | ||
97 | // Implementation | |
98 | ||
99 | // Find an existing, or create a new, XFontStruct | |
100 | // based on this wxFont and the given scale. Append the | |
101 | // font to list in the private data for future reference. | |
102 | ||
103 | // TODO This is a fairly basic implementation, that doesn't | |
104 | // allow for different facenames, and also doesn't do a mapping | |
105 | // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.) | |
106 | // and the fonts that are available on a particular system. | |
107 | // Maybe we need to scan the user's machine to build up a profile | |
108 | // of the fonts and a mapping file. | |
109 | ||
110 | // Return font struct, and optionally the Motif font list | |
111 | wxXFont* GetInternalFont(double scale = 1.0, WXDisplay* display = NULL) const; | |
112 | ||
113 | // These two are helper functions for convenient access of the above. | |
114 | inline WXFontStructPtr GetFontStruct(double scale = 1.0, WXDisplay* display = NULL) const | |
115 | { | |
116 | wxXFont* f = GetInternalFont(scale, display); | |
117 | return (f ? f->m_fontStruct : (WXFontStructPtr) 0); | |
118 | } | |
119 | WXFontList GetFontList(double scale = 1.0, WXDisplay* display = NULL) const | |
120 | { | |
121 | wxXFont* f = GetInternalFont(scale, display); | |
122 | return (f ? f->m_fontList : (WXFontList) 0); | |
123 | } | |
124 | ||
125 | WXFontStructPtr LoadQueryFont(int pointSize, int family, int style, | |
126 | int weight, bool underlined) const; | |
127 | protected: | |
128 | bool RealizeResource(); | |
129 | void Unshare(); | |
130 | }; | |
131 | ||
132 | #endif | |
133 | // _WX_FONT_H_ |