1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: font-related helper functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // General note: this header is private to wxWidgets 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.
16 #ifndef _WX_FONTUTIL_H_
17 #define _WX_FONTUTIL_H_
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "fontutil.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 #include "wx/font.h" // for wxFont and wxFontEncoding
29 #if defined(__WXMSW__)
30 #include "wx/msw/wrapwin.h"
33 struct WXDLLEXPORT wxNativeEncodingInfo
;
35 #if defined(_WX_X_FONTLIKE)
37 // the symbolic names for the XLFD fields (with examples for their value)
39 // NB: we suppose that the font always starts with the empty token (font name
40 // registry field) as we never use nor generate it anyhow
43 wxXLFD_FOUNDRY
, // adobe
44 wxXLFD_FAMILY
, // courier, times, ...
45 wxXLFD_WEIGHT
, // black, bold, demibold, medium, regular, light
46 wxXLFD_SLANT
, // r/i/o (roman/italique/oblique)
47 wxXLFD_SETWIDTH
, // condensed, expanded, ...
48 wxXLFD_ADDSTYLE
, // whatever - usually nothing
49 wxXLFD_PIXELSIZE
, // size in pixels
50 wxXLFD_POINTSIZE
, // size in points
51 wxXLFD_RESX
, // 72, 75, 100, ...
53 wxXLFD_SPACING
, // m/p/c (monospaced/proportional/character cell)
54 wxXLFD_AVGWIDTH
, // average width in 1/10 pixels
55 wxXLFD_REGISTRY
, // iso8859, rawin, koi8, ...
56 wxXLFD_ENCODING
, // 1, r, r, ...
60 #endif // _WX_X_FONTLIKE
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // wxNativeFontInfo is platform-specific font representation: this struct
67 // should be considered as opaque font description only used by the native
68 // functions, the user code can only get the objects of this type from
69 // somewhere and pass it somewhere else (possibly save them somewhere using
70 // ToString() and restore them using FromString())
72 // NB: it is a POD currently for max efficiency but if it continues to grow
73 // further it might make sense to make it a real class with virtual methods
74 struct WXDLLEXPORT wxNativeFontInfo
77 PangoFontDescription
*description
;
78 #elif defined(_WX_X_FONTLIKE)
79 // the members can't be accessed directly as we only parse the
80 // xFontName on demand
82 // the components of the XLFD
83 wxString fontElements
[wxXLFD_MAX
];
88 // true until SetXFontName() is called
91 // return true if we have already initialized fontElements
92 inline bool HasElements() const;
95 // init the elements from an XLFD, return true if ok
96 bool FromXFontName(const wxString
& xFontName
);
98 // return false if we were never initialized with a valid XLFD
99 bool IsDefault() const { return m_isDefault
; }
101 // return the XLFD (using the fontElements if necessary)
102 wxString
GetXFontName() const;
104 // get the given XFLD component
105 wxString
GetXFontComponent(wxXLFDField field
) const;
107 // change the font component
108 void SetXFontComponent(wxXLFDField field
, const wxString
& value
);
111 void SetXFontName(const wxString
& xFontName
);
112 #elif defined(__WXMSW__)
114 #elif defined(__WXPM__)
115 // OS/2 native structures that define a font
119 #else // other platforms
121 // This is a generic implementation that should work on all ports
122 // without specific support by the port.
124 #define wxNO_NATIVE_FONTINFO
132 wxFontEncoding encoding
;
135 // default ctor (default copy ctor is ok)
136 wxNativeFontInfo() { Init(); }
140 void Init(const wxNativeFontInfo
& info
);
144 wxNativeFontInfo(const wxNativeFontInfo
& info
) { Init(info
); }
145 ~wxNativeFontInfo() { Free(); }
147 wxNativeFontInfo
& operator=(const wxNativeFontInfo
& info
)
153 #endif // wxUSE_PANGO
155 // reset to the default state
158 // init with the parameters of the given font
159 void InitFromFont(const wxFont
& font
)
161 // translate all font parameters
162 SetStyle((wxFontStyle
)font
.GetStyle());
163 SetWeight((wxFontWeight
)font
.GetWeight());
164 SetUnderlined(font
.GetUnderlined());
165 #if defined(__WXMSW__)
166 if ( font
.IsUsingSizeInPixels() )
167 SetPixelSize(font
.GetPixelSize());
169 SetPointSize(font
.GetPointSize());
171 SetPointSize(font
.GetPointSize());
174 // set the family/facename
175 SetFamily((wxFontFamily
)font
.GetFamily());
176 const wxString
& facename
= font
.GetFaceName();
177 if ( !facename
.empty() )
179 SetFaceName(facename
);
182 // deal with encoding now (it may override the font family and facename
183 // so do it after setting them)
184 SetEncoding(font
.GetEncoding());
187 // accessors and modifiers for the font elements
188 int GetPointSize() const;
189 wxSize
GetPixelSize() const;
190 wxFontStyle
GetStyle() const;
191 wxFontWeight
GetWeight() const;
192 bool GetUnderlined() const;
193 wxString
GetFaceName() const;
194 wxFontFamily
GetFamily() const;
195 wxFontEncoding
GetEncoding() const;
197 void SetPointSize(int pointsize
);
198 void SetPixelSize(const wxSize
& pixelSize
);
199 void SetStyle(wxFontStyle style
);
200 void SetWeight(wxFontWeight weight
);
201 void SetUnderlined(bool underlined
);
202 void SetFaceName(wxString facename
);
203 void SetFamily(wxFontFamily family
);
204 void SetEncoding(wxFontEncoding encoding
);
206 // it is important to be able to serialize wxNativeFontInfo objects to be
207 // able to store them (in config file, for example)
208 bool FromString(const wxString
& s
);
209 wxString
ToString() const;
211 // we also want to present the native font descriptions to the user in some
212 // human-readable form (it is not platform independent neither, but can
213 // hopefully be understood by the user)
214 bool FromUserString(const wxString
& s
);
215 wxString
ToUserString() const;
218 // ----------------------------------------------------------------------------
219 // font-related functions (common)
220 // ----------------------------------------------------------------------------
222 // translate a wxFontEncoding into native encoding parameter (defined above),
223 // returning true if an (exact) macth could be found, false otherwise (without
224 // attempting any substitutions)
225 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
226 wxNativeEncodingInfo
*info
);
228 // test for the existence of the font described by this facename/encoding,
229 // return true if such font(s) exist, false otherwise
230 extern bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
232 // ----------------------------------------------------------------------------
233 // font-related functions (X and GTK)
234 // ----------------------------------------------------------------------------
236 #ifdef _WX_X_FONTLIKE
237 #include "wx/unix/fontutil.h"
240 // ----------------------------------------------------------------------------
241 // font-related functions (MGL)
242 // ----------------------------------------------------------------------------
245 #include "wx/mgl/fontutil.h"
248 #endif // _WX_FONTUTIL_H_