]> git.saurik.com Git - wxWidgets.git/blame - include/wx/fontutil.h
renamed wxComboControl to wxComboCtrl and related wxUSE_XXX and configure switches...
[wxWidgets.git] / include / wx / fontutil.h
CommitLineData
7beba2fc
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/fontutil.h
3// Purpose: font-related helper functions
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05.11.99
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
7beba2fc
VZ
10/////////////////////////////////////////////////////////////////////////////
11
77ffb593 12// General note: this header is private to wxWidgets and is not supposed to be
7beba2fc
VZ
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.
15
16#ifndef _WX_FONTUTIL_H_
17#define _WX_FONTUTIL_H_
18
7beba2fc
VZ
19// ----------------------------------------------------------------------------
20// headers
21// ----------------------------------------------------------------------------
22
23#include "wx/font.h" // for wxFont and wxFontEncoding
24
82ef81ed 25#if defined(__WXMSW__)
7b162e54 26 #include "wx/msw/wrapwin.h"
09fcd889
VZ
27#endif
28
e4ffab29
MB
29struct WXDLLEXPORT wxNativeEncodingInfo;
30
53f6aab7
VZ
31#if defined(_WX_X_FONTLIKE)
32
33// the symbolic names for the XLFD fields (with examples for their value)
409d5a58
VZ
34//
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
53f6aab7
VZ
37enum wxXLFDField
38{
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, ...
48 wxXLFD_RESY,
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, ...
53 wxXLFD_MAX
54};
55
56#endif // _WX_X_FONTLIKE
57
7beba2fc
VZ
58// ----------------------------------------------------------------------------
59// types
60// ----------------------------------------------------------------------------
61
7826e2dd
VZ
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())
ab5fe833
VZ
67//
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
7826e2dd 70struct WXDLLEXPORT wxNativeFontInfo
7beba2fc 71{
2b5f62a0
VZ
72#if wxUSE_PANGO
73 PangoFontDescription *description;
74#elif defined(_WX_X_FONTLIKE)
409d5a58
VZ
75 // the members can't be accessed directly as we only parse the
76 // xFontName on demand
53f6aab7 77private:
ab5fe833 78 // the components of the XLFD
53f6aab7 79 wxString fontElements[wxXLFD_MAX];
ab5fe833
VZ
80
81 // the full XLFD
7826e2dd 82 wxString xFontName;
ab5fe833 83
409d5a58
VZ
84 // true until SetXFontName() is called
85 bool m_isDefault;
86
87 // return true if we have already initialized fontElements
88 inline bool HasElements() const;
89
90public:
a62848fd 91 // init the elements from an XLFD, return true if ok
ab5fe833
VZ
92 bool FromXFontName(const wxString& xFontName);
93
409d5a58
VZ
94 // return false if we were never initialized with a valid XLFD
95 bool IsDefault() const { return m_isDefault; }
96
97 // return the XLFD (using the fontElements if necessary)
ab5fe833 98 wxString GetXFontName() const;
53f6aab7
VZ
99
100 // get the given XFLD component
101 wxString GetXFontComponent(wxXLFDField field) const;
409d5a58
VZ
102
103 // change the font component
104 void SetXFontComponent(wxXLFDField field, const wxString& value);
105
106 // set the XFLD
107 void SetXFontName(const wxString& xFontName);
82ef81ed 108#elif defined(__WXMSW__)
09fcd889 109 LOGFONT lf;
cc95f4f9
DW
110#elif defined(__WXPM__)
111 // OS/2 native structures that define a font
112 FATTRS fa;
113 FONTMETRICS fm;
114 FACENAMEDESC fn;
7826e2dd
VZ
115#else // other platforms
116 //
117 // This is a generic implementation that should work on all ports
118 // without specific support by the port.
119 //
ef243e70 120 #define wxNO_NATIVE_FONTINFO
ab5fe833 121
7826e2dd 122 int pointSize;
7936354d 123 wxFontFamily family;
ab5fe833
VZ
124 wxFontStyle style;
125 wxFontWeight weight;
7826e2dd
VZ
126 bool underlined;
127 wxString faceName;
128 wxFontEncoding encoding;
129#endif // platforms
130
ab5fe833
VZ
131 // default ctor (default copy ctor is ok)
132 wxNativeFontInfo() { Init(); }
133
fdf7514a 134#if wxUSE_PANGO
23afe648
VZ
135private:
136 void Init(const wxNativeFontInfo& info);
137 void Free();
138
139public:
140 wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
141 ~wxNativeFontInfo() { Free(); }
142
143 wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
144 {
145 Free();
146 Init(info);
147 return *this;
148 }
149#endif // wxUSE_PANGO
fdf7514a 150
ab5fe833
VZ
151 // reset to the default state
152 void Init();
153
3bf5a59b
VZ
154 // init with the parameters of the given font
155 void InitFromFont(const wxFont& font)
156 {
157 // translate all font parameters
158 SetStyle((wxFontStyle)font.GetStyle());
159 SetWeight((wxFontWeight)font.GetWeight());
160 SetUnderlined(font.GetUnderlined());
544229d1
VZ
161#if defined(__WXMSW__)
162 if ( font.IsUsingSizeInPixels() )
163 SetPixelSize(font.GetPixelSize());
164 else
66e9a9f0 165 SetPointSize(font.GetPointSize());
544229d1 166#else
3bf5a59b 167 SetPointSize(font.GetPointSize());
544229d1 168#endif
3bf5a59b
VZ
169
170 // set the family/facename
171 SetFamily((wxFontFamily)font.GetFamily());
172 const wxString& facename = font.GetFaceName();
173 if ( !facename.empty() )
174 {
175 SetFaceName(facename);
176 }
177
178 // deal with encoding now (it may override the font family and facename
179 // so do it after setting them)
180 SetEncoding(font.GetEncoding());
181 }
182
7936354d 183 // accessors and modifiers for the font elements
ab5fe833 184 int GetPointSize() const;
544229d1 185 wxSize GetPixelSize() const;
ab5fe833
VZ
186 wxFontStyle GetStyle() const;
187 wxFontWeight GetWeight() const;
188 bool GetUnderlined() const;
189 wxString GetFaceName() const;
7936354d 190 wxFontFamily GetFamily() const;
ab5fe833
VZ
191 wxFontEncoding GetEncoding() const;
192
193 void SetPointSize(int pointsize);
544229d1 194 void SetPixelSize(const wxSize& pixelSize);
ab5fe833
VZ
195 void SetStyle(wxFontStyle style);
196 void SetWeight(wxFontWeight weight);
197 void SetUnderlined(bool underlined);
fbfb8bcc 198 void SetFaceName(const wxString& facename);
7936354d 199 void SetFamily(wxFontFamily family);
ab5fe833
VZ
200 void SetEncoding(wxFontEncoding encoding);
201
7826e2dd
VZ
202 // it is important to be able to serialize wxNativeFontInfo objects to be
203 // able to store them (in config file, for example)
7beba2fc
VZ
204 bool FromString(const wxString& s);
205 wxString ToString() const;
ab5fe833
VZ
206
207 // we also want to present the native font descriptions to the user in some
208 // human-readable form (it is not platform independent neither, but can
209 // hopefully be understood by the user)
210 bool FromUserString(const wxString& s);
211 wxString ToUserString() const;
7beba2fc
VZ
212};
213
214// ----------------------------------------------------------------------------
215// font-related functions (common)
216// ----------------------------------------------------------------------------
217
218// translate a wxFontEncoding into native encoding parameter (defined above),
a62848fd 219// returning true if an (exact) macth could be found, false otherwise (without
7beba2fc
VZ
220// attempting any substitutions)
221extern bool wxGetNativeFontEncoding(wxFontEncoding encoding,
222 wxNativeEncodingInfo *info);
223
224// test for the existence of the font described by this facename/encoding,
a62848fd 225// return true if such font(s) exist, false otherwise
7beba2fc
VZ
226extern bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
227
228// ----------------------------------------------------------------------------
229// font-related functions (X and GTK)
230// ----------------------------------------------------------------------------
231
232#ifdef _WX_X_FONTLIKE
233 #include "wx/unix/fontutil.h"
234#endif // X || GDK
235
1e6feb95
VZ
236// ----------------------------------------------------------------------------
237// font-related functions (MGL)
238// ----------------------------------------------------------------------------
239
240#ifdef __WXMGL__
241 #include "wx/mgl/fontutil.h"
242#endif // __WXMGL__
243
7beba2fc 244#endif // _WX_FONTUTIL_H_