Include wx/hash.h according to precompiled headers of wx/wx.h (with other minor clean...
[wxWidgets.git] / src / cocoa / fontutil.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/fontutil.cpp
3 // Purpose: Font helper functions for X11 (GDK/X)
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 05.11.99
7 // RCS-ID: $Id$
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/hash.h"
29 #endif // PCH
30
31 #include "wx/fontutil.h"
32 #include "wx/fontmap.h"
33 #include "wx/tokenzr.h"
34 #include "wx/module.h"
35 #include "wx/encinfo.h"
36
37 #ifdef __WXGTK20__
38
39 #include "wx/gtk/private.h"
40
41 // ----------------------------------------------------------------------------
42 // wxNativeFontInfo
43 // ----------------------------------------------------------------------------
44
45 void wxNativeFontInfo::Init()
46 {
47 description = NULL;
48 }
49
50 int wxNativeFontInfo::GetPointSize() const
51 {
52 return pango_font_description_get_size( description ) / PANGO_SCALE;
53 }
54
55 wxFontStyle wxNativeFontInfo::GetStyle() const
56 {
57 wxFontStyle m_style = wxFONTSTYLE_NORMAL;
58
59 switch (pango_font_description_get_style( description ))
60 {
61 case PANGO_STYLE_NORMAL:
62 m_style = wxFONTSTYLE_NORMAL;
63 break;
64 case PANGO_STYLE_ITALIC:
65 m_style = wxFONTSTYLE_ITALIC;
66 break;
67 case PANGO_STYLE_OBLIQUE:
68 m_style = wxFONTSTYLE_SLANT;
69 break;
70 }
71
72 return m_style;
73 }
74
75 wxFontWeight wxNativeFontInfo::GetWeight() const
76 {
77 wxFontWeight m_weight = wxFONTWEIGHT_NORMAL;
78
79 switch (pango_font_description_get_weight( description ))
80 {
81 case PANGO_WEIGHT_ULTRALIGHT:
82 m_weight = wxFONTWEIGHT_LIGHT;
83 break;
84 case PANGO_WEIGHT_LIGHT:
85 m_weight = wxFONTWEIGHT_LIGHT;
86 break;
87 case PANGO_WEIGHT_NORMAL:
88 m_weight = wxFONTWEIGHT_NORMAL;
89 break;
90 case PANGO_WEIGHT_BOLD:
91 m_weight = wxFONTWEIGHT_BOLD;
92 break;
93 case PANGO_WEIGHT_ULTRABOLD:
94 m_weight = wxFONTWEIGHT_BOLD;
95 break;
96 case PANGO_WEIGHT_HEAVY:
97 m_weight = wxFONTWEIGHT_BOLD;
98 break;
99 }
100
101 return m_weight;
102 }
103
104 bool wxNativeFontInfo::GetUnderlined() const
105 {
106 return false;
107 }
108
109 wxString wxNativeFontInfo::GetFaceName() const
110 {
111 wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) );
112
113 return tmp;
114 }
115
116 wxFontFamily wxNativeFontInfo::GetFamily() const
117 {
118 return wxFONTFAMILY_SWISS;
119 }
120
121 wxFontEncoding wxNativeFontInfo::GetEncoding() const
122 {
123 return wxFONTENCODING_SYSTEM;
124 }
125
126 // ----------------------------------------------------------------------------
127 // wxNativeEncodingInfo
128 // ----------------------------------------------------------------------------
129
130 bool wxNativeEncodingInfo::FromString(const wxString& s)
131 {
132 return false;
133 }
134
135 wxString wxNativeEncodingInfo::ToString() const
136 {
137 return wxEmptyString;
138 }
139
140 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
141 {
142 return true;
143 }
144
145 bool wxGetNativeFontEncoding(wxFontEncoding encoding,
146 wxNativeEncodingInfo *info)
147 {
148 return false;
149 }
150
151 #else
152 // __WXGTK20__
153
154 #ifdef __X__
155 #ifdef __VMS__
156 #pragma message disable nosimpint
157 #endif
158
159 #include <X11/Xlib.h>
160
161 #ifdef __VMS__
162 #pragma message enable nosimpint
163 #endif
164
165 #include "wx/utils.h" // for wxGetDisplay()
166 #elif defined(__WXGTK__)
167 // we have to declare struct tm to avoid problems with first forward
168 // declaring it in C code (glib.h included from gdk.h does it) and then
169 // defining it when time.h is included from the headers below - this is
170 // known not to work at least with Sun CC 6.01
171 #include <time.h>
172
173 #include <gdk/gdk.h>
174 #endif
175
176
177 // ----------------------------------------------------------------------------
178 // private data
179 // ----------------------------------------------------------------------------
180
181 static wxHashTable *g_fontHash = (wxHashTable*) NULL;
182
183 // ----------------------------------------------------------------------------
184 // private functions
185 // ----------------------------------------------------------------------------
186
187 // ============================================================================
188 // implementation
189 // ============================================================================
190
191 // ----------------------------------------------------------------------------
192 // wxNativeEncodingInfo
193 // ----------------------------------------------------------------------------
194
195 // convert to/from the string representation: format is
196 // encodingid;registry;encoding[;facename]
197 bool wxNativeEncodingInfo::FromString(const wxString& s)
198 {
199 return false;
200 }
201
202 wxString wxNativeEncodingInfo::ToString() const
203 {
204 return wxEmptyString;
205 }
206
207 // ----------------------------------------------------------------------------
208 // common functions
209 // ----------------------------------------------------------------------------
210
211 bool wxGetNativeFontEncoding(wxFontEncoding encoding,
212 wxNativeEncodingInfo *info)
213 {
214 return false;
215 }
216
217 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
218 {
219 return false;
220 }
221
222 // ----------------------------------------------------------------------------
223 // private functions
224 // ----------------------------------------------------------------------------
225
226 // ----------------------------------------------------------------------------
227 // wxFontModule
228 // ----------------------------------------------------------------------------
229
230 class wxFontModule : public wxModule
231 {
232 public:
233 bool OnInit();
234 void OnExit();
235
236 private:
237 DECLARE_DYNAMIC_CLASS(wxFontModule)
238 };
239
240 IMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule)
241
242 bool wxFontModule::OnInit()
243 {
244 g_fontHash = new wxHashTable( wxKEY_STRING );
245
246 return true;
247 }
248
249 void wxFontModule::OnExit()
250 {
251 delete g_fontHash;
252
253 g_fontHash = (wxHashTable *)NULL;
254 }
255
256 #endif
257 // not GTK 2.0