1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: font-related helper functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
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.
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__)
31 #include "wx/msw/winundef.h"
34 struct WXDLLEXPORT wxNativeEncodingInfo
;
36 #if defined(_WX_X_FONTLIKE)
38 // the symbolic names for the XLFD fields (with examples for their value)
40 // NB: we suppose that the font always starts with the empty token (font name
41 // registry field) as we never use nor generate it anyhow
44 wxXLFD_FOUNDRY
, // adobe
45 wxXLFD_FAMILY
, // courier, times, ...
46 wxXLFD_WEIGHT
, // black, bold, demibold, medium, regular, light
47 wxXLFD_SLANT
, // r/i/o (roman/italique/oblique)
48 wxXLFD_SETWIDTH
, // condensed, expanded, ...
49 wxXLFD_ADDSTYLE
, // whatever - usually nothing
50 wxXLFD_PIXELSIZE
, // size in pixels
51 wxXLFD_POINTSIZE
, // size in points
52 wxXLFD_RESX
, // 72, 75, 100, ...
54 wxXLFD_SPACING
, // m/p/c (monospaced/proportional/character cell)
55 wxXLFD_AVGWIDTH
, // average width in 1/10 pixels
56 wxXLFD_REGISTRY
, // iso8859, rawin, koi8, ...
57 wxXLFD_ENCODING
, // 1, r, r, ...
61 #endif // _WX_X_FONTLIKE
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // wxNativeFontInfo is platform-specific font representation: this struct
68 // should be considered as opaque font description only used by the native
69 // functions, the user code can only get the objects of this type from
70 // somewhere and pass it somewhere else (possibly save them somewhere using
71 // ToString() and restore them using FromString())
73 // NB: it is a POD currently for max efficiency but if it continues to grow
74 // further it might make sense to make it a real class with virtual methods
75 struct WXDLLEXPORT wxNativeFontInfo
78 PangoFontDescription
*description
;
79 #elif defined(_WX_X_FONTLIKE)
80 // the members can't be accessed directly as we only parse the
81 // xFontName on demand
83 // the components of the XLFD
84 wxString fontElements
[wxXLFD_MAX
];
89 // true until SetXFontName() is called
92 // return true if we have already initialized fontElements
93 inline bool HasElements() const;
96 // init the elements from an XLFD, return TRUE if ok
97 bool FromXFontName(const wxString
& xFontName
);
99 // return false if we were never initialized with a valid XLFD
100 bool IsDefault() const { return m_isDefault
; }
102 // return the XLFD (using the fontElements if necessary)
103 wxString
GetXFontName() const;
105 // get the given XFLD component
106 wxString
GetXFontComponent(wxXLFDField field
) const;
108 // change the font component
109 void SetXFontComponent(wxXLFDField field
, const wxString
& value
);
112 void SetXFontName(const wxString
& xFontName
);
113 #elif defined(__WXMSW__)
115 #elif defined(__WXPM__)
116 // OS/2 native structures that define a font
120 #else // other platforms
122 // This is a generic implementation that should work on all ports
123 // without specific support by the port.
125 #define wxNO_NATIVE_FONTINFO
133 wxFontEncoding encoding
;
136 // default ctor (default copy ctor is ok)
137 wxNativeFontInfo() { Init(); }
139 // reset to the default state
142 // init with the parameters of the given font
143 void InitFromFont(const wxFont
& font
)
145 // translate all font parameters
146 SetStyle((wxFontStyle
)font
.GetStyle());
147 SetWeight((wxFontWeight
)font
.GetWeight());
148 SetUnderlined(font
.GetUnderlined());
149 SetPointSize(font
.GetPointSize());
151 // set the family/facename
152 SetFamily((wxFontFamily
)font
.GetFamily());
153 const wxString
& facename
= font
.GetFaceName();
154 if ( !facename
.empty() )
156 SetFaceName(facename
);
159 // deal with encoding now (it may override the font family and facename
160 // so do it after setting them)
161 SetEncoding(font
.GetEncoding());
164 // accessors and modifiers for the font elements
165 int GetPointSize() const;
166 wxFontStyle
GetStyle() const;
167 wxFontWeight
GetWeight() const;
168 bool GetUnderlined() const;
169 wxString
GetFaceName() const;
170 wxFontFamily
GetFamily() const;
171 wxFontEncoding
GetEncoding() const;
173 void SetPointSize(int pointsize
);
174 void SetStyle(wxFontStyle style
);
175 void SetWeight(wxFontWeight weight
);
176 void SetUnderlined(bool underlined
);
177 void SetFaceName(wxString facename
);
178 void SetFamily(wxFontFamily family
);
179 void SetEncoding(wxFontEncoding encoding
);
181 // it is important to be able to serialize wxNativeFontInfo objects to be
182 // able to store them (in config file, for example)
183 bool FromString(const wxString
& s
);
184 wxString
ToString() const;
186 // we also want to present the native font descriptions to the user in some
187 // human-readable form (it is not platform independent neither, but can
188 // hopefully be understood by the user)
189 bool FromUserString(const wxString
& s
);
190 wxString
ToUserString() const;
193 // ----------------------------------------------------------------------------
194 // font-related functions (common)
195 // ----------------------------------------------------------------------------
197 // translate a wxFontEncoding into native encoding parameter (defined above),
198 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
199 // attempting any substitutions)
200 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
201 wxNativeEncodingInfo
*info
);
203 // test for the existence of the font described by this facename/encoding,
204 // return TRUE if such font(s) exist, FALSE otherwise
205 extern bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
207 // ----------------------------------------------------------------------------
208 // font-related functions (X and GTK)
209 // ----------------------------------------------------------------------------
211 #ifdef _WX_X_FONTLIKE
212 #include "wx/unix/fontutil.h"
215 // ----------------------------------------------------------------------------
216 // font-related functions (MGL)
217 // ----------------------------------------------------------------------------
220 #include "wx/mgl/fontutil.h"
223 #endif // _WX_FONTUTIL_H_