source: vendor/trolltech/current/src/codecs/qfontcncodec.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1/****************************************************************************
2** $Id: qfontcncodec.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Chinese Font utilities for X11
5**
6** Created : 20010130
7**
8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
9**
10** This file is part of the tools module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "private/qfontcodecs_p.h"
39
40#ifndef QT_NO_CODECS
41#ifndef QT_NO_BIG_CODECS
42
43
44extern int qt_UnicodeToGbk(uint unicode, uchar *gbchar);
45
46
47int QFontGb2312Codec::heuristicContentMatch(const char *, int) const
48{
49 return 0;
50}
51
52
53QFontGb2312Codec::QFontGb2312Codec()
54{
55 //qDebug("QFontGb2312Codec::QFontGb2312Codec()");
56}
57
58
59const char* QFontGb2312Codec::name() const
60{
61 //qDebug("QFontGb2312Codec::name() = \"gb2312.1980-0\"");
62 return "gb2312.1980-0";
63}
64
65
66int QFontGb2312Codec::mibEnum() const
67{
68 //qDebug("QFontGb2312Codec::mibEnum() = 57");
69 return 57;
70}
71
72
73QString QFontGb2312Codec::toUnicode(const char* /*chars*/, int /*len*/) const
74{
75 return QString::null;
76}
77
78unsigned short QFontGb2312Codec::characterFromUnicode(const QString &str, int pos) const
79{
80 uchar buf[4];
81 int len = qt_UnicodeToGbk((str.unicode() + pos)->unicode(), buf);
82 if (len == 2 && buf[0] > 0xa0 && buf[1] > 0xa0)
83 return ((buf[0] & 0x7f) << 8) + (buf[1] & 0x7f);
84 return 0;
85}
86
87QCString QFontGb2312Codec::fromUnicode(const QString& uc, int& lenInOut ) const
88{
89 QCString result(lenInOut * 2 + 1);
90 uchar *rdata = (uchar *) result.data();
91 const QChar *ucp = uc.unicode();
92
93 //qDebug("QFontGb2312Codec::fromUnicode(const QString& uc, int& lenInOut = %d)", lenInOut);
94 for ( int i = 0; i < lenInOut; i++ ) {
95 QChar ch(*ucp++);
96 uchar buf[8];
97
98 int len = qt_UnicodeToGbk( ch.unicode(), buf );
99
100 if ( len == 2 && buf[0] > 0xa0 && buf[1] > 0xa0 ) {
101 *rdata++ = buf[0] & 0x7f;
102 *rdata++ = buf[1] & 0x7f;
103 } else {
104 //white square
105 *rdata++ = 0x21;
106 *rdata++ = 0x75;
107 }
108 }
109
110 lenInOut *= 2;
111
112 return result;
113}
114
115void QFontGb2312Codec::fromUnicode(const QChar *in, unsigned short *out, int length) const
116{
117 int len;
118 uchar buf[8];
119 while (length--) {
120 len = qt_UnicodeToGbk(in->unicode(), buf);
121 if ( len == 2 && buf[0] > 0xa0 && buf[1] > 0xa0 ) {
122 *out = (((buf[0] << 8) | buf[1]) & 0x7f7f);
123 } else {
124 *out = 0;
125 }
126
127 ++in;
128 ++out;
129 }
130}
131
132
133bool QFontGb2312Codec::canEncode( QChar ch ) const
134{
135 uchar buf[4];
136 int len = qt_UnicodeToGbk( ch.unicode(), buf );
137 //qDebug("QFontGb2312Codec::canEncode( QChar ch = %02X%02X )", ch.row(), ch.cell());
138 return ( len == 2 && buf[0] > 0xa0 && buf[1] > 0xa0 );
139}
140
141//==========================================================================
142
143
144int QFontGbkCodec::heuristicContentMatch(const char *, int) const
145{
146 return 0;
147}
148
149
150int QFontGbkCodec::heuristicNameMatch(const char* hint) const
151{
152 //qDebug("QFontGbkCodec::heuristicNameMatch(const char* hint = \"%s\")", hint);
153 return ( qstricmp(hint, "gbk-0") == 0 ||
154 qstricmp(hint, "gb18030.2000-0") == 0 )
155 ? 13 : 0;
156}
157
158
159QFontGbkCodec::QFontGbkCodec()
160{
161 //qDebug("QFontGbkCodec::QFontGbkCodec()");
162}
163
164
165const char* QFontGbkCodec::name() const
166{
167 //qDebug("QFontGbkCodec::name() = \"gbk-0\"");
168 return "gbk-0";
169}
170
171
172int QFontGbkCodec::mibEnum() const
173{
174 //qDebug("QFontGbkCodec::mibEnum() = -113");
175 return -113;
176}
177
178
179QString QFontGbkCodec::toUnicode(const char* /*chars*/, int /*len*/) const
180{
181 return QString::null;
182}
183
184unsigned short QFontGbkCodec::characterFromUnicode(const QString &str, int pos) const
185{
186 uchar buf[4];
187 int len = qt_UnicodeToGbk((str.unicode() + pos)->unicode(), buf);
188 if (len == 2)
189 return (buf[0] << 8) + buf[1];
190 return 0;
191}
192
193QCString QFontGbkCodec::fromUnicode(const QString& uc, int& lenInOut ) const
194{
195 QCString result(lenInOut * 2 + 1);
196 uchar *rdata = (uchar *) result.data();
197 const QChar *ucp = uc.unicode();
198
199 //qDebug("QFontGbkCodec::fromUnicode(const QString& uc, int& lenInOut = %d)", lenInOut);
200 for ( int i = 0; i < lenInOut; i++ ) {
201 QChar ch(*ucp++);
202 uchar buf[8];
203
204 int len = qt_UnicodeToGbk( ch.unicode(), buf );
205
206 if ( len == 2 ) {
207 *rdata++ = buf[0];
208 *rdata++ = buf[1];
209 } else {
210 //white square
211 *rdata++ = 0xa1;
212 *rdata++ = 0xf5;
213 }
214 }
215
216 lenInOut *= 2;
217
218 return result;
219}
220
221void QFontGbkCodec::fromUnicode(const QChar *in, unsigned short *out, int length) const
222{
223 uchar buf[8];
224 while (length--) {
225 *out++ = (qt_UnicodeToGbk(in->unicode(), buf) == 2) ? (buf[0] << 8) | buf[1] : 0;
226 ++in;
227 }
228}
229
230bool QFontGbkCodec::canEncode( QChar ch ) const
231{
232 if (ch.unicode() >= 0x4e00 && ch.unicode() <= 0x9fa5)
233 return TRUE;
234 uchar buf[4];
235 int len = qt_UnicodeToGbk( ch.unicode(), buf );
236 //qDebug("QFontGbkCodec::canEncode( QChar ch = %02X%02X )", ch.row(), ch.cell());
237 return ( len == 2 );
238}
239
240//==========================================================================
241
242int QFontGb18030_0Codec::heuristicContentMatch(const char *, int) const
243{
244 return 0;
245}
246
247
248QFontGb18030_0Codec::QFontGb18030_0Codec()
249{
250 //qDebug("QFontGb18030_0Codec::QFontGb18030_0Codec()");
251}
252
253
254const char* QFontGb18030_0Codec::name() const
255{
256 //qDebug("QFontGb18030_0Codec::name() = \"gb18030-0\"");
257 return "gb18030-0";
258}
259
260
261int QFontGb18030_0Codec::mibEnum() const
262{
263 //qDebug("QFontGb18030_0Codec::mibEnum() = -114");
264 return -114;
265}
266
267
268QString QFontGb18030_0Codec::toUnicode(const char* /*chars*/, int /*len*/) const
269{
270 return QString::null;
271}
272
273unsigned short
274QFontGb18030_0Codec::characterFromUnicode(const QString &str, int pos) const
275{
276 const QChar * const ch = str.unicode() + pos;
277 if (ch->row () > 0 && !(ch->row () >= 0xd8 && ch->row () < 0xe0))
278 return ch->unicode();
279 return 0;
280}
281
282QCString QFontGb18030_0Codec::fromUnicode(const QString& uc, int& lenInOut ) const
283{
284 QCString result(lenInOut * 2 + 1);
285 uchar *rdata = (uchar *) result.data();
286 const QChar *ucp = uc.unicode();
287
288 //qDebug("QFontGb18030_0Codec::fromUnicode(const QString& uc, int& lenInOut = %d)", lenInOut);
289 for ( int i = 0; i < lenInOut; i++ ) {
290 QChar ch(*ucp++);
291 if (ch.row () > 0 && !(ch.row () >= 0xd8 && ch.row () < 0xe0)) {
292 *rdata++ = ch.row();
293 *rdata++ = ch.cell();
294 } else {
295 *rdata++ = 0xff;
296 *rdata++ = 0xfd;
297 }
298 }
299
300 lenInOut *= 2;
301
302 return result;
303}
304
305void QFontGb18030_0Codec::fromUnicode(const QChar *in, unsigned short *out, int length) const
306{
307 while (length--) {
308 *out = ((in->row () > 0 && !(in->row () >= 0xd8 && in->row () < 0xe0))
309 ? in->unicode() : 0);
310 ++in;
311 ++out;
312 }
313}
314
315bool QFontGb18030_0Codec::canEncode( QChar ch ) const
316{
317 //qDebug("QFontGb18030_0Codec::canEncode( QChar ch = %02X%02X )", ch.row(), ch.cell());
318 return (ch.row () > 0 && !(ch.row () >= 0xd8 && ch.row () < 0xe0));
319}
320
321//==========================================================================
322
323
324#endif // QT_NO_BIG_CODECS
325#endif // QT_NO_CODECS
Note: See TracBrowser for help on using the repository browser.