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())
69 class WXDLLIMPEXP_CORE wxNativeFontInfo
73 PangoFontDescription
*description
;
74 #elif defined(_WX_X_FONTLIKE)
75 // the members can't be accessed directly as we only parse the
76 // xFontName on demand
78 // the components of the XLFD
79 wxString fontElements
[wxXLFD_MAX
];
84 // true until SetXFontName() is called
87 // return true if we have already initialized fontElements
88 inline bool HasElements() const;
91 // init the elements from an XLFD, return true if ok
92 bool FromXFontName(const wxString
& xFontName
);
94 // return false if we were never initialized with a valid XLFD
95 bool IsDefault() const { return m_isDefault
; }
97 // return the XLFD (using the fontElements if necessary)
98 wxString
GetXFontName() const;
100 // get the given XFLD component
101 wxString
GetXFontComponent(wxXLFDField field
) const;
103 // change the font component
104 void SetXFontComponent(wxXLFDField field
, const wxString
& value
);
107 void SetXFontName(const wxString
& xFontName
);
108 #elif defined(__WXMSW__)
109 wxNativeFontInfo(const LOGFONT
& lf_
) : lf(lf_
) { }
112 #elif defined(__WXPM__)
113 // OS/2 native structures that define a font
117 #elif defined(__WXOSX__)
119 wxNativeFontInfo(const wxNativeFontInfo
& info
) { Init(info
); }
120 wxNativeFontInfo( int size
,
125 const wxString
& faceName
,
126 wxFontEncoding encoding
)
127 { Init(size
,family
,style
,weight
,underlined
,faceName
,encoding
); }
129 ~wxNativeFontInfo() { Free(); }
131 wxNativeFontInfo
& operator=(const wxNativeFontInfo
& info
)
141 #if wxOSX_USE_CORE_TEXT
142 void Init(CTFontDescriptorRef descr
);
144 void Init(const wxNativeFontInfo
& info
);
150 const wxString
& faceName
,
151 wxFontEncoding encoding
);
156 bool m_descriptorValid
;
158 #if wxOSX_USE_ATSU_TEXT
159 bool m_atsuFontValid
;
161 wxUint32 m_atsuFontID
;
162 // the qd styles that are not intrinsic to the font above
163 wxInt16 m_atsuAdditionalQDStyles
;
165 wxInt16 m_qdFontFamily
;
166 wxInt16 m_qdFontStyle
;
171 wxFontFamily m_family
;
173 wxFontWeight m_weight
;
175 bool m_strikethrough
;
177 wxFontEncoding m_encoding
;
179 #else // other platforms
181 // This is a generic implementation that should work on all ports
182 // without specific support by the port.
184 #define wxNO_NATIVE_FONTINFO
193 wxFontEncoding encoding
;
196 // default ctor (default copy ctor is ok)
197 wxNativeFontInfo() { Init(); }
201 void Init(const wxNativeFontInfo
& info
);
205 wxNativeFontInfo(const wxNativeFontInfo
& info
) { Init(info
); }
206 ~wxNativeFontInfo() { Free(); }
208 wxNativeFontInfo
& operator=(const wxNativeFontInfo
& info
)
217 #endif // wxUSE_PANGO
219 // reset to the default state
222 // init with the parameters of the given font
223 void InitFromFont(const wxFont
& font
)
225 // translate all font parameters
226 SetStyle((wxFontStyle
)font
.GetStyle());
227 SetWeight((wxFontWeight
)font
.GetWeight());
228 SetUnderlined(font
.GetUnderlined());
229 SetStrikethrough(font
.GetStrikethrough());
230 #if defined(__WXMSW__)
231 if ( font
.IsUsingSizeInPixels() )
232 SetPixelSize(font
.GetPixelSize());
234 SetPointSize(font
.GetPointSize());
236 SetPointSize(font
.GetPointSize());
239 // set the family/facename
240 SetFamily((wxFontFamily
)font
.GetFamily());
241 const wxString
& facename
= font
.GetFaceName();
242 if ( !facename
.empty() )
244 SetFaceName(facename
);
247 // deal with encoding now (it may override the font family and facename
248 // so do it after setting them)
249 SetEncoding(font
.GetEncoding());
252 // accessors and modifiers for the font elements
253 int GetPointSize() const;
254 wxSize
GetPixelSize() const;
255 wxFontStyle
GetStyle() const;
256 wxFontWeight
GetWeight() const;
257 bool GetUnderlined() const;
258 bool GetStrikethrough() const;
259 wxString
GetFaceName() const;
260 wxFontFamily
GetFamily() const;
261 wxFontEncoding
GetEncoding() const;
263 void SetPointSize(int pointsize
);
264 void SetPixelSize(const wxSize
& pixelSize
);
265 void SetStyle(wxFontStyle style
);
266 void SetWeight(wxFontWeight weight
);
267 void SetUnderlined(bool underlined
);
268 void SetStrikethrough(bool strikethrough
);
269 bool SetFaceName(const wxString
& facename
);
270 void SetFamily(wxFontFamily family
);
271 void SetEncoding(wxFontEncoding encoding
);
273 // sets the first facename in the given array which is found
274 // to be valid. If no valid facename is given, sets the
275 // first valid facename returned by wxFontEnumerator::GetFacenames().
276 // Does not return a bool since it cannot fail.
277 void SetFaceName(const wxArrayString
&facenames
);
280 // it is important to be able to serialize wxNativeFontInfo objects to be
281 // able to store them (in config file, for example)
282 bool FromString(const wxString
& s
);
283 wxString
ToString() const;
285 // we also want to present the native font descriptions to the user in some
286 // human-readable form (it is not platform independent neither, but can
287 // hopefully be understood by the user)
288 bool FromUserString(const wxString
& s
);
289 wxString
ToUserString() const;
292 // ----------------------------------------------------------------------------
293 // font-related functions (common)
294 // ----------------------------------------------------------------------------
296 // translate a wxFontEncoding into native encoding parameter (defined above),
297 // returning true if an (exact) macth could be found, false otherwise (without
298 // attempting any substitutions)
299 WXDLLIMPEXP_CORE
bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
300 wxNativeEncodingInfo
*info
);
302 // test for the existence of the font described by this facename/encoding,
303 // return true if such font(s) exist, false otherwise
304 WXDLLIMPEXP_CORE
bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
306 // ----------------------------------------------------------------------------
307 // font-related functions (X and GTK)
308 // ----------------------------------------------------------------------------
310 #ifdef _WX_X_FONTLIKE
311 #include "wx/unix/fontutil.h"
314 #endif // _WX_FONTUTIL_H_