]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/fontutil.cpp
[ 1635287 ] wrong cursor when dragging an image
[wxWidgets.git] / src / mgl / fontutil.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
127eab18 2// Name: src/mgl/fontutil.cpp
32b8ec41
VZ
3// Purpose: Font helper functions for MGL
4// Author: Vaclav Slavik
5// Created: 2001/04/29
6// RCS-ID: $Id$
c41c20a5 7// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 8// Licence: wxWindows licence
32b8ec41
VZ
9/////////////////////////////////////////////////////////////////////////////
10
32b8ec41
VZ
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
32d4c30a
WS
18#ifndef WX_PRECOMP
19 #include "wx/hash.h"
e4db172a 20 #include "wx/log.h"
32d4c30a
WS
21#endif
22
3af1a9f8
JS
23#include "wx/fontutil.h"
24#include "wx/encinfo.h"
25#include "wx/fontmap.h"
26#include "wx/tokenzr.h"
32b8ec41 27
32b8ec41 28#include "wx/listimpl.cpp"
493bdcc7 29#include "wx/sysopt.h"
32b8ec41 30#include "wx/mgl/private.h"
d7ae4a62 31#include "wx/private/fontmgr.h"
32b8ec41
VZ
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]
45bool wxNativeEncodingInfo::FromString(const wxString& s)
46{
47 wxStringTokenizer tokenizer(s, _T(";"));
48
49 wxString encid = tokenizer.GetNextToken();
50 long enc;
51 if ( !encid.ToLong(&enc) )
127eab18 52 return false;
32b8ec41
VZ
53 encoding = (wxFontEncoding)enc;
54
55 // ok even if empty
56 facename = tokenizer.GetNextToken();
57
127eab18 58 return true;
32b8ec41
VZ
59}
60
61wxString wxNativeEncodingInfo::ToString() const
62{
63 wxString s;
64 s << (long)encoding;
127eab18 65 if ( !facename.empty() )
32b8ec41
VZ
66 {
67 s << _T(';') << facename;
68 }
69
70 return s;
71}
72
73// ----------------------------------------------------------------------------
74// common functions
75// ----------------------------------------------------------------------------
76
77bool wxGetNativeFontEncoding(wxFontEncoding encoding,
78 wxNativeEncodingInfo *info)
79{
127eab18 80 wxCHECK_MSG( info, false, _T("bad pointer in wxGetNativeFontEncoding") );
32b8ec41
VZ
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
127eab18 129 return false;
32b8ec41
VZ
130 }
131
132 info->encoding = encoding;
133
127eab18 134 return true;
32b8ec41
VZ
135}
136
137bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
138{
139 if ( !info.facename )
127eab18
WS
140 return true;
141
d7ae4a62
VS
142 wxFontBundle *bundle = wxFontsManager::Get()->GetBundle(info.facename);
143 if ( !bundle )
127eab18 144 return false;
d7ae4a62
VS
145 if ( bundle->GetInfo()->fontLibType == MGL_BITMAPFONT_LIB )
146 {
32b8ec41
VZ
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);
32b8ec41 151 }
32b8ec41 152 else
d7ae4a62 153 return true;
32b8ec41 154}