Eneboo - Documentación para desarrolladores
src/qt/include/private/qunicodetables_p.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qunicodetables_p.h   3.3.8   edited Jan 11 14:46 $
00003 **
00004 ** ???
00005 **
00006 ** Copyright (C) 2005-2007 Trolltech ASA.  All rights reserved.
00007 **
00008 ** This file is part of the widgets module of the Qt GUI Toolkit.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech ASA of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00020 ** licenses may use this file in accordance with the Qt Commercial License
00021 ** Agreement provided with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #ifndef QUNICODETABLES_P_H
00037 #define QUNICODETABLES_P_H
00038 
00039 //
00040 //  W A R N I N G
00041 //  -------------
00042 //
00043 // This file is not part of the Qt API.  It exists for the convenience
00044 // of internal files.  This header file may change from version to version
00045 // without notice, or even be removed.
00046 //
00047 // We mean it.
00048 //
00049 //
00050 
00051 #ifndef QT_H
00052 #include "qstring.h"
00053 #endif // QT_H
00054 
00055 #ifdef QT_NO_UNICODETABLES
00056 # include <ctype.h>
00057 #endif
00058 
00059 class QUnicodeTables {
00060 public:
00061     static const Q_UINT8 unicode_info[];
00062 #ifndef QT_NO_UNICODETABLES
00063     static const Q_UINT16 decomposition_map[];
00064     static const Q_UINT16 decomposition_info[];
00065     static const Q_UINT16 ligature_map[];
00066     static const Q_UINT16 ligature_info[];
00067     static const Q_UINT8 direction_info[];
00068     static const Q_UINT8 combining_info[];
00069     static const Q_UINT16 case_info[];
00070     static const Q_INT8 decimal_info[];
00071     static const Q_UINT16 symmetricPairs[];
00072     static const int symmetricPairsSize;
00073     static const Q_UINT8 line_break_info[];
00074 #else
00075     static const Q_UINT8 latin1_line_break_info[];
00076 #endif
00077     static const unsigned char otherScripts[];
00078     static const unsigned char indicScripts[];
00079     static const unsigned char scriptTable[];
00080     enum { SCRIPTS_INDIC = 0x7e };
00081 
00082     // see http://www.unicode.org/reports/tr14/tr14-13.html
00083     // we don't use the XX and AI properties and map them to AL instead.
00084     enum LineBreakClass {
00085         LineBreak_OP, LineBreak_CL, LineBreak_QU, LineBreak_GL, LineBreak_NS,
00086         LineBreak_EX, LineBreak_SY, LineBreak_IS, LineBreak_PR, LineBreak_PO,
00087         LineBreak_NU, LineBreak_AL, LineBreak_ID, LineBreak_IN, LineBreak_HY,
00088         LineBreak_BA, LineBreak_BB, LineBreak_B2, LineBreak_ZW, LineBreak_CM,
00089         LineBreak_SA, LineBreak_BK, LineBreak_CR, LineBreak_LF, LineBreak_SG,
00090         LineBreak_CB, LineBreak_SP
00091     };
00092 };
00093 
00094 
00095 inline QChar::Category category( const QChar &c )
00096 {
00097 #ifdef QT_NO_UNICODETABLES
00098     if ( c.unicode() > 0xff ) return QChar::Letter_Uppercase; //########
00099     return (QChar::Category)QUnicodeTables::unicode_info[c.unicode()];
00100 #else
00101     register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
00102     uc += c.cell();
00103     return (QChar::Category)QUnicodeTables::unicode_info[uc];
00104 #endif // QT_NO_UNICODETABLES
00105 }
00106 
00107 inline QChar lower( const QChar &c )
00108 {
00109 #ifndef QT_NO_UNICODETABLES
00110     int row = c.row();
00111     int cell = c.cell();
00112     register int ci = QUnicodeTables::case_info[row];
00113     register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
00114     uc += c.cell();
00115     if (QUnicodeTables::unicode_info[uc] != QChar::Letter_Uppercase || !ci)
00116         return c;
00117     Q_UINT16 lower = QUnicodeTables::case_info[(ci<<8)+cell];
00118     return lower ? QChar(lower) : c;
00119 #else
00120     if ( c.row() )
00121         return c;
00122     return QChar( tolower((uchar) c.latin1()) );
00123 #endif
00124 }
00125 
00126 inline QChar upper( const QChar &c )
00127 {
00128 #ifndef QT_NO_UNICODETABLES
00129     int row = c.row();
00130     int cell = c.cell();
00131     register int ci = QUnicodeTables::case_info[row];
00132     register int uc = ((int)QUnicodeTables::unicode_info[c.row()]) << 8;
00133     uc += c.cell();
00134     if (QUnicodeTables::unicode_info[uc] != QChar::Letter_Lowercase || !ci)
00135         return c;
00136     Q_UINT16 upper = QUnicodeTables::case_info[(ci<<8)+cell];
00137     return upper ? QChar(upper) : c;
00138 #else
00139     if ( c.row() )
00140         return c;
00141     return QChar( toupper((uchar) c.latin1()) );
00142 #endif
00143 }
00144 
00145 inline QChar::Direction direction( const QChar &c )
00146 {
00147 #ifndef QT_NO_UNICODETABLES
00148     register int pos = QUnicodeTables::direction_info[c.row()];
00149     return (QChar::Direction) (QUnicodeTables::direction_info[(pos<<8)+c.cell()] & 0x1f);
00150 #else
00151     Q_UNUSED(c);
00152     return QChar::DirL;
00153 #endif
00154 }
00155 
00156 inline bool mirrored( const QChar &c )
00157 {
00158 #ifndef QT_NO_UNICODETABLES
00159     register int pos = QUnicodeTables::direction_info[c.row()];
00160     return QUnicodeTables::direction_info[(pos<<8)+c.cell()] > 128;
00161 #else
00162     Q_UNUSED(c);
00163     return FALSE;
00164 #endif
00165 }
00166 
00167 
00168 inline QChar mirroredChar( const QChar &ch )
00169 {
00170 #ifndef QT_NO_UNICODETABLES
00171     if(!::mirrored( ch ))
00172         return ch;
00173 
00174     int i;
00175     int c = ch.unicode();
00176     for (i = 0; i < QUnicodeTables::symmetricPairsSize; i ++) {
00177         if (QUnicodeTables::symmetricPairs[i] == c)
00178             return QUnicodeTables::symmetricPairs[(i%2) ? (i-1) : (i+1)];
00179     }
00180 #endif
00181     return ch;
00182 }
00183 
00184 inline QChar::Joining joining( const QChar &ch )
00185 {
00186 #ifndef QT_NO_UNICODETABLES
00187     register int pos = QUnicodeTables::direction_info[ch.row()];
00188     return (QChar::Joining) ((QUnicodeTables::direction_info[(pos<<8)+ch.cell()] >> 5) &0x3);
00189 #else
00190     Q_UNUSED(ch);
00191     return QChar::OtherJoining;
00192 #endif
00193 }
00194 
00195 inline bool isMark( const QChar &ch )
00196 {
00197     QChar::Category c = ::category( ch );
00198     return c >= QChar::Mark_NonSpacing && c <= QChar::Mark_Enclosing;
00199 }
00200 
00201 inline unsigned char combiningClass( const QChar &ch )
00202 {
00203 #ifndef QT_NO_UNICODETABLES
00204     const int pos = QUnicodeTables::combining_info[ch.row()];
00205     return QUnicodeTables::combining_info[(pos<<8) + ch.cell()];
00206 #else
00207     Q_UNUSED(ch);
00208     return 0;
00209 #endif
00210 }
00211 
00212 inline bool isSpace( const QChar &ch )
00213 {
00214     if( ch.unicode() >= 9 && ch.unicode() <=13 ) return TRUE;
00215     QChar::Category c = ::category( ch );
00216     return c >= QChar::Separator_Space && c <= QChar::Separator_Paragraph;
00217 }
00218 
00219 inline int lineBreakClass( const QChar &ch )
00220 {
00221 #ifdef QT_NO_UNICODETABLES
00222     return ch.row() ? QUnicodeTables::LineBreak_AL
00223         : QUnicodeTables::latin1_line_break_info[ch.cell()];
00224 #else
00225     register int pos = ((int)QUnicodeTables::line_break_info[ch.row()] << 8) + ch.cell();
00226     return QUnicodeTables::line_break_info[pos];
00227 #endif
00228 }
00229 
00230 inline int scriptForChar( ushort uc )
00231 {
00232     unsigned char script = QUnicodeTables::scriptTable[(uc>>8)];
00233     if ( script >= QUnicodeTables::SCRIPTS_INDIC ) {
00234         if ( script == QUnicodeTables::SCRIPTS_INDIC ) {
00235             script = QUnicodeTables::indicScripts[ (uc-0x0900)>>7 ];
00236         } else {
00237             // 0x80 + SCRIPTS_xx
00238             unsigned char index = script-0x80;
00239             unsigned char cell = uc &0xff;
00240             while( QUnicodeTables::otherScripts[index++] < cell )
00241                 index++;
00242             script = QUnicodeTables::otherScripts[index];
00243         }
00244     }
00245     return script;
00246 }
00247 
00248 #ifdef Q_WS_X11
00249 #define SCRIPT_FOR_CHAR( script, c )    \
00250 do {                                            \
00251     unsigned short _uc = (c).unicode();                 \
00252     if ( _uc < 0x100 ) {                                \
00253         script = QFont::Latin;          \
00254     } else {                                    \
00255         script = (QFont::Script)scriptForChar( _uc );   \
00256     }                                           \
00257 } while( FALSE )
00258 #else
00259 #define SCRIPT_FOR_CHAR( script, c ) \
00260     script = (QFont::Script)scriptForChar( (c).unicode() )
00261 #endif
00262 
00263 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'