File: fontmap.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (196 lines) | stat: -rw-r--r-- 7,191 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/////////////////////////////////////////////////////////////////////////////
// Name:        fontmap.h
// Purpose:     interface of wxFontMapper
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    @class wxFontMapper

    wxFontMapper manages user-definable correspondence between logical font
    names and the fonts present on the machine.

    The default implementations of all functions will ask the user if they are
    not capable of finding the answer themselves and store the answer in a
    config file (configurable via SetConfigXXX functions). This behaviour may
    be disabled by giving the value of @false to "interactive" parameter.

    However, the functions will always consult the config file to allow the
    user-defined values override the default logic and there is no way to
    disable this - which shouldn't be ever needed because if "interactive" was
    never @true, the config file is never created anyhow.

    In case everything else fails (i.e. there is no record in config file
    and "interactive" is @false or user denied to choose any replacement),
    the class queries wxEncodingConverter for "equivalent" encodings
    (e.g. iso8859-2 and cp1250) and tries them.


    @section fontmapper_mbconv Using wxFontMapper in conjunction with wxMBConv classes

    If you need to display text in encoding which is not available at host
    system (see wxFontMapper::IsEncodingAvailable), you may use these two
    classes to find font in some similar encoding (see wxFontMapper::GetAltForEncoding)
    and convert the text to this encoding (wxMBConv classes).
    Following code snippet demonstrates it:

    @code
    if (!wxFontMapper::Get()->IsEncodingAvailable(enc, facename))
    {
        wxFontEncoding alternative;
        if (wxFontMapper::Get()->GetAltForEncoding(enc, &alternative,
                                                    facename, false))
        {
            wxCSConv convFrom(wxFontMapper::Get()->GetEncodingName(enc));
            wxCSConv convTo(wxFontMapper::Get()->GetEncodingName(alternative));
            text = wxString(text.mb_str(convFrom), convTo);
        }
        else
            ...failure (or we may try iso8859-1/7bit ASCII)...
    }
    ...display text...
    @endcode

    @library{wxcore}
    @category{cfg}

    @see wxEncodingConverter, @ref overview_nonenglish
*/
class wxFontMapper
{
public:
    /**
        Default ctor.

        @note
        The preferred way of creating a wxFontMapper instance is to call wxFontMapper::Get().
    */
    wxFontMapper();

    /**
        Virtual dtor.
    */
    virtual ~wxFontMapper();

    /**
        Returns the encoding for the given charset (in the form of RFC 2046) or
        @c wxFONTENCODING_SYSTEM if couldn't decode it.

        Be careful when using this function with @a interactive set to @true
        (default value) as the function then may show a dialog box to the user which
        may lead to unexpected reentrancies and may also take a significantly longer
        time than a simple function call. For these reasons, it is almost always a bad
        idea to call this function from the event handlers for repeatedly generated
        events such as @c EVT_PAINT.
    */
    virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
                                             bool interactive = true);

    /**
        Get the current font mapper object. If there is no current object, creates one.

        @see Set()
    */
    static wxFontMapper* Get();

    /**
        Returns the array of all possible names for the given encoding.

        The array is @NULL-terminated. IF it isn't empty, the first name in it is
        the canonical encoding name, i.e. the same string as returned by
        GetEncodingName().
    */
    static const wxChar** GetAllEncodingNames(wxFontEncoding encoding);

    //@{
    /**
        Find an alternative for the given encoding (which is supposed to not be
        available on this system). If successful, return @true and fill info
        structure with the parameters required to create the font, otherwise
        return @false.

        The first form is for wxWidgets' internal use while the second one
        is better suitable for general use -- it returns wxFontEncoding which
        can consequently be passed to wxFont constructor.
    */
    bool GetAltForEncoding(wxFontEncoding encoding,
                           wxNativeEncodingInfo* info,
                           const wxString& facename = wxEmptyString,
                           bool interactive = true);
    bool GetAltForEncoding(wxFontEncoding encoding,
                           wxFontEncoding* alt_encoding,
                           const wxString& facename = wxEmptyString,
                           bool interactive = true);
    //@}

    /**
        Returns the @e n-th supported encoding.

        Together with GetSupportedEncodingsCount() this method may be used
        to get all supported encodings.
    */
    static wxFontEncoding GetEncoding(size_t n);

    /**
        Return user-readable string describing the given encoding.
    */
    static wxString GetEncodingDescription(wxFontEncoding encoding);

    /**
        Return the encoding corresponding to the given internal name.

        This function is the inverse of GetEncodingName() and is intentionally
        less general than CharsetToEncoding(), i.e. it doesn't try to make any
        guesses nor ever asks the user. It is meant just as a way of restoring
        objects previously serialized using GetEncodingName().
    */
    static wxFontEncoding GetEncodingFromName(const wxString& encoding);

    /**
        Return internal string identifier for the encoding (see also
        wxFontMapper::GetEncodingDescription).

        @see GetEncodingFromName()
    */
    static wxString GetEncodingName(wxFontEncoding encoding);

    /**
        Returns the number of the font encodings supported by this class.
        Together with GetEncoding() this method may be used to get
        all supported encodings.
    */
    static size_t GetSupportedEncodingsCount();

    /**
        Check whether given encoding is available in given face or not.
        If no facename is given, find @e any font in this encoding.
    */
    virtual bool IsEncodingAvailable(wxFontEncoding encoding,
                                     const wxString& facename = wxEmptyString);

    /**
        Set the current font mapper object and return previous one (may be @NULL).
        This method is only useful if you want to plug-in an alternative font mapper
        into wxWidgets.

        @see Get()
    */
    static wxFontMapper* Set(wxFontMapper* mapper);

    /**
        Set the root config path to use (should be an absolute path).
    */
    void SetConfigPath(const wxString& prefix);

    /**
        The parent window for modal dialogs.
    */
    void SetDialogParent(wxWindow* parent);

    /**
        The title for the dialogs (note that default is quite reasonable).
    */
    void SetDialogTitle(const wxString& title);
};