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 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 #include "wx/font.h" // for wxFont and wxFontEncoding
25 #if defined(__WXMSW__)
26 #include "wx/msw/wrapwin.h"
29 class WXDLLIMPEXP_FWD_BASE wxArrayString
;
30 struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo
;
32 #if defined(_WX_X_FONTLIKE)
34 // the symbolic names for the XLFD fields (with examples for their value)
36 // NB: we suppose that the font always starts with the empty token (font name
37 // registry field) as we never use nor generate it anyhow
40 wxXLFD_FOUNDRY
, // adobe
41 wxXLFD_FAMILY
, // courier, times, ...
42 wxXLFD_WEIGHT
, // black, bold, demibold, medium, regular, light
43 wxXLFD_SLANT
, // r/i/o (roman/italique/oblique)
44 wxXLFD_SETWIDTH
, // condensed, expanded, ...
45 wxXLFD_ADDSTYLE
, // whatever - usually nothing
46 wxXLFD_PIXELSIZE
, // size in pixels
47 wxXLFD_POINTSIZE
, // size in points
48 wxXLFD_RESX
, // 72, 75, 100, ...
50 wxXLFD_SPACING
, // m/p/c (monospaced/proportional/character cell)
51 wxXLFD_AVGWIDTH
, // average width in 1/10 pixels
52 wxXLFD_REGISTRY
, // iso8859, rawin, koi8, ...
53 wxXLFD_ENCODING
, // 1, r, r, ...
57 #endif // _WX_X_FONTLIKE
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // wxNativeFontInfo is platform-specific font representation: this struct
64 // should be considered as opaque font description only used by the native
65 // functions, the user code can only get the objects of this type from
66 // somewhere and pass it somewhere else (possibly save them somewhere using
67 // ToString() and restore them using FromString())
68 class WXDLLIMPEXP_CORE wxNativeFontInfo
72 PangoFontDescription
*description
;
73 #elif defined(_WX_X_FONTLIKE)
74 // the members can't be accessed directly as we only parse the
75 // xFontName on demand
77 // the components of the XLFD
78 wxString fontElements
[wxXLFD_MAX
];
83 // true until SetXFontName() is called
86 // return true if we have already initialized fontElements
87 inline bool HasElements() const;
90 // init the elements from an XLFD, return true if ok
91 bool FromXFontName(const wxString
& xFontName
);
93 // return false if we were never initialized with a valid XLFD
94 bool IsDefault() const { return m_isDefault
; }
96 // return the XLFD (using the fontElements if necessary)
97 wxString
GetXFontName() const;
99 // get the given XFLD component
100 wxString
GetXFontComponent(wxXLFDField field
) const;
102 // change the font component
103 void SetXFontComponent(wxXLFDField field
, const wxString
& value
);
106 void SetXFontName(const wxString
& xFontName
);
107 #elif defined(__WXMSW__)
108 wxNativeFontInfo(const LOGFONT
& lf_
) : lf(lf_
) { }
111 #elif defined(__WXPM__)
112 // OS/2 native structures that define a font
116 #else // other platforms
118 // This is a generic implementation that should work on all ports
119 // without specific support by the port.
121 #define wxNO_NATIVE_FONTINFO
129 wxFontEncoding encoding
;
132 // default ctor (default copy ctor is ok)
133 wxNativeFontInfo() { Init(); }
137 void Init(const wxNativeFontInfo
& info
);
141 wxNativeFontInfo(const wxNativeFontInfo
& info
) { Init(info
); }
142 ~wxNativeFontInfo() { Free(); }
144 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 bool SetFaceName(const wxString
& facename
);
203 void SetFamily(wxFontFamily family
);
204 void SetEncoding(wxFontEncoding encoding
);
206 // sets the first facename in the given array which is found
207 // to be valid. If no valid facename is given, sets the
208 // first valid facename returned by wxFontEnumerator::GetFacenames().
209 // Does not return a bool since it cannot fail.
210 void SetFaceName(const wxArrayString
&facenames
);
213 // it is important to be able to serialize wxNativeFontInfo objects to be
214 // able to store them (in config file, for example)
215 bool FromString(const wxString
& s
);
216 wxString
ToString() const;
218 // we also want to present the native font descriptions to the user in some
219 // human-readable form (it is not platform independent neither, but can
220 // hopefully be understood by the user)
221 bool FromUserString(const wxString
& s
);
222 wxString
ToUserString() const;
225 // ----------------------------------------------------------------------------
226 // font-related functions (common)
227 // ----------------------------------------------------------------------------
229 // translate a wxFontEncoding into native encoding parameter (defined above),
230 // returning true if an (exact) macth could be found, false otherwise (without
231 // attempting any substitutions)
232 WXDLLIMPEXP_CORE
bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
233 wxNativeEncodingInfo
*info
);
235 // test for the existence of the font described by this facename/encoding,
236 // return true if such font(s) exist, false otherwise
237 WXDLLIMPEXP_CORE
bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
239 // ----------------------------------------------------------------------------
240 // font-related functions (X and GTK)
241 // ----------------------------------------------------------------------------
243 #ifdef _WX_X_FONTLIKE
244 #include "wx/unix/fontutil.h"
247 #endif // _WX_FONTUTIL_H_