summaryrefslogtreecommitdiff
path: root/qmake/include/qunicodetables_p.h
Unidiff
Diffstat (limited to 'qmake/include/qunicodetables_p.h') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/include/qunicodetables_p.h263
1 files changed, 263 insertions, 0 deletions
diff --git a/qmake/include/qunicodetables_p.h b/qmake/include/qunicodetables_p.h
new file mode 100644
index 0000000..0e799e4
--- a/dev/null
+++ b/qmake/include/qunicodetables_p.h
@@ -0,0 +1,263 @@
1/****************************************************************************
2**
3**
4** ???
5**
6** Copyright (C) 2003 Trolltech AS. All rights reserved.
7**
8** This file is part of the widgets module of the Qt GUI Toolkit.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
20** licenses may use this file in accordance with the Qt Commercial License
21** Agreement provided with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#ifndef QUNICODETABLES_P_H
37#define QUNICODETABLES_P_H
38
39//
40// W A R N I N G
41// -------------
42//
43// This file is not part of the Qt API. It exists for the convenience
44// of internal files. This header file may change from version to version
45// without notice, or even be removed.
46//
47// We mean it.
48//
49//
50
51#ifndef QT_H
52#include "qstring.h"
53#endif // QT_H
54
55#ifdef QT_NO_UNICODETABLES
56# include <ctype.h>
57#endif
58
59class QUnicodeTables {
60public:
61 static const Q_UINT8 unicode_info[];
62#ifndef QT_NO_UNICODETABLES
63 static const Q_UINT16 decomposition_map[];
64 static const Q_UINT16 decomposition_info[];
65 static const Q_UINT16 ligature_map[];
66 static const Q_UINT16 ligature_info[];
67 static const Q_UINT8 direction_info[];
68 static const Q_UINT8 combining_info[];
69 static const Q_UINT16 case_info[];
70 static const Q_INT8 decimal_info[];
71 static const Q_UINT16 symmetricPairs[];
72 static const int symmetricPairsSize;
73 static const Q_UINT8 line_break_info[];
74#else
75 static const Q_UINT8 latin1_line_break_info[];
76#endif
77 static const unsigned char otherScripts[];
78 static const unsigned char indicScripts[];
79 static const unsigned char scriptTable[];
80 enum { SCRIPTS_INDIC = 0x7e };
81
82 // see http://www.unicode.org/reports/tr14/tr14-13.html
83 // we don't use the XX and AI properties and map them to AL instead.
84 enum LineBreakClass {
85 LineBreak_OP, LineBreak_CL, LineBreak_QU, LineBreak_GL, LineBreak_NS,
86 LineBreak_EX, LineBreak_SY, LineBreak_IS, LineBreak_PR, LineBreak_PO,
87 LineBreak_NU, LineBreak_AL, LineBreak_ID, LineBreak_IN, LineBreak_HY,
88 LineBreak_BA, LineBreak_BB, LineBreak_B2, LineBreak_ZW, LineBreak_CM,
89 LineBreak_SA, LineBreak_BK, LineBreak_CR, LineBreak_LF, LineBreak_SG,
90 LineBreak_CB, LineBreak_SP
91 };
92};
93
94
95inline QChar::Category category( const QChar &c )
96{
97#ifdef QT_NO_UNICODETABLES
98 if ( c.unicode() > 0xff ) return QChar::Letter_Uppercase; //########
99 return (QChar::Category)QUnicodeTables::unicode_info[c.unicode()];
100#else
101 register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
102 uc += c.cell();
103 return (QChar::Category)QUnicodeTables::unicode_info[uc];
104#endif // QT_NO_UNICODETABLES
105}
106
107inline QChar lower( const QChar &c )
108{
109#ifndef QT_NO_UNICODETABLES
110 int row = c.row();
111 int cell = c.cell();
112 register int ci = QUnicodeTables::case_info[row];
113 register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
114 uc += c.cell();
115 if (QUnicodeTables::unicode_info[uc] != QChar::Letter_Uppercase || !ci)
116 return c;
117 Q_UINT16 lower = QUnicodeTables::case_info[(ci<<8)+cell];
118 return lower ? QChar(lower) : c;
119#else
120 if ( c.row() )
121 return c;
122 return QChar( tolower((uchar) c.latin1()) );
123#endif
124}
125
126inline QChar upper( const QChar &c )
127{
128#ifndef QT_NO_UNICODETABLES
129 int row = c.row();
130 int cell = c.cell();
131 register int ci = QUnicodeTables::case_info[row];
132 register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
133 uc += c.cell();
134 if (QUnicodeTables::unicode_info[uc] != QChar::Letter_Lowercase || !ci)
135 return c;
136 Q_UINT16 upper = QUnicodeTables::case_info[(ci<<8)+cell];
137 return upper ? QChar(upper) : c;
138#else
139 if ( c.row() )
140 return c;
141 return QChar( toupper((uchar) c.latin1()) );
142#endif
143}
144
145inline QChar::Direction direction( const QChar &c )
146{
147#ifndef QT_NO_UNICODETABLES
148 register int pos = QUnicodeTables::direction_info[c.row()];
149 return (QChar::Direction) (QUnicodeTables::direction_info[(pos<<8)+c.cell()] & 0x1f);
150#else
151 Q_UNUSED(c);
152 return QChar::DirL;
153#endif
154}
155
156inline bool mirrored( const QChar &c )
157{
158#ifndef QT_NO_UNICODETABLES
159 register int pos = QUnicodeTables::direction_info[c.row()];
160 return QUnicodeTables::direction_info[(pos<<8)+c.cell()] > 128;
161#else
162 Q_UNUSED(c);
163 return FALSE;
164#endif
165}
166
167
168inline QChar mirroredChar( const QChar &ch )
169{
170#ifndef QT_NO_UNICODETABLES
171 if(!::mirrored( ch ))
172 return ch;
173
174 int i;
175 int c = ch.unicode();
176 for (i = 0; i < QUnicodeTables::symmetricPairsSize; i ++) {
177 if (QUnicodeTables::symmetricPairs[i] == c)
178 return QUnicodeTables::symmetricPairs[(i%2) ? (i-1) : (i+1)];
179 }
180#endif
181 return ch;
182}
183
184inline QChar::Joining joining( const QChar &ch )
185{
186#ifndef QT_NO_UNICODETABLES
187 register int pos = QUnicodeTables::direction_info[ch.row()];
188 return (QChar::Joining) ((QUnicodeTables::direction_info[(pos<<8)+ch.cell()] >> 5) &0x3);
189#else
190 Q_UNUSED(ch);
191 return QChar::OtherJoining;
192#endif
193}
194
195inline bool isMark( const QChar &ch )
196{
197 QChar::Category c = ::category( ch );
198 return c >= QChar::Mark_NonSpacing && c <= QChar::Mark_Enclosing;
199}
200
201inline unsigned char combiningClass( const QChar &ch )
202{
203#ifndef QT_NO_UNICODETABLES
204 const int pos = QUnicodeTables::combining_info[ch.row()];
205 return QUnicodeTables::combining_info[(pos<<8) + ch.cell()];
206#else
207 Q_UNUSED(ch);
208 return 0;
209#endif
210}
211
212inline bool isSpace( const QChar &ch )
213{
214 if( ch.unicode() >= 9 && ch.unicode() <=13 ) return TRUE;
215 QChar::Category c = ::category( ch );
216 return c >= QChar::Separator_Space && c <= QChar::Separator_Paragraph;
217}
218
219inline int lineBreakClass( const QChar &ch )
220{
221#ifdef QT_NO_UNICODETABLES
222 return ch.row() ? QUnicodeTables::LineBreak_AL
223 : QUnicodeTables::latin1_line_break_info[ch.cell()];
224#else
225 register int pos = ((int)QUnicodeTables::line_break_info[ch.row()] << 8) + ch.cell();
226 return QUnicodeTables::line_break_info[pos];
227#endif
228}
229
230inline int scriptForChar( ushort uc )
231{
232 unsigned char script = QUnicodeTables::scriptTable[(uc>>8)];
233 if ( script >= QUnicodeTables::SCRIPTS_INDIC ) {
234 if ( script == QUnicodeTables::SCRIPTS_INDIC ) {
235 script = QUnicodeTables::indicScripts[ (uc-0x0900)>>7 ];
236 } else {
237 // 0x80 + SCRIPTS_xx
238 unsigned char index = script-0x80;
239 unsigned char cell = uc &0xff;
240 while( QUnicodeTables::otherScripts[index++] < cell )
241 index++;
242 script = QUnicodeTables::otherScripts[index];
243 }
244 }
245 return script;
246}
247
248#ifdef Q_WS_X11
249 #define SCRIPT_FOR_CHAR( script, c ) \
250 do { \
251 unsigned short _uc = (c).unicode(); \
252 if ( _uc < 0x100 ) { \
253 script = QFont::Latin; \
254 } else { \
255 script = (QFont::Script)scriptForChar( _uc ); \
256 } \
257} while( FALSE )
258#else
259#define SCRIPT_FOR_CHAR( script, c ) \
260 script = (QFont::Script)scriptForChar( (c).unicode() )
261#endif
262
263#endif