Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qtextengine_p.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** ??? 00005 ** 00006 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00007 ** 00008 ** This file is part of the kernel module of the Qt GUI Toolkit. 00009 ** 00010 ** This file may be distributed and/or modified under the terms of the 00011 ** GNU General Public License version 2 as published by the Free Software 00012 ** Foundation and appearing in the file LICENSE.GPL included in the 00013 ** packaging of this file. 00014 ** 00015 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00016 ** licenses for Qt/Embedded may use this file in accordance with the 00017 ** Qt Embedded Commercial License Agreement provided with the Software. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00023 ** information about Qt Commercial License Agreements. 00024 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00025 ** 00026 ** Contact info@trolltech.com if any conditions of this licensing are 00027 ** not clear to you. 00028 ** 00029 **********************************************************************/ 00030 00031 #ifndef QTEXTENGINE_P_H 00032 #define QTEXTENGINE_P_H 00033 00034 #ifndef QT_H 00035 #include "qglobal.h" 00036 #include "qstring.h" 00037 #include "qnamespace.h" 00038 #include <private/qfontdata_p.h> 00039 #endif // QT_H 00040 00041 #include <stdlib.h> 00042 #ifndef Q_OS_TEMP 00043 #include <assert.h> 00044 #endif // Q_OS_TEMP 00045 00046 class QFontPrivate; 00047 class QString; 00048 00049 class QOpenType; 00050 class QPainter; 00051 00052 // this uses the same coordinate system as Qt, but a different one to freetype and Xft. 00053 // * y is usually negative, and is equal to the ascent. 00054 // * negative yoff means the following stuff is drawn higher up. 00055 // the characters bounding rect is given by QRect( x,y,width,height), it's advance by 00056 // xoo and yoff 00057 struct glyph_metrics_t 00058 { 00059 inline glyph_metrics_t() { 00060 x = 100000; 00061 y = 100000; 00062 width = 0; 00063 height = 0; 00064 xoff = 0; 00065 yoff = 0; 00066 } 00067 inline glyph_metrics_t( int _x, int _y, int _width, int _height, int _xoff, int _yoff ) { 00068 x = _x; 00069 y = _y; 00070 width = _width; 00071 height = _height; 00072 xoff = _xoff; 00073 yoff = _yoff; 00074 } 00075 int x; 00076 int y; 00077 int width; 00078 int height; 00079 int xoff; 00080 int yoff; 00081 }; 00082 00083 #if defined( Q_WS_X11 ) || defined ( Q_WS_QWS ) 00084 typedef unsigned short glyph_t; 00085 00086 struct qoffset_t { 00087 short x; 00088 short y; 00089 }; 00090 00091 typedef int advance_t; 00092 00093 struct QScriptAnalysis 00094 { 00095 unsigned short script : 7; 00096 unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61) 00097 unsigned short override : 1; // Set when in LRO/RLO embedding 00098 unsigned short reserved : 2; 00099 bool operator == ( const QScriptAnalysis &other ) { 00100 return 00101 script == other.script && 00102 bidiLevel == other.bidiLevel; 00103 // ### 00104 // && override == other.override; 00105 } 00106 00107 }; 00108 00109 #elif defined( Q_WS_MAC ) 00110 00111 typedef unsigned short glyph_t; 00112 00113 struct qoffset_t { 00114 short x; 00115 short y; 00116 }; 00117 00118 typedef int advance_t; 00119 00120 struct QScriptAnalysis 00121 { 00122 unsigned short script : 7; 00123 unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61) 00124 unsigned short override : 1; // Set when in LRO/RLO embedding 00125 unsigned short reserved : 2; 00126 bool operator == ( const QScriptAnalysis &other ) { 00127 return 00128 script == other.script && 00129 bidiLevel == other.bidiLevel; 00130 // ### 00131 // && override == other.override; 00132 } 00133 00134 }; 00135 00136 #elif defined( Q_WS_WIN ) 00137 00138 // do not change the definitions below unless you know what you are doing! 00139 // it is designed to be compatible with the types found in uniscribe. 00140 00141 typedef unsigned short glyph_t; 00142 00143 struct qoffset_t { 00144 int x; 00145 int y; 00146 }; 00147 00148 typedef int advance_t; 00149 00150 struct QScriptAnalysis { 00151 unsigned short script :10; 00152 unsigned short rtl :1; 00153 unsigned short layoutRTL :1; 00154 unsigned short linkBefore :1; 00155 unsigned short linkAfter :1; 00156 unsigned short logicalOrder :1; 00157 unsigned short noGlyphIndex :1; 00158 unsigned short bidiLevel :5; 00159 unsigned short override :1; 00160 unsigned short inhibitSymSwap :1; 00161 unsigned short charShape :1; 00162 unsigned short digitSubstitute :1; 00163 unsigned short inhibitLigate :1; 00164 unsigned short fDisplayZWG :1; 00165 unsigned short arabicNumContext :1; 00166 unsigned short gcpClusters :1; 00167 unsigned short reserved :1; 00168 unsigned short engineReserved :2; 00169 }; 00170 00171 inline bool operator == ( const QScriptAnalysis &sa1, const QScriptAnalysis &sa2 ) 00172 { 00173 return 00174 sa1.script == sa2.script && 00175 sa1.bidiLevel == sa2.bidiLevel; 00176 // ### 00177 // && override == other.override; 00178 } 00179 00180 #endif 00181 00182 // enum and struct are made to be compatible with Uniscribe, dont change unless you know what you're doing. 00183 struct GlyphAttributes { 00184 // highest value means highest priority for justification. Justification is done by first inserting kashidas 00185 // starting with the highest priority positions, then stretching spaces, afterwards extending inter char 00186 // spacing, and last spacing between arabic words. 00187 // NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics. 00188 enum Justification { 00189 NoJustification= 0, // Justification can't be applied after this glyph 00190 Arabic_Space = 1, // This glyph represents a space inside arabic text 00191 Character = 2, // Inter-character justification point follows this glyph 00192 Space = 4, // This glyph represents a blank outside an Arabic run 00193 Arabic_Normal = 7, // Normal Middle-Of-Word glyph that connects to the right (begin) 00194 Arabic_Waw = 8, // Next character is final form of Waw/Ain/Qaf/Fa 00195 Arabic_BaRa = 9, // Next two chars are Ba + Ra/Ya/AlefMaksura 00196 Arabic_Alef = 10, // Next character is final form of Alef/Tah/Lam/Kaf/Gaf 00197 Arabic_HaaDal = 11, // Next character is final form of Haa/Dal/Taa Marbutah 00198 Arabic_Seen = 12, // Initial or Medial form Of Seen/Sad 00199 Arabic_Kashida = 13 // Kashida(U+640) in middle of word 00200 }; 00201 unsigned short justification :4; // Justification class 00202 unsigned short clusterStart :1; // First glyph of representation of cluster 00203 unsigned short mark :1; // needs to be positioned around base char 00204 unsigned short zeroWidth :1; // ZWJ, ZWNJ etc, with no width, currently used as "Don't print" for ZWSP 00205 unsigned short reserved :1; 00206 unsigned short combiningClass :8; 00207 }; 00208 00209 // also this is compatible to uniscribe. Do not change. 00210 struct QCharAttributes { 00211 uchar softBreak :1; // Potential linebreak point _before_ this character 00212 uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP 00213 uchar charStop :1; // Valid cursor position (for left/right arrow) 00214 uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow) 00215 uchar invalid :1; 00216 uchar reserved :3; 00217 }; 00218 00219 inline bool qIsZeroWidthChar(ushort uc) 00220 { 00221 return (uc >= 0x200b && uc <= 0x200f /* ZW Space, ZWNJ, ZWJ, LRM and RLM */) 00222 || (uc >= 0x2028 && uc <= 0x202f /* LS, PS, LRE, RLE, PDF, LRO, RLO, NNBSP */) 00223 || (uc >= 0x206a && uc <= 0x206f /* ISS, ASS, IAFS, AFS, NADS, NODS */); 00224 } 00225 00226 class QFontEngine; 00227 00228 struct QScriptItem 00229 { 00230 inline QScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ), 00231 isObject( FALSE ), hasPositioning( FALSE ), 00232 descent( -1 ), ascent( -1 ), width( -1 ), 00233 x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ), 00234 fontEngine( 0 ) { } 00235 int position; 00236 QScriptAnalysis analysis; 00237 unsigned short isSpace : 1; 00238 unsigned short isTab : 1; 00239 unsigned short isObject : 1; 00240 unsigned short hasPositioning : 1; 00241 unsigned short complex : 1; // Windows only 00242 unsigned short private_use : 1; // Windows only 00243 unsigned short reserved : 10; 00244 short descent; 00245 int ascent; 00246 int width; 00247 int x; 00248 int y; 00249 int num_glyphs; 00250 int glyph_data_offset; 00251 QFontEngine *fontEngine; 00252 }; 00253 00254 struct QScriptItemArrayPrivate 00255 { 00256 unsigned int alloc; 00257 unsigned int size; 00258 QScriptItem items[1]; 00259 }; 00260 00261 class QScriptItemArray 00262 { 00263 public: 00264 QScriptItemArray() : d( 0 ) {} 00265 ~QScriptItemArray(); 00266 00267 inline QScriptItem &operator[] (int i) const {return d->items[i]; } 00268 inline void append( const QScriptItem &item ) { 00269 if ( d->size == d->alloc ) 00270 resize( d->size + 1 ); 00271 d->items[d->size] = item; 00272 d->size++; 00273 } 00274 inline int size() const { return d ? d->size : 0; } 00275 00276 void resize( int s ); 00277 void clear(); 00278 00279 QScriptItemArrayPrivate *d; 00280 private: 00281 #ifdef Q_DISABLE_COPY 00282 QScriptItemArray( const QScriptItemArray & ); 00283 QScriptItemArray &operator = ( const QScriptItemArray & ); 00284 #endif 00285 }; 00286 00287 class QFontPrivate; 00288 00289 class Q_EXPORT QTextEngine { 00290 public: 00291 QTextEngine( const QString &str, QFontPrivate *f ); 00292 ~QTextEngine(); 00293 00294 enum Mode { 00295 Full = 0x00, 00296 NoBidi = 0x01, 00297 SingleLine = 0x02, 00298 WidthOnly = 0x07 00299 }; 00300 00301 void itemize( int mode = Full ); 00302 00303 static void bidiReorder( int numRuns, const Q_UINT8 *levels, int *visualOrder ); 00304 00305 const QCharAttributes *attributes(); 00306 void shape( int item ) const; 00307 00308 // ### we need something for justification 00309 00310 enum Edge { 00311 Leading, 00312 Trailing 00313 }; 00314 enum ShaperFlag { 00315 RightToLeft = 0x0001, 00316 Mirrored = 0x0001 00317 }; 00318 00319 int width( int charFrom, int numChars ) const; 00320 glyph_metrics_t boundingBox( int from, int len ) const; 00321 00322 QScriptItemArray items; 00323 QString string; 00324 QFontPrivate *fnt; 00325 int lineWidth; 00326 int widthUsed; 00327 int firstItemInLine; 00328 int currentItem; 00329 QChar::Direction direction : 5; 00330 unsigned int haveCharAttributes : 1; 00331 unsigned int widthOnly : 1; 00332 unsigned int reserved : 25; 00333 00334 int length( int item ) const { 00335 const QScriptItem &si = items[item]; 00336 int from = si.position; 00337 item++; 00338 return ( item < items.size() ? items[item].position : string.length() ) - from; 00339 } 00340 void splitItem( int item, int pos ); 00341 00342 unsigned short *logClustersPtr; 00343 glyph_t *glyphPtr; 00344 advance_t *advancePtr; 00345 qoffset_t *offsetsPtr; 00346 GlyphAttributes *glyphAttributesPtr; 00347 00348 inline unsigned short *logClusters( const QScriptItem *si ) const 00349 { return logClustersPtr+si->position; } 00350 inline glyph_t *glyphs( const QScriptItem *si ) const 00351 { return glyphPtr+si->glyph_data_offset; } 00352 inline advance_t *advances( const QScriptItem *si ) const 00353 { return advancePtr+si->glyph_data_offset; } 00354 inline qoffset_t *offsets( const QScriptItem *si ) const 00355 { return offsetsPtr+si->glyph_data_offset; } 00356 inline GlyphAttributes *glyphAttributes( const QScriptItem *si ) const 00357 { return glyphAttributesPtr+si->glyph_data_offset; } 00358 00359 void reallocate( int totalGlyphs ); 00360 inline void ensureSpace( int nGlyphs ) const { 00361 if ( num_glyphs - used < nGlyphs ) 00362 ((QTextEngine *)this)->reallocate( ( (used + nGlyphs + 16) >> 4 ) << 4 ); 00363 } 00364 00365 int allocated; 00366 void **memory; 00367 int num_glyphs; 00368 int used; 00369 }; 00370 00371 #endif