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 // accessors and modifiers for the font elements
143 int GetPointSize() const;
144 wxFontStyle
GetStyle() const;
145 wxFontWeight
GetWeight() const;
146 bool GetUnderlined() const;
147 wxString
GetFaceName() const;
148 wxFontFamily
GetFamily() const;
149 wxFontEncoding
GetEncoding() const;
151 void SetPointSize(int pointsize
);
152 void SetStyle(wxFontStyle style
);
153 void SetWeight(wxFontWeight weight
);
154 void SetUnderlined(bool underlined
);
155 void SetFaceName(wxString facename
);
156 void SetFamily(wxFontFamily family
);
157 void SetEncoding(wxFontEncoding encoding
);
159 // it is important to be able to serialize wxNativeFontInfo objects to be
160 // able to store them (in config file, for example)
161 bool FromString(const wxString
& s
);
162 wxString
ToString() const;
164 // we also want to present the native font descriptions to the user in some
165 // human-readable form (it is not platform independent neither, but can
166 // hopefully be understood by the user)
167 bool FromUserString(const wxString
& s
);
168 wxString
ToUserString() const;
171 // ----------------------------------------------------------------------------
172 // font-related functions (common)
173 // ----------------------------------------------------------------------------
175 // translate a wxFontEncoding into native encoding parameter (defined above),
176 // returning TRUE if an (exact) macth could be found, FALSE otherwise (without
177 // attempting any substitutions)
178 extern bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
179 wxNativeEncodingInfo
*info
);
181 // test for the existence of the font described by this facename/encoding,
182 // return TRUE if such font(s) exist, FALSE otherwise
183 extern bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
);
185 // ----------------------------------------------------------------------------
186 // font-related functions (X and GTK)
187 // ----------------------------------------------------------------------------
189 #ifdef _WX_X_FONTLIKE
190 #include "wx/unix/fontutil.h"
193 // ----------------------------------------------------------------------------
194 // font-related functions (MGL)
195 // ----------------------------------------------------------------------------
198 #include "wx/mgl/fontutil.h"
201 #endif // _WX_FONTUTIL_H_