]> git.saurik.com Git - wxWidgets.git/blob - include/wx/fontutil.h
wxBITMAP now uses XPM constructor for wxCocoa (like everything except wxMSW)
[wxWidgets.git] / include / wx / fontutil.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/fontutil.h
3 // Purpose: font-related helper functions
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 05.11.99
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // General note: this header is private to wxWindows and is not supposed to be
13 // included by user code. The functions declared here are implemented in
14 // msw/fontutil.cpp for Windows, unix/fontutil.cpp for GTK/Motif &c.
15
16 #ifndef _WX_FONTUTIL_H_
17 #define _WX_FONTUTIL_H_
18
19 #if defined(__GNUG__) && !defined(__APPLE__)
20 #pragma interface "fontutil.h"
21 #endif
22
23 // ----------------------------------------------------------------------------
24 // headers
25 // ----------------------------------------------------------------------------
26
27 #include "wx/font.h" // for wxFont and wxFontEncoding
28
29 #if defined(__WXMSW__)
30 #include <windows.h>
31 #include "wx/msw/winundef.h"
32 #endif
33
34 #if defined(_WX_X_FONTLIKE)
35
36 // the symbolic names for the XLFD fields (with examples for their value)
37 //
38 // NB: we suppose that the font always starts with the empty token (font name
39 // registry field) as we never use nor generate it anyhow
40 enum wxXLFDField
41 {
42 wxXLFD_FOUNDRY, // adobe
43 wxXLFD_FAMILY, // courier, times, ...
44 wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light
45 wxXLFD_SLANT, // r/i/o (roman/italique/oblique)
46 wxXLFD_SETWIDTH, // condensed, expanded, ...
47 wxXLFD_ADDSTYLE, // whatever - usually nothing
48 wxXLFD_PIXELSIZE, // size in pixels
49 wxXLFD_POINTSIZE, // size in points
50 wxXLFD_RESX, // 72, 75, 100, ...
51 wxXLFD_RESY,
52 wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell)
53 wxXLFD_AVGWIDTH, // average width in 1/10 pixels
54 wxXLFD_REGISTRY, // iso8859, rawin, koi8, ...
55 wxXLFD_ENCODING, // 1, r, r, ...
56 wxXLFD_MAX
57 };
58
59 #endif // _WX_X_FONTLIKE
60
61 // ----------------------------------------------------------------------------
62 // types
63 // ----------------------------------------------------------------------------
64
65 // wxNativeFontInfo is platform-specific font representation: this struct
66 // should be considered as opaque font description only used by the native
67 // functions, the user code can only get the objects of this type from
68 // somewhere and pass it somewhere else (possibly save them somewhere using
69 // ToString() and restore them using FromString())
70 //
71 // NB: it is a POD currently for max efficiency but if it continues to grow
72 // further it might make sense to make it a real class with virtual methods
73 struct WXDLLEXPORT wxNativeFontInfo
74 {
75 #if wxUSE_PANGO
76 PangoFontDescription *description;
77 #elif defined(_WX_X_FONTLIKE)
78 // the members can't be accessed directly as we only parse the
79 // xFontName on demand
80 private:
81 // the components of the XLFD
82 wxString fontElements[wxXLFD_MAX];
83
84 // the full XLFD
85 wxString xFontName;
86
87 // true until SetXFontName() is called
88 bool m_isDefault;
89
90 // return true if we have already initialized fontElements
91 inline bool HasElements() const;
92
93 public:
94 // init the elements from an XLFD, return TRUE if ok
95 bool FromXFontName(const wxString& xFontName);
96
97 // return false if we were never initialized with a valid XLFD
98 bool IsDefault() const { return m_isDefault; }
99
100 // return the XLFD (using the fontElements if necessary)
101 wxString GetXFontName() const;
102
103 // get the given XFLD component
104 wxString GetXFontComponent(wxXLFDField field) const;
105
106 // change the font component
107 void SetXFontComponent(wxXLFDField field, const wxString& value);
108
109 // set the XFLD
110 void SetXFontName(const wxString& xFontName);
111 #elif defined(__WXMSW__)
112 LOGFONT lf;
113 #elif defined(__WXPM__)
114 // OS/2 native structures that define a font
115 FATTRS fa;
116 FONTMETRICS fm;
117 FACENAMEDESC fn;
118 #else // other platforms
119 //
120 // This is a generic implementation that should work on all ports
121 // without specific support by the port.
122 //
123 #define wxNO_NATIVE_FONTINFO
124
125 int pointSize;
126 wxFontFamily family;
127 wxFontStyle style;
128 wxFontWeight weight;
129 bool underlined;
130 wxString faceName;
131 wxFontEncoding encoding;
132 #endif // platforms
133
134 // default ctor (default copy ctor is ok)
135 wxNativeFontInfo() { Init(); }
136
137 // reset to the default state
138 void Init();
139
140 // accessors and modifiers for the font elements
141 int GetPointSize() const;
142 wxFontStyle GetStyle() const;
143 wxFontWeight GetWeight() const;
144 bool GetUnderlined() const;
145 wxString GetFaceName() const;
146 wxFontFamily GetFamily() const;
147 wxFontEncoding GetEncoding() const;
148
149 void SetPointSize(int pointsize);
150 void SetStyle(wxFontStyle style);
151 void SetWeight(wxFontWeight weight);
152 void SetUnderlined(bool underlined);
153 void SetFaceName(wxString facename);
154 void SetFamily(wxFontFamily family);
155 void SetEncoding(wxFontEncoding encoding);
156
157 // it is important to be able to serialize wxNativeFontInfo objects to be
158 // able to store them (in config file, for example)
159 bool FromString(const wxString& s);
160 wxString ToString() const;
161
162 // we also want to present the native font descriptions to the user in some
163 // human-readable form (it is not platform independent neither, but can
164 // hopefully be understood by the user)
165 bool FromUserString(const wxString& s);
166 wxString ToUserString() const;
167 };
168
169 // ----------------------------------------------------------------------------
170 // font-related functions (common)
171 // ----------------------------------------------------------------------------
172
173 // translate a wxFontEncoding into native encoding parameter (defined above),
174 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
175 // attempting any substitutions)
176 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding,
177 wxNativeEncodingInfo *info);
178
179 // test for the existence of the font described by this facename/encoding,
180 // return TRUE if such font(s) exist, FALSE otherwise
181 extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
182
183 // ----------------------------------------------------------------------------
184 // font-related functions (X and GTK)
185 // ----------------------------------------------------------------------------
186
187 #ifdef _WX_X_FONTLIKE
188 #include "wx/unix/fontutil.h"
189 #endif // X || GDK
190
191 // ----------------------------------------------------------------------------
192 // font-related functions (MGL)
193 // ----------------------------------------------------------------------------
194
195 #ifdef __WXMGL__
196 #include "wx/mgl/fontutil.h"
197 #endif // __WXMGL__
198
199 #endif // _WX_FONTUTIL_H_