1 | /****************************************************************************
|
---|
2 | ** $Id: qfontjpcodec.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Japanese Font utilities for X11
|
---|
5 | **
|
---|
6 | ** Created : 20010130
|
---|
7 | **
|
---|
8 | ** Copyright (C) 1992-2000 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 | #include "qjpunicode.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | // JIS X 0201
|
---|
46 |
|
---|
47 | QFontJis0201Codec::QFontJis0201Codec()
|
---|
48 | {
|
---|
49 | }
|
---|
50 |
|
---|
51 | const char *QFontJis0201Codec::name() const
|
---|
52 | {
|
---|
53 | return "jisx0201*-0";
|
---|
54 | }
|
---|
55 |
|
---|
56 | int QFontJis0201Codec::mibEnum() const
|
---|
57 | {
|
---|
58 | return 15;
|
---|
59 | }
|
---|
60 |
|
---|
61 | unsigned short
|
---|
62 | QFontJis0201Codec::characterFromUnicode(const QString &str, int pos) const
|
---|
63 | {
|
---|
64 | const QChar *c = str.unicode() + pos;
|
---|
65 | if ( c->unicode() < 0x80 )
|
---|
66 | return c->unicode();
|
---|
67 | if ( c->unicode() >= 0xff61 && c->unicode() <= 0xff9f )
|
---|
68 | return c->unicode() - 0xff61 + 0xa1;
|
---|
69 | return 0;
|
---|
70 | }
|
---|
71 |
|
---|
72 | QCString QFontJis0201Codec::fromUnicode(const QString& uc, int& lenInOut ) const
|
---|
73 | {
|
---|
74 | QCString rstring( lenInOut+1 );
|
---|
75 | uchar *rdata = (uchar *) rstring.data();
|
---|
76 | const QChar *sdata = uc.unicode();
|
---|
77 | int i = 0;
|
---|
78 | for ( ; i < lenInOut; ++i, ++sdata, ++rdata ) {
|
---|
79 | if ( sdata->unicode() < 0x80 ) {
|
---|
80 | *rdata = (uchar) sdata->unicode();
|
---|
81 | } else if ( sdata->unicode() >= 0xff61 && sdata->unicode() <= 0xff9f ) {
|
---|
82 | *rdata = (uchar) (sdata->unicode() - 0xff61 + 0xa1);
|
---|
83 | } else {
|
---|
84 | *rdata = '?';
|
---|
85 | }
|
---|
86 | }
|
---|
87 | *rdata = 0u;
|
---|
88 | return rstring;
|
---|
89 | }
|
---|
90 |
|
---|
91 | void QFontJis0201Codec::fromUnicode(const QChar *in, unsigned short *out, int length) const
|
---|
92 | {
|
---|
93 | while (length--) {
|
---|
94 | if ( in->unicode() < 0x80 ) {
|
---|
95 | *out = (uchar) in->unicode();
|
---|
96 | } else if ( in->unicode() >= 0xff61 && in->unicode() <= 0xff9f ) {
|
---|
97 | *out = (uchar) (in->unicode() - 0xff61 + 0xa1);
|
---|
98 | } else {
|
---|
99 | *out = 0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | ++in;
|
---|
103 | ++out;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | int QFontJis0201Codec::heuristicNameMatch(const char* hint) const
|
---|
108 | {
|
---|
109 | if ( qstrncmp( hint, "jisx0201", 8 ) == 0 )
|
---|
110 | return 20;
|
---|
111 | return -1;
|
---|
112 |
|
---|
113 | }
|
---|
114 |
|
---|
115 | bool QFontJis0201Codec::canEncode( QChar ch ) const
|
---|
116 | {
|
---|
117 | return ( ch.unicode() < 0x80 || ( ch.unicode() >= 0xff61 &&
|
---|
118 | ch.unicode() <= 0xff9f ) );
|
---|
119 | }
|
---|
120 |
|
---|
121 | int QFontJis0201Codec::heuristicContentMatch(const char *, int) const
|
---|
122 | {
|
---|
123 | return 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | // JIS X 0208
|
---|
128 |
|
---|
129 | int QFontJis0208Codec::heuristicContentMatch(const char *, int) const
|
---|
130 | {
|
---|
131 | return 0;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | int QFontJis0208Codec::heuristicNameMatch(const char *hint) const
|
---|
136 | {
|
---|
137 | if ( qstrncmp( hint, "jisx0208.", 9 ) == 0 )
|
---|
138 | return 20;
|
---|
139 | return -1;
|
---|
140 | }
|
---|
141 |
|
---|
142 | QFontJis0208Codec::QFontJis0208Codec()
|
---|
143 | {
|
---|
144 | convJP = QJpUnicodeConv::newConverter(QJpUnicodeConv::Default);
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 | QFontJis0208Codec::~QFontJis0208Codec()
|
---|
149 | {
|
---|
150 | delete convJP;
|
---|
151 | convJP = 0;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | const char* QFontJis0208Codec::name() const
|
---|
156 | {
|
---|
157 | return "jisx0208*-0";
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | int QFontJis0208Codec::mibEnum() const
|
---|
162 | {
|
---|
163 | return 63;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | QString QFontJis0208Codec::toUnicode(const char* /*chars*/, int /*len*/) const
|
---|
168 | {
|
---|
169 | return QString::null;
|
---|
170 | }
|
---|
171 |
|
---|
172 | unsigned short QFontJis0208Codec::characterFromUnicode(const QString &str, int pos) const
|
---|
173 | {
|
---|
174 | return convJP->unicodeToJisx0208((str.unicode() + pos)->unicode());
|
---|
175 | }
|
---|
176 |
|
---|
177 | QCString QFontJis0208Codec::fromUnicode(const QString& uc, int& lenInOut ) const
|
---|
178 | {
|
---|
179 | QCString result(lenInOut * 2 + 1);
|
---|
180 | uchar *rdata = (uchar *) result.data();
|
---|
181 | const QChar *ucp = uc.unicode();
|
---|
182 |
|
---|
183 | for ( int i = 0; i < lenInOut; i++ ) {
|
---|
184 | QChar ch(*ucp++);
|
---|
185 | ch = convJP->unicodeToJisx0208(ch.unicode());
|
---|
186 |
|
---|
187 | if ( ! ch.isNull() ) {
|
---|
188 | *rdata++ = ch.row();
|
---|
189 | *rdata++ = ch.cell();
|
---|
190 | } else {
|
---|
191 | //white square
|
---|
192 | *rdata++ = 0x22;
|
---|
193 | *rdata++ = 0x22;
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | lenInOut *= 2;
|
---|
198 |
|
---|
199 | return result;
|
---|
200 | }
|
---|
201 |
|
---|
202 | void QFontJis0208Codec::fromUnicode(const QChar *in, unsigned short *out, int length) const
|
---|
203 | {
|
---|
204 | while (length--) {
|
---|
205 | *out++ = convJP->unicodeToJisx0208(in->unicode());
|
---|
206 | ++in;
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 | bool QFontJis0208Codec::canEncode( QChar ch ) const
|
---|
212 | {
|
---|
213 | return ( convJP->unicodeToJisx0208(ch.unicode()) != 0 );
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 |
|
---|
218 |
|
---|
219 | #endif // QT_NO_BIG_CODECS
|
---|
220 | #endif // QT_NO_CODECS
|
---|