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 struct WXDLLEXPORT wxNativeEncodingInfo
;
31 #if defined(_WX_X_FONTLIKE)
33 // the symbolic names for the XLFD fields (with examples for their value)
35 // NB: we suppose that the font always starts with the empty token (font name
36 // registry field) as we never use nor generate it anyhow
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, ...
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, ...
56 #endif // _WX_X_FONTLIKE
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
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 class WXDLLEXPORT wxNativeFontInfo
71 PangoFontDescription
*description
;
72 #elif defined(_WX_X_FONTLIKE)
73 // the members can't be accessed directly as we only parse the
74 // xFontName on demand
76 // the components of the XLFD
77 wxString fontElements
[wxXLFD_MAX
];
82 // true until SetXFontName() is called
85 // return true if we have already initialized fontElements
86 inline bool HasElements() const;
89 // init the elements from an XLFD, return true if ok
90 bool FromXFontName(const wxString
& xFontName
);
92 // return false if we were never initialized with a valid XLFD
93 bool IsDefault() const { return m_isDefault
; }
95 // return the XLFD (using the fontElements if necessary)
96 wxString
GetXFontName() const;
98 // get the given XFLD component
99 wxString
GetXFontComponent(wxXLFDField field
) const;
101 // change the font component
102 void SetXFontComponent(wxXLFDField field
, const wxString
& value
);
105 void SetXFontName(const wxString
& xFontName
);
106 #elif defined(__WXMSW__)
108 #elif defined(__WXPM__)
109 // OS/2 native structures that define a font
113 #else // other platforms
115 // This is a generic implementation that should work on all ports
116 // without specific support by the port.
118 #define wxNO_NATIVE_FONTINFO
126 wxFontEncoding encoding
;
129 // default ctor (default copy ctor is ok)
130 wxNativeFontInfo() { Init(); }
134 void Init(const wxNativeFontInfo
& info
);
138 wxNativeFontInfo(const wxNativeFontInfo
& info
) { Init(info
); }
139 ~wxNativeFontInfo() { Free(); }
141 wxNativeFontInfo
& operator=(const wxNativeFontInfo
& info
)
147 #endif // wxUSE_PANGO
149 // reset to the default state
152 // init with the parameters of the given font
153 void InitFromFont(const wxFont
& font
)
155 // translate all font parameters
156 SetStyle((wxFontStyle
)font
.GetStyle());
157 SetWeight((wxFontWeight
)font
.GetWeight());
158 SetUnderlined(font
.GetUnderlined());
159 #if defined(__WXMSW__)
160 if ( font
.IsUsingSizeInPixels() )
161 SetPixelSize(font
.GetPixelSize());
163 SetPointSize(font
.GetPointSize());
165 SetPointSize(font
.GetPointSize());
168 // set the family/facename
169 SetFamily((wxFontFamily
)font
.GetFamily());
170 const wxString
& facename
= font
.GetFaceName();
171 if ( !facename
.empty() )
173 SetFaceName(facename
);
176 // deal with encoding now (it may override the font family and facename
177 // so do it after setting them)
178 SetEncoding(font
.GetEncoding());
181 // accessors and modifiers for the font elements
182 int GetPointSize() const;
183 wxSize
GetPixelSize() const;
184 wxFontStyle
GetStyle() const;
185 wxFontWeight
GetWeight() const;
186 bool GetUnderlined() const;
187 wxString
GetFaceName() const;
188 wxFontFamily
GetFamily() const;
189 wxFontEncoding
GetEncoding() const;
191 void SetPointSize(int pointsize
);
192 void SetPixelSize(const wxSize
& pixelSize
);
193 void SetStyle(wxFontStyle style
);
194 void SetWeight(wxFontWeight weight
);
195 void SetUnderlined(bool underlined
);
196 bool SetFaceName(const wxString
& facename
);
197 void SetFamily(wxFontFamily family
);
198 void SetEncoding(wxFontEncoding encoding
);
200 // sets the first facename in the given array which is found
201 // to be valid. If no valid facename is given, sets the
202 // first valid facename returned by wxFontEnumerator::GetFacenames().
203 // Does not return a bool since it cannot fail.
204 void SetFaceName(const wxArrayString
&facenames
);
207 // it is important to be able to serialize wxNativeFontInfo objects to be
208 // able to store them (in config file, for example)
209 bool FromString(const wxString
& s
);
210 wxString
ToString() const;
212 // we also want to present the native font descriptions to the user in some
213 // human-readable form (it is not platform independent neither, but can
214 // hopefully be understood by the user)
215 bool FromUserString(const wxString
& s
);
216 wxString
ToUserString() const;
219 // ----------------------------------------------------------------------------
220 // font-related functions (common)
221 // ----------------------------------------------------------------------------
223 // translate a wxFontEncoding into native encoding parameter (defined above),
224 // returning true if an (exact) macth could be found, false otherwise (without
225 // attempting any substitutions)
226 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
227 wxNativeEncodingInfo
*info
);
229 // test for the existence of the font described by this facename/encoding,
230 // return true if such font(s) exist, false otherwise
231 extern bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
233 // ----------------------------------------------------------------------------
234 // font-related functions (X and GTK)
235 // ----------------------------------------------------------------------------
237 #ifdef _WX_X_FONTLIKE
238 #include "wx/unix/fontutil.h"
241 // ----------------------------------------------------------------------------
242 // font-related functions (MGL)
243 // ----------------------------------------------------------------------------
246 #include "wx/mgl/fontutil.h"
249 #endif // _WX_FONTUTIL_H_