[2] | 1 | /****************************************************************************
|
---|
| 2 | ** $Id: qtextengine_p.h 169 2007-03-31 16:22:28Z dmik $
|
---|
| 3 | **
|
---|
| 4 | ** ???
|
---|
| 5 | **
|
---|
| 6 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
| 7 | **
|
---|
| 8 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
---|
| 9 | **
|
---|
| 10 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 11 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 12 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 13 | ** packaging of this file.
|
---|
| 14 | **
|
---|
| 15 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 16 | ** licenses for Qt/Embedded may use this file in accordance with the
|
---|
| 17 | ** Qt Embedded Commercial License Agreement provided with the Software.
|
---|
| 18 | **
|
---|
| 19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 21 | **
|
---|
| 22 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 23 | ** information about Qt Commercial License Agreements.
|
---|
| 24 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 25 | **
|
---|
| 26 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 27 | ** not clear to you.
|
---|
| 28 | **
|
---|
| 29 | **********************************************************************/
|
---|
| 30 |
|
---|
| 31 | #ifndef QTEXTENGINE_P_H
|
---|
| 32 | #define QTEXTENGINE_P_H
|
---|
| 33 |
|
---|
| 34 | #ifndef QT_H
|
---|
| 35 | #include "qglobal.h"
|
---|
| 36 | #include "qstring.h"
|
---|
| 37 | #include "qnamespace.h"
|
---|
| 38 | #include <private/qfontdata_p.h>
|
---|
| 39 | #endif // QT_H
|
---|
| 40 |
|
---|
| 41 | #include <stdlib.h>
|
---|
| 42 | #ifndef Q_OS_TEMP
|
---|
| 43 | #include <assert.h>
|
---|
| 44 | #endif // Q_OS_TEMP
|
---|
| 45 |
|
---|
| 46 | class QFontPrivate;
|
---|
| 47 | class QString;
|
---|
| 48 |
|
---|
| 49 | class QOpenType;
|
---|
| 50 | class QPainter;
|
---|
| 51 |
|
---|
| 52 | // this uses the same coordinate system as Qt, but a different one to freetype and Xft.
|
---|
| 53 | // * y is usually negative, and is equal to the ascent.
|
---|
| 54 | // * negative yoff means the following stuff is drawn higher up.
|
---|
| 55 | // the characters bounding rect is given by QRect( x,y,width,height), it's advance by
|
---|
| 56 | // xoo and yoff
|
---|
| 57 | struct glyph_metrics_t
|
---|
| 58 | {
|
---|
| 59 | inline glyph_metrics_t() {
|
---|
| 60 | x = 100000;
|
---|
| 61 | y = 100000;
|
---|
| 62 | width = 0;
|
---|
| 63 | height = 0;
|
---|
| 64 | xoff = 0;
|
---|
| 65 | yoff = 0;
|
---|
| 66 | }
|
---|
| 67 | inline glyph_metrics_t( int _x, int _y, int _width, int _height, int _xoff, int _yoff ) {
|
---|
| 68 | x = _x;
|
---|
| 69 | y = _y;
|
---|
| 70 | width = _width;
|
---|
| 71 | height = _height;
|
---|
| 72 | xoff = _xoff;
|
---|
| 73 | yoff = _yoff;
|
---|
| 74 | }
|
---|
| 75 | int x;
|
---|
| 76 | int y;
|
---|
| 77 | int width;
|
---|
| 78 | int height;
|
---|
| 79 | int xoff;
|
---|
| 80 | int yoff;
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | #if defined( Q_WS_X11 ) || defined ( Q_WS_QWS )
|
---|
| 84 | typedef unsigned short glyph_t;
|
---|
| 85 |
|
---|
| 86 | struct qoffset_t {
|
---|
| 87 | short x;
|
---|
| 88 | short y;
|
---|
| 89 | };
|
---|
| 90 |
|
---|
| 91 | typedef int advance_t;
|
---|
| 92 |
|
---|
| 93 | struct QScriptAnalysis
|
---|
| 94 | {
|
---|
| 95 | unsigned short script : 7;
|
---|
| 96 | unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61)
|
---|
| 97 | unsigned short override : 1; // Set when in LRO/RLO embedding
|
---|
| 98 | unsigned short reserved : 2;
|
---|
| 99 | bool operator == ( const QScriptAnalysis &other ) {
|
---|
| 100 | return
|
---|
| 101 | script == other.script &&
|
---|
| 102 | bidiLevel == other.bidiLevel;
|
---|
| 103 | // ###
|
---|
| 104 | // && override == other.override;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | #elif defined( Q_WS_MAC )
|
---|
| 110 |
|
---|
| 111 | typedef unsigned short glyph_t;
|
---|
| 112 |
|
---|
| 113 | struct qoffset_t {
|
---|
| 114 | short x;
|
---|
| 115 | short y;
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 | typedef int advance_t;
|
---|
| 119 |
|
---|
| 120 | struct QScriptAnalysis
|
---|
| 121 | {
|
---|
| 122 | unsigned short script : 7;
|
---|
| 123 | unsigned short bidiLevel : 6; // Unicode Bidi algorithm embedding level (0-61)
|
---|
| 124 | unsigned short override : 1; // Set when in LRO/RLO embedding
|
---|
| 125 | unsigned short reserved : 2;
|
---|
| 126 | bool operator == ( const QScriptAnalysis &other ) {
|
---|
| 127 | return
|
---|
| 128 | script == other.script &&
|
---|
| 129 | bidiLevel == other.bidiLevel;
|
---|
| 130 | // ###
|
---|
| 131 | // && override == other.override;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | };
|
---|
| 135 |
|
---|
| 136 | #elif defined( Q_WS_WIN )
|
---|
| 137 |
|
---|
| 138 | // do not change the definitions below unless you know what you are doing!
|
---|
| 139 | // it is designed to be compatible with the types found in uniscribe.
|
---|
| 140 |
|
---|
| 141 | typedef unsigned short glyph_t;
|
---|
| 142 |
|
---|
| 143 | struct qoffset_t {
|
---|
| 144 | int x;
|
---|
| 145 | int y;
|
---|
| 146 | };
|
---|
| 147 |
|
---|
| 148 | typedef int advance_t;
|
---|
| 149 |
|
---|
| 150 | struct QScriptAnalysis {
|
---|
| 151 | unsigned short script :10;
|
---|
| 152 | unsigned short rtl :1;
|
---|
| 153 | unsigned short layoutRTL :1;
|
---|
| 154 | unsigned short linkBefore :1;
|
---|
| 155 | unsigned short linkAfter :1;
|
---|
| 156 | unsigned short logicalOrder :1;
|
---|
| 157 | unsigned short noGlyphIndex :1;
|
---|
| 158 | unsigned short bidiLevel :5;
|
---|
| 159 | unsigned short override :1;
|
---|
| 160 | unsigned short inhibitSymSwap :1;
|
---|
| 161 | unsigned short charShape :1;
|
---|
| 162 | unsigned short digitSubstitute :1;
|
---|
| 163 | unsigned short inhibitLigate :1;
|
---|
| 164 | unsigned short fDisplayZWG :1;
|
---|
| 165 | unsigned short arabicNumContext :1;
|
---|
| 166 | unsigned short gcpClusters :1;
|
---|
| 167 | unsigned short reserved :1;
|
---|
| 168 | unsigned short engineReserved :2;
|
---|
| 169 | };
|
---|
| 170 |
|
---|
| 171 | inline bool operator == ( const QScriptAnalysis &sa1, const QScriptAnalysis &sa2 )
|
---|
| 172 | {
|
---|
| 173 | return
|
---|
| 174 | sa1.script == sa2.script &&
|
---|
| 175 | sa1.bidiLevel == sa2.bidiLevel;
|
---|
| 176 | // ###
|
---|
| 177 | // && override == other.override;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[8] | 180 | #elif defined( Q_WS_PM )
|
---|
| 181 |
|
---|
[169] | 182 | /// @todo (r=dmik) the definitions below is almost unchecked (no true unicode
|
---|
[8] | 183 | // support yet)
|
---|
| 184 |
|
---|
[169] | 185 | // Use wide char to contain DBCS char in one glyph
|
---|
| 186 | typedef unsigned short glyph_t;
|
---|
[8] | 187 |
|
---|
| 188 | struct qoffset_t {
|
---|
| 189 | int x;
|
---|
| 190 | int y;
|
---|
| 191 | };
|
---|
| 192 |
|
---|
| 193 | typedef int advance_t;
|
---|
| 194 |
|
---|
[169] | 195 | /// @todo (r=dmik) it's a dummy version...
|
---|
[8] | 196 | struct QScriptAnalysis {
|
---|
| 197 | unsigned short script :10;
|
---|
| 198 | unsigned short bidiLevel :5;
|
---|
| 199 | unsigned short override :1;
|
---|
| 200 | unsigned short reserved :1;
|
---|
| 201 | };
|
---|
| 202 |
|
---|
| 203 | inline bool operator == ( const QScriptAnalysis &sa1, const QScriptAnalysis &sa2 )
|
---|
| 204 | {
|
---|
| 205 | return
|
---|
| 206 | sa1.script == sa2.script &&
|
---|
| 207 | sa1.bidiLevel == sa2.bidiLevel;
|
---|
| 208 | // ###
|
---|
| 209 | // && override == other.override;
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[2] | 212 | #endif
|
---|
| 213 |
|
---|
| 214 | // enum and struct are made to be compatible with Uniscribe, dont change unless you know what you're doing.
|
---|
| 215 | struct GlyphAttributes {
|
---|
| 216 | // highest value means highest priority for justification. Justification is done by first inserting kashidas
|
---|
| 217 | // starting with the highest priority positions, then stretching spaces, afterwards extending inter char
|
---|
| 218 | // spacing, and last spacing between arabic words.
|
---|
| 219 | // NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics.
|
---|
| 220 | enum Justification {
|
---|
| 221 | NoJustification= 0, // Justification can't be applied at this glyph
|
---|
| 222 | Arabic_Space = 1, // This glyph represents a space in an Arabic item
|
---|
| 223 | Character = 2, // Inter-character justification point follows this glyph
|
---|
| 224 | Space = 4, // This glyph represents a blank outside an Arabic run
|
---|
| 225 | Arabic_Normal = 7, // Normal Middle-Of-Word glyph that connects to the right (begin)
|
---|
| 226 | Arabic_Kashida = 8, // Kashida(U+640) in middle of word
|
---|
| 227 | Arabic_Alef = 9, // Final form of Alef-like (U+627, U+625, U+623, U+632)
|
---|
| 228 | Arabic_Ha = 10, // Final Form Of Ha (U+647)
|
---|
| 229 | Arabic_Ra = 11, // Final Form Of Ra (U+631)
|
---|
| 230 | Arabic_Ba = 12, // Middle-Of-Word Form Of Ba (U+628)
|
---|
| 231 | Arabic_Bara = 13, // Ligature Of Alike (U+628,U+631)
|
---|
| 232 | Arabic_Seen = 14 // Highest Priority: Initial Shape Of Seen(U+633) (End)
|
---|
| 233 | };
|
---|
| 234 | unsigned short justification :4; // Justification class
|
---|
| 235 | unsigned short clusterStart :1; // First glyph of representation of cluster
|
---|
| 236 | unsigned short mark :1; // needs to be positioned around base char
|
---|
| 237 | unsigned short zeroWidth :1; // ZWJ, ZWNJ etc, with no width
|
---|
| 238 | unsigned short reserved :1;
|
---|
| 239 | unsigned short combiningClass :8;
|
---|
| 240 | };
|
---|
| 241 |
|
---|
| 242 | // also this is compatible to uniscribe. Do not change.
|
---|
| 243 | struct QCharAttributes {
|
---|
| 244 | uchar softBreak :1; // Potential linebreak point _before_ this character
|
---|
| 245 | uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP
|
---|
| 246 | uchar charStop :1; // Valid cursor position (for left/right arrow)
|
---|
| 247 | uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow)
|
---|
| 248 | uchar invalid :1;
|
---|
| 249 | uchar reserved :3;
|
---|
| 250 | };
|
---|
| 251 |
|
---|
| 252 | class QFontEngine;
|
---|
| 253 |
|
---|
| 254 | struct QScriptItem
|
---|
| 255 | {
|
---|
| 256 | inline QScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ),
|
---|
| 257 | isObject( FALSE ), hasPositioning( FALSE ),
|
---|
| 258 | descent( -1 ), ascent( -1 ), width( -1 ),
|
---|
| 259 | x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ),
|
---|
| 260 | fontEngine( 0 ) { }
|
---|
| 261 | int position;
|
---|
| 262 | QScriptAnalysis analysis;
|
---|
| 263 | unsigned short isSpace : 1;
|
---|
| 264 | unsigned short isTab : 1;
|
---|
| 265 | unsigned short isObject : 1;
|
---|
| 266 | unsigned short hasPositioning : 1;
|
---|
| 267 | unsigned short reserved : 12;
|
---|
| 268 | short descent;
|
---|
| 269 | int ascent;
|
---|
| 270 | int width;
|
---|
| 271 | int x;
|
---|
| 272 | int y;
|
---|
| 273 | int num_glyphs;
|
---|
| 274 | int glyph_data_offset;
|
---|
| 275 | QFontEngine *fontEngine;
|
---|
| 276 | };
|
---|
| 277 |
|
---|
| 278 | struct QScriptItemArrayPrivate
|
---|
| 279 | {
|
---|
| 280 | unsigned int alloc;
|
---|
| 281 | unsigned int size;
|
---|
| 282 | QScriptItem items[1];
|
---|
| 283 | };
|
---|
| 284 |
|
---|
| 285 | class QScriptItemArray
|
---|
| 286 | {
|
---|
| 287 | public:
|
---|
| 288 | QScriptItemArray() : d( 0 ) {}
|
---|
| 289 | ~QScriptItemArray();
|
---|
| 290 |
|
---|
| 291 | inline QScriptItem &operator[] (int i) const {return d->items[i]; }
|
---|
| 292 | inline void append( const QScriptItem &item ) {
|
---|
| 293 | if ( d->size == d->alloc )
|
---|
| 294 | resize( d->size + 1 );
|
---|
| 295 | d->items[d->size] = item;
|
---|
| 296 | d->size++;
|
---|
| 297 | }
|
---|
| 298 | inline int size() const { return d ? d->size : 0; }
|
---|
| 299 |
|
---|
| 300 | void resize( int s );
|
---|
| 301 | void clear();
|
---|
| 302 |
|
---|
| 303 | QScriptItemArrayPrivate *d;
|
---|
| 304 | private:
|
---|
| 305 | #ifdef Q_DISABLE_COPY
|
---|
| 306 | QScriptItemArray( const QScriptItemArray & );
|
---|
| 307 | QScriptItemArray &operator = ( const QScriptItemArray & );
|
---|
| 308 | #endif
|
---|
| 309 | };
|
---|
| 310 |
|
---|
| 311 | class QFontPrivate;
|
---|
| 312 |
|
---|
| 313 | class QTextEngine {
|
---|
| 314 | public:
|
---|
| 315 | QTextEngine( const QString &str, QFontPrivate *f );
|
---|
| 316 | ~QTextEngine();
|
---|
| 317 |
|
---|
| 318 | enum Mode {
|
---|
| 319 | Full = 0x00,
|
---|
| 320 | NoBidi = 0x01,
|
---|
| 321 | SingleLine = 0x02,
|
---|
| 322 | WidthOnly = 0x07
|
---|
| 323 | };
|
---|
| 324 |
|
---|
| 325 | void itemize( int mode = Full );
|
---|
| 326 |
|
---|
| 327 | static void bidiReorder( int numRuns, const Q_UINT8 *levels, int *visualOrder );
|
---|
| 328 |
|
---|
| 329 | const QCharAttributes *attributes();
|
---|
| 330 | void shape( int item ) const;
|
---|
| 331 |
|
---|
| 332 | // ### we need something for justification
|
---|
| 333 |
|
---|
| 334 | enum Edge {
|
---|
| 335 | Leading,
|
---|
| 336 | Trailing
|
---|
| 337 | };
|
---|
| 338 |
|
---|
| 339 | int width( int charFrom, int numChars ) const;
|
---|
| 340 | glyph_metrics_t boundingBox( int from, int len ) const;
|
---|
| 341 |
|
---|
| 342 | QScriptItemArray items;
|
---|
| 343 | QString string;
|
---|
| 344 | QFontPrivate *fnt;
|
---|
| 345 | int lineWidth;
|
---|
| 346 | int widthUsed;
|
---|
| 347 | int firstItemInLine;
|
---|
| 348 | int currentItem;
|
---|
| 349 | QChar::Direction direction : 5;
|
---|
| 350 | unsigned int haveCharAttributes : 1;
|
---|
| 351 | unsigned int widthOnly : 1;
|
---|
| 352 | unsigned int reserved : 25;
|
---|
| 353 |
|
---|
| 354 | int length( int item ) const {
|
---|
| 355 | const QScriptItem &si = items[item];
|
---|
| 356 | int from = si.position;
|
---|
| 357 | item++;
|
---|
| 358 | return ( item < items.size() ? items[item].position : string.length() ) - from;
|
---|
| 359 | }
|
---|
| 360 | void splitItem( int item, int pos );
|
---|
| 361 |
|
---|
| 362 | unsigned short *logClustersPtr;
|
---|
| 363 | glyph_t *glyphPtr;
|
---|
| 364 | advance_t *advancePtr;
|
---|
| 365 | qoffset_t *offsetsPtr;
|
---|
| 366 | GlyphAttributes *glyphAttributesPtr;
|
---|
| 367 |
|
---|
| 368 | inline unsigned short *logClusters( const QScriptItem *si ) const
|
---|
| 369 | { return logClustersPtr+si->position; }
|
---|
| 370 | inline glyph_t *glyphs( const QScriptItem *si ) const
|
---|
| 371 | { return glyphPtr+si->glyph_data_offset; }
|
---|
| 372 | inline advance_t *advances( const QScriptItem *si ) const
|
---|
| 373 | { return advancePtr+si->glyph_data_offset; }
|
---|
| 374 | inline qoffset_t *offsets( const QScriptItem *si ) const
|
---|
| 375 | { return offsetsPtr+si->glyph_data_offset; }
|
---|
| 376 | inline GlyphAttributes *glyphAttributes( const QScriptItem *si ) const
|
---|
| 377 | { return glyphAttributesPtr+si->glyph_data_offset; }
|
---|
| 378 |
|
---|
| 379 | void reallocate( int totalGlyphs );
|
---|
| 380 | inline void ensureSpace( int nGlyphs ) const {
|
---|
| 381 | if ( num_glyphs - used < nGlyphs )
|
---|
| 382 | ((QTextEngine *)this)->reallocate( ( (used + nGlyphs + 16) >> 4 ) << 4 );
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | int allocated;
|
---|
| 386 | void **memory;
|
---|
| 387 | int num_glyphs;
|
---|
| 388 | int used;
|
---|
| 389 | };
|
---|
| 390 |
|
---|
| 391 | #endif
|
---|