1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: font-related helper functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
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_
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 #if defined(_WX_X_FONTLIKE)
36 // the symbolic names for the XLFD fields (with examples for their value)
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())
68 // NB: it is a POD currently for max efficiency but if it continues to grow
69 // further it might make sense to make it a real class with virtual methods
70 struct WXDLLEXPORT wxNativeFontInfo
72 #if defined(_WX_X_FONTLIKE)
73 // the fonts array can't be accessed directly as we only parse the
74 // xFontName when needed
76 // the components of the XLFD
77 wxString fontElements
[wxXLFD_MAX
];
83 // init the elements from an XLFD, return TRUE if ok
84 bool FromXFontName(const wxString
& xFontName
);
86 // generate an XLFD using the fontElements
87 wxString
GetXFontName() const;
89 // get the given XFLD component
90 wxString
GetXFontComponent(wxXLFDField field
) const;
91 #elif defined(__WXMSW__)
93 #elif defined(__WXPM__)
94 // OS/2 native structures that define a font
98 #else // other platforms
100 // This is a generic implementation that should work on all ports
101 // without specific support by the port.
103 #define wxNO_NATIVE_FONTINFO
111 wxFontEncoding encoding
;
114 // default ctor (default copy ctor is ok)
115 wxNativeFontInfo() { Init(); }
117 // reset to the default state
120 // accessors and modifiers for the font elements
121 int GetPointSize() const;
122 wxFontStyle
GetStyle() const;
123 wxFontWeight
GetWeight() const;
124 bool GetUnderlined() const;
125 wxString
GetFaceName() const;
126 wxFontFamily
GetFamily() const;
127 wxFontEncoding
GetEncoding() const;
129 void SetPointSize(int pointsize
);
130 void SetStyle(wxFontStyle style
);
131 void SetWeight(wxFontWeight weight
);
132 void SetUnderlined(bool underlined
);
133 void SetFaceName(wxString facename
);
134 void SetFamily(wxFontFamily family
);
135 void SetEncoding(wxFontEncoding encoding
);
137 // it is important to be able to serialize wxNativeFontInfo objects to be
138 // able to store them (in config file, for example)
139 bool FromString(const wxString
& s
);
140 wxString
ToString() const;
142 // we also want to present the native font descriptions to the user in some
143 // human-readable form (it is not platform independent neither, but can
144 // hopefully be understood by the user)
145 bool FromUserString(const wxString
& s
);
146 wxString
ToUserString() const;
149 // ----------------------------------------------------------------------------
150 // font-related functions (common)
151 // ----------------------------------------------------------------------------
153 // translate a wxFontEncoding into native encoding parameter (defined above),
154 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
155 // attempting any substitutions)
156 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
157 wxNativeEncodingInfo
*info
);
159 // test for the existence of the font described by this facename/encoding,
160 // return TRUE if such font(s) exist, FALSE otherwise
161 extern bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
163 // ----------------------------------------------------------------------------
164 // font-related functions (X and GTK)
165 // ----------------------------------------------------------------------------
167 #ifdef _WX_X_FONTLIKE
168 #include "wx/unix/fontutil.h"
171 // ----------------------------------------------------------------------------
172 // font-related functions (MGL)
173 // ----------------------------------------------------------------------------
176 #include "wx/mgl/fontutil.h"
179 #endif // _WX_FONTUTIL_H_