added wxFont::IsFixedWidth(), documented it and implemented for wxGTK/Motif
[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 license
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 #ifdef __GNUG__
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 enum wxXLFDField
38 {
39 wxXLFD_FOUNDRY, // adobe
40 wxXLFD_FAMILY, // courier, times, ...
41 wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light
42 wxXLFD_SLANT, // r/i/o (roman/italique/oblique)
43 wxXLFD_SETWIDTH, // condensed, expanded, ...
44 wxXLFD_ADDSTYLE, // whatever - usually nothing
45 wxXLFD_PIXELSIZE, // size in pixels
46 wxXLFD_POINTSIZE, // size in points
47 wxXLFD_RESX, // 72, 75, 100, ...
48 wxXLFD_RESY,
49 wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell)
50 wxXLFD_AVGWIDTH, // average width in 1/10 pixels
51 wxXLFD_REGISTRY, // iso8859, rawin, koi8, ...
52 wxXLFD_ENCODING, // 1, r, r, ...
53 wxXLFD_MAX
54 };
55
56 #endif // _WX_X_FONTLIKE
57
58 // ----------------------------------------------------------------------------
59 // types
60 // ----------------------------------------------------------------------------
61
62 // wxNativeFontInfo is platform-specific font representation: this struct
63 // should be considered as opaque font description only used by the native
64 // functions, the user code can only get the objects of this type from
65 // somewhere and pass it somewhere else (possibly save them somewhere using
66 // ToString() and restore them using FromString())
67 //
68 // NB: it is a POD currently for max efficiency but if it continues to grow
69 // further it might make sense to make it a real class with virtual methods
70 struct WXDLLEXPORT wxNativeFontInfo
71 {
72 #if defined(_WX_X_FONTLIKE)
73 // the fonts array can't be accessed directly as we only parse the
74 // xFontName when needed
75 private:
76 // the components of the XLFD
77 wxString fontElements[wxXLFD_MAX];
78
79 public:
80 // the full XLFD
81 wxString xFontName;
82
83 // init the elements from an XLFD, return TRUE if ok
84 bool FromXFontName(const wxString& xFontName);
85
86 // generate an XLFD using the fontElements
87 wxString GetXFontName() const;
88
89 // get the given XFLD component
90 wxString GetXFontComponent(wxXLFDField field) const;
91 #elif defined(__WXMSW__)
92 LOGFONT lf;
93 #elif defined(__WXPM__)
94 // OS/2 native structures that define a font
95 FATTRS fa;
96 FONTMETRICS fm;
97 FACENAMEDESC fn;
98 #else // other platforms
99 //
100 // This is a generic implementation that should work on all ports
101 // without specific support by the port.
102 //
103 #define wxNO_NATIVE_FONTINFO
104
105 int pointSize;
106 wxFontFamily family;
107 wxFontStyle style;
108 wxFontWeight weight;
109 bool underlined;
110 wxString faceName;
111 wxFontEncoding encoding;
112 #endif // platforms
113
114 // default ctor (default copy ctor is ok)
115 wxNativeFontInfo() { Init(); }
116
117 // reset to the default state
118 void Init();
119
120 // accessors and modifiers for the font elements
121 int GetPointSize() const;
122 wxFontStyle GetStyle() const;
123 wxFontWeight GetWeight() const;
124 bool GetUnderlined() const;
125 wxString GetFaceName() const;
126 wxFontFamily GetFamily() const;
127 wxFontEncoding GetEncoding() const;
128
129 void SetPointSize(int pointsize);
130 void SetStyle(wxFontStyle style);
131 void SetWeight(wxFontWeight weight);
132 void SetUnderlined(bool underlined);
133 void SetFaceName(wxString facename);
134 void SetFamily(wxFontFamily family);
135 void SetEncoding(wxFontEncoding encoding);
136
137 // it is important to be able to serialize wxNativeFontInfo objects to be
138 // able to store them (in config file, for example)
139 bool FromString(const wxString& s);
140 wxString ToString() const;
141
142 // we also want to present the native font descriptions to the user in some
143 // human-readable form (it is not platform independent neither, but can
144 // hopefully be understood by the user)
145 bool FromUserString(const wxString& s);
146 wxString ToUserString() const;
147 };
148
149 // ----------------------------------------------------------------------------
150 // font-related functions (common)
151 // ----------------------------------------------------------------------------
152
153 // translate a wxFontEncoding into native encoding parameter (defined above),
154 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
155 // attempting any substitutions)
156 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding,
157 wxNativeEncodingInfo *info);
158
159 // test for the existence of the font described by this facename/encoding,
160 // return TRUE if such font(s) exist, FALSE otherwise
161 extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
162
163 // ----------------------------------------------------------------------------
164 // font-related functions (X and GTK)
165 // ----------------------------------------------------------------------------
166
167 #ifdef _WX_X_FONTLIKE
168 #include "wx/unix/fontutil.h"
169 #endif // X || GDK
170
171 // ----------------------------------------------------------------------------
172 // font-related functions (MGL)
173 // ----------------------------------------------------------------------------
174
175 #ifdef __WXMGL__
176 #include "wx/mgl/fontutil.h"
177 #endif // __WXMGL__
178
179 #endif // _WX_FONTUTIL_H_