]> git.saurik.com Git - wxWidgets.git/blob - src/mgl/fontutil.cpp
Use unsigned char for XBM bitmaps data.
[wxWidgets.git] / src / mgl / fontutil.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/fontutil.cpp
3 // Purpose: Font helper functions for MGL
4 // Author: Vaclav Slavik
5 // Created: 2001/04/29
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/hash.h"
20 #include "wx/log.h"
21 #endif
22
23 #include "wx/fontutil.h"
24 #include "wx/encinfo.h"
25 #include "wx/fontmap.h"
26 #include "wx/tokenzr.h"
27
28 #include "wx/listimpl.cpp"
29 #include "wx/sysopt.h"
30 #include "wx/mgl/private.h"
31 #include "wx/private/fontmgr.h"
32
33 #include <mgraph.h>
34
35 // ============================================================================
36 // implementation
37 // ============================================================================
38
39 // ----------------------------------------------------------------------------
40 // wxNativeEncodingInfo
41 // ----------------------------------------------------------------------------
42
43 // convert to/from the string representation: format is
44 // encoding[;facename]
45 bool wxNativeEncodingInfo::FromString(const wxString& s)
46 {
47 wxStringTokenizer tokenizer(s, wxT(";"));
48
49 wxString encid = tokenizer.GetNextToken();
50 long enc;
51 if ( !encid.ToLong(&enc) )
52 return false;
53 encoding = (wxFontEncoding)enc;
54
55 // ok even if empty
56 facename = tokenizer.GetNextToken();
57
58 return true;
59 }
60
61 wxString wxNativeEncodingInfo::ToString() const
62 {
63 wxString s;
64 s << (long)encoding;
65 if ( !facename.empty() )
66 {
67 s << wxT(';') << facename;
68 }
69
70 return s;
71 }
72
73 // ----------------------------------------------------------------------------
74 // common functions
75 // ----------------------------------------------------------------------------
76
77 bool wxGetNativeFontEncoding(wxFontEncoding encoding,
78 wxNativeEncodingInfo *info)
79 {
80 wxCHECK_MSG( info, false, wxT("bad pointer in wxGetNativeFontEncoding") );
81
82 if ( encoding == wxFONTENCODING_DEFAULT )
83 {
84 encoding = wxFont::GetDefaultEncoding();
85 }
86
87 switch ( encoding )
88 {
89 case wxFONTENCODING_ISO8859_1:
90 case wxFONTENCODING_ISO8859_2:
91 case wxFONTENCODING_ISO8859_3:
92 case wxFONTENCODING_ISO8859_4:
93 case wxFONTENCODING_ISO8859_5:
94 case wxFONTENCODING_ISO8859_6:
95 case wxFONTENCODING_ISO8859_7:
96 case wxFONTENCODING_ISO8859_8:
97 case wxFONTENCODING_ISO8859_9:
98 case wxFONTENCODING_ISO8859_10:
99 case wxFONTENCODING_ISO8859_11:
100 case wxFONTENCODING_ISO8859_13:
101 case wxFONTENCODING_ISO8859_14:
102 case wxFONTENCODING_ISO8859_15:
103 info->mglEncoding = MGL_ENCODING_ISO8859_1 +
104 (encoding - wxFONTENCODING_ISO8859_1);
105 break;
106
107 case wxFONTENCODING_KOI8:
108 info->mglEncoding = MGL_ENCODING_KOI8;
109 break;
110
111 case wxFONTENCODING_CP1250:
112 case wxFONTENCODING_CP1251:
113 case wxFONTENCODING_CP1252:
114 case wxFONTENCODING_CP1253:
115 case wxFONTENCODING_CP1254:
116 case wxFONTENCODING_CP1255:
117 case wxFONTENCODING_CP1256:
118 case wxFONTENCODING_CP1257:
119 info->mglEncoding = MGL_ENCODING_CP1250 +
120 (encoding - wxFONTENCODING_CP1250);
121 break;
122
123 case wxFONTENCODING_SYSTEM:
124 info->mglEncoding = MGL_ENCODING_ASCII;
125 break;
126
127 default:
128 // encoding not known to MGL
129 return false;
130 }
131
132 info->encoding = encoding;
133
134 return true;
135 }
136
137 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
138 {
139 if ( !info.facename )
140 return true;
141
142 wxFontBundle *bundle = wxFontsManager::Get()->GetBundle(info.facename);
143 if ( !bundle )
144 return false;
145 if ( bundle->GetInfo()->fontLibType == MGL_BITMAPFONT_LIB )
146 {
147 return (info.mglEncoding == MGL_ENCODING_ASCII ||
148 info.mglEncoding == MGL_ENCODING_ISO8859_1 ||
149 info.mglEncoding == MGL_ENCODING_ISO8859_15 ||
150 info.mglEncoding == MGL_ENCODING_CP1252);
151 }
152 else
153 return true;
154 }