]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/fontutil.cpp
mimetype.cpp/.h split into unix,mac,msw
[wxWidgets.git] / src / mac / carbon / fontutil.cpp
CommitLineData
72e7876b
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/fontutil.cpp
3// Purpose: font-related helper functions for wxMSW
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05.11.99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9// Licence: wxWindows license
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "fontutil.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35#endif //WX_PRECOMP
36
37#include "wx/fontutil.h"
38#include "wx/fontmap.h"
39
40#include "wx/tokenzr.h"
41
42// ============================================================================
43// implementation
44// ============================================================================
45
46// ----------------------------------------------------------------------------
47// wxNativeEncodingInfo
48// ----------------------------------------------------------------------------
49
50// convert to/from the string representation: format is
1e1d0be1 51// encodingid;facename[;charset]
72e7876b
SC
52
53bool wxNativeEncodingInfo::FromString(const wxString& s)
54{
55 wxStringTokenizer tokenizer(s, _T(";"));
56
1e1d0be1
VS
57 wxString encid = tokenizer.GetNextToken();
58 long enc;
59 if ( !encid.ToLong(&enc) )
60 return FALSE;
61 encoding = (wxFontEncoding)enc;
62
72e7876b
SC
63 facename = tokenizer.GetNextToken();
64 if ( !facename )
65 return FALSE;
66
67 wxString tmp = tokenizer.GetNextToken();
68 if ( !tmp )
69 {
70 // default charset (don't use DEFAULT_CHARSET though because of subtle
71 // Windows 9x/NT differences in handling it)
72 charset = 0;
73 }
74 else
75 {
76 if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
77 {
78 // should be a number!
79 return FALSE;
80 }
81 }
82
83 return TRUE;
84}
85
86wxString wxNativeEncodingInfo::ToString() const
87{
1e1d0be1
VS
88 wxString s;
89
90 s << (long)encoding << _T(';') << facename;
91
72e7876b
SC
92 if ( charset != 0 )
93 {
94 s << _T(';') << charset;
95 }
96
97 return s;
98}
99
100// ----------------------------------------------------------------------------
101// helper functions
102// ----------------------------------------------------------------------------
103
104bool wxGetNativeFontEncoding(wxFontEncoding encoding,
105 wxNativeEncodingInfo *info)
106{
107 wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
108
109 if ( encoding == wxFONTENCODING_DEFAULT )
110 {
111 encoding = wxFont::GetDefaultEncoding();
112 }
113
114 switch ( encoding )
115 {
116 // although this function is supposed to return an exact match, do do
117 // some mappings here for the most common case of "standard" encoding
118 case wxFONTENCODING_SYSTEM:
119 case wxFONTENCODING_ISO8859_1:
120 case wxFONTENCODING_ISO8859_15:
121 case wxFONTENCODING_CP1252:
122 info->charset = 0;
123 break;
124
125 case wxFONTENCODING_CP1250:
126 info->charset = 0;
127 break;
128
129 case wxFONTENCODING_CP1251:
130 info->charset = 0;
131 break;
132
133 case wxFONTENCODING_CP1253:
134 info->charset = 0;
135 break;
136
137 case wxFONTENCODING_CP1254:
138 info->charset = 0;
139 break;
140
141 case wxFONTENCODING_CP1255:
142 info->charset = 0;
143 break;
144
145 case wxFONTENCODING_CP1256:
146 info->charset = 0;
147 break;
148
149 case wxFONTENCODING_CP1257:
150 info->charset = 0;
151 break;
152
153 case wxFONTENCODING_CP437:
154 info->charset = 0;
155 break;
156
157 default:
158 // no way to translate this encoding into a Windows charset
159 return FALSE;
160 }
161
6b0eebc5
VS
162 info->encoding = encoding;
163
72e7876b
SC
164 return TRUE;
165}
166
167bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
168{
169 return TRUE;
170}