| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qtextengine_p.h 8 2005-11-16 19:36:46Z 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 |
|
|---|
| 180 | #elif defined( Q_WS_PM )
|
|---|
| 181 |
|
|---|
| 182 | //@@TODO (dmik): the definitions below is almost unchecked (no true unicode
|
|---|
| 183 | // support yet)
|
|---|
| 184 |
|
|---|
| 185 | //@@TODO (dmik): curretnly glyphs are just 8 bit chars (see
|
|---|
| 186 | // QFontEnginePM::stringToCMap()), so glyph_t is temporarily defined as
|
|---|
| 187 | // unsigned char. it should be changed later.
|
|---|
| 188 | typedef unsigned char glyph_t;
|
|---|
| 189 | //typedef unsigned short glyph_t;
|
|---|
| 190 |
|
|---|
| 191 | struct qoffset_t {
|
|---|
| 192 | int x;
|
|---|
| 193 | int y;
|
|---|
| 194 | };
|
|---|
| 195 |
|
|---|
| 196 | typedef int advance_t;
|
|---|
| 197 |
|
|---|
| 198 | //@@TODO (dmik): it's a dummy version...
|
|---|
| 199 | struct QScriptAnalysis {
|
|---|
| 200 | unsigned short script :10;
|
|---|
| 201 | unsigned short bidiLevel :5;
|
|---|
| 202 | unsigned short override :1;
|
|---|
| 203 | unsigned short reserved :1;
|
|---|
| 204 | };
|
|---|
| 205 |
|
|---|
| 206 | inline bool operator == ( const QScriptAnalysis &sa1, const QScriptAnalysis &sa2 )
|
|---|
| 207 | {
|
|---|
| 208 | return
|
|---|
| 209 | sa1.script == sa2.script &&
|
|---|
| 210 | sa1.bidiLevel == sa2.bidiLevel;
|
|---|
| 211 | // ###
|
|---|
| 212 | // && override == other.override;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | #endif
|
|---|
| 216 |
|
|---|
| 217 | // enum and struct are made to be compatible with Uniscribe, dont change unless you know what you're doing.
|
|---|
| 218 | struct GlyphAttributes {
|
|---|
| 219 | // highest value means highest priority for justification. Justification is done by first inserting kashidas
|
|---|
| 220 | // starting with the highest priority positions, then stretching spaces, afterwards extending inter char
|
|---|
| 221 | // spacing, and last spacing between arabic words.
|
|---|
| 222 | // NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics.
|
|---|
| 223 | enum Justification {
|
|---|
| 224 | NoJustification= 0, // Justification can't be applied at this glyph
|
|---|
| 225 | Arabic_Space = 1, // This glyph represents a space in an Arabic item
|
|---|
| 226 | Character = 2, // Inter-character justification point follows this glyph
|
|---|
| 227 | Space = 4, // This glyph represents a blank outside an Arabic run
|
|---|
| 228 | Arabic_Normal = 7, // Normal Middle-Of-Word glyph that connects to the right (begin)
|
|---|
| 229 | Arabic_Kashida = 8, // Kashida(U+640) in middle of word
|
|---|
| 230 | Arabic_Alef = 9, // Final form of Alef-like (U+627, U+625, U+623, U+632)
|
|---|
| 231 | Arabic_Ha = 10, // Final Form Of Ha (U+647)
|
|---|
| 232 | Arabic_Ra = 11, // Final Form Of Ra (U+631)
|
|---|
| 233 | Arabic_Ba = 12, // Middle-Of-Word Form Of Ba (U+628)
|
|---|
| 234 | Arabic_Bara = 13, // Ligature Of Alike (U+628,U+631)
|
|---|
| 235 | Arabic_Seen = 14 // Highest Priority: Initial Shape Of Seen(U+633) (End)
|
|---|
| 236 | };
|
|---|
| 237 | unsigned short justification :4; // Justification class
|
|---|
| 238 | unsigned short clusterStart :1; // First glyph of representation of cluster
|
|---|
| 239 | unsigned short mark :1; // needs to be positioned around base char
|
|---|
| 240 | unsigned short zeroWidth :1; // ZWJ, ZWNJ etc, with no width
|
|---|
| 241 | unsigned short reserved :1;
|
|---|
| 242 | unsigned short combiningClass :8;
|
|---|
| 243 | };
|
|---|
| 244 |
|
|---|
| 245 | // also this is compatible to uniscribe. Do not change.
|
|---|
| 246 | struct QCharAttributes {
|
|---|
| 247 | uchar softBreak :1; // Potential linebreak point _before_ this character
|
|---|
| 248 | uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP
|
|---|
| 249 | uchar charStop :1; // Valid cursor position (for left/right arrow)
|
|---|
| 250 | uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow)
|
|---|
| 251 | uchar invalid :1;
|
|---|
| 252 | uchar reserved :3;
|
|---|
| 253 | };
|
|---|
| 254 |
|
|---|
| 255 | class QFontEngine;
|
|---|
| 256 |
|
|---|
| 257 | struct QScriptItem
|
|---|
| 258 | {
|
|---|
| 259 | inline QScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ),
|
|---|
| 260 | isObject( FALSE ), hasPositioning( FALSE ),
|
|---|
| 261 | descent( -1 ), ascent( -1 ), width( -1 ),
|
|---|
| 262 | x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ),
|
|---|
| 263 | fontEngine( 0 ) { }
|
|---|
| 264 | int position;
|
|---|
| 265 | QScriptAnalysis analysis;
|
|---|
| 266 | unsigned short isSpace : 1;
|
|---|
| 267 | unsigned short isTab : 1;
|
|---|
| 268 | unsigned short isObject : 1;
|
|---|
| 269 | unsigned short hasPositioning : 1;
|
|---|
| 270 | unsigned short reserved : 12;
|
|---|
| 271 | short descent;
|
|---|
| 272 | int ascent;
|
|---|
| 273 | int width;
|
|---|
| 274 | int x;
|
|---|
| 275 | int y;
|
|---|
| 276 | int num_glyphs;
|
|---|
| 277 | int glyph_data_offset;
|
|---|
| 278 | QFontEngine *fontEngine;
|
|---|
| 279 | };
|
|---|
| 280 |
|
|---|
| 281 | struct QScriptItemArrayPrivate
|
|---|
| 282 | {
|
|---|
| 283 | unsigned int alloc;
|
|---|
| 284 | unsigned int size;
|
|---|
| 285 | QScriptItem items[1];
|
|---|
| 286 | };
|
|---|
| 287 |
|
|---|
| 288 | class QScriptItemArray
|
|---|
| 289 | {
|
|---|
| 290 | public:
|
|---|
| 291 | QScriptItemArray() : d( 0 ) {}
|
|---|
| 292 | ~QScriptItemArray();
|
|---|
| 293 |
|
|---|
| 294 | inline QScriptItem &operator[] (int i) const {return d->items[i]; }
|
|---|
| 295 | inline void append( const QScriptItem &item ) {
|
|---|
| 296 | if ( d->size == d->alloc )
|
|---|
| 297 | resize( d->size + 1 );
|
|---|
| 298 | d->items[d->size] = item;
|
|---|
| 299 | d->size++;
|
|---|
| 300 | }
|
|---|
| 301 | inline int size() const { return d ? d->size : 0; }
|
|---|
| 302 |
|
|---|
| 303 | void resize( int s );
|
|---|
| 304 | void clear();
|
|---|
| 305 |
|
|---|
| 306 | QScriptItemArrayPrivate *d;
|
|---|
| 307 | private:
|
|---|
| 308 | #ifdef Q_DISABLE_COPY
|
|---|
| 309 | QScriptItemArray( const QScriptItemArray & );
|
|---|
| 310 | QScriptItemArray &operator = ( const QScriptItemArray & );
|
|---|
| 311 | #endif
|
|---|
| 312 | };
|
|---|
| 313 |
|
|---|
| 314 | class QFontPrivate;
|
|---|
| 315 |
|
|---|
| 316 | class QTextEngine {
|
|---|
| 317 | public:
|
|---|
| 318 | QTextEngine( const QString &str, QFontPrivate *f );
|
|---|
| 319 | ~QTextEngine();
|
|---|
| 320 |
|
|---|
| 321 | enum Mode {
|
|---|
| 322 | Full = 0x00,
|
|---|
| 323 | NoBidi = 0x01,
|
|---|
| 324 | SingleLine = 0x02,
|
|---|
| 325 | WidthOnly = 0x07
|
|---|
| 326 | };
|
|---|
| 327 |
|
|---|
| 328 | void itemize( int mode = Full );
|
|---|
| 329 |
|
|---|
| 330 | static void bidiReorder( int numRuns, const Q_UINT8 *levels, int *visualOrder );
|
|---|
| 331 |
|
|---|
| 332 | const QCharAttributes *attributes();
|
|---|
| 333 | void shape( int item ) const;
|
|---|
| 334 |
|
|---|
| 335 | // ### we need something for justification
|
|---|
| 336 |
|
|---|
| 337 | enum Edge {
|
|---|
| 338 | Leading,
|
|---|
| 339 | Trailing
|
|---|
| 340 | };
|
|---|
| 341 |
|
|---|
| 342 | int width( int charFrom, int numChars ) const;
|
|---|
| 343 | glyph_metrics_t boundingBox( int from, int len ) const;
|
|---|
| 344 |
|
|---|
| 345 | QScriptItemArray items;
|
|---|
| 346 | QString string;
|
|---|
| 347 | QFontPrivate *fnt;
|
|---|
| 348 | int lineWidth;
|
|---|
| 349 | int widthUsed;
|
|---|
| 350 | int firstItemInLine;
|
|---|
| 351 | int currentItem;
|
|---|
| 352 | QChar::Direction direction : 5;
|
|---|
| 353 | unsigned int haveCharAttributes : 1;
|
|---|
| 354 | unsigned int widthOnly : 1;
|
|---|
| 355 | unsigned int reserved : 25;
|
|---|
| 356 |
|
|---|
| 357 | int length( int item ) const {
|
|---|
| 358 | const QScriptItem &si = items[item];
|
|---|
| 359 | int from = si.position;
|
|---|
| 360 | item++;
|
|---|
| 361 | return ( item < items.size() ? items[item].position : string.length() ) - from;
|
|---|
| 362 | }
|
|---|
| 363 | void splitItem( int item, int pos );
|
|---|
| 364 |
|
|---|
| 365 | unsigned short *logClustersPtr;
|
|---|
| 366 | glyph_t *glyphPtr;
|
|---|
| 367 | advance_t *advancePtr;
|
|---|
| 368 | qoffset_t *offsetsPtr;
|
|---|
| 369 | GlyphAttributes *glyphAttributesPtr;
|
|---|
| 370 |
|
|---|
| 371 | inline unsigned short *logClusters( const QScriptItem *si ) const
|
|---|
| 372 | { return logClustersPtr+si->position; }
|
|---|
| 373 | inline glyph_t *glyphs( const QScriptItem *si ) const
|
|---|
| 374 | { return glyphPtr+si->glyph_data_offset; }
|
|---|
| 375 | inline advance_t *advances( const QScriptItem *si ) const
|
|---|
| 376 | { return advancePtr+si->glyph_data_offset; }
|
|---|
| 377 | inline qoffset_t *offsets( const QScriptItem *si ) const
|
|---|
| 378 | { return offsetsPtr+si->glyph_data_offset; }
|
|---|
| 379 | inline GlyphAttributes *glyphAttributes( const QScriptItem *si ) const
|
|---|
| 380 | { return glyphAttributesPtr+si->glyph_data_offset; }
|
|---|
| 381 |
|
|---|
| 382 | void reallocate( int totalGlyphs );
|
|---|
| 383 | inline void ensureSpace( int nGlyphs ) const {
|
|---|
| 384 | if ( num_glyphs - used < nGlyphs )
|
|---|
| 385 | ((QTextEngine *)this)->reallocate( ( (used + nGlyphs + 16) >> 4 ) << 4 );
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | int allocated;
|
|---|
| 389 | void **memory;
|
|---|
| 390 | int num_glyphs;
|
|---|
| 391 | int used;
|
|---|
| 392 | };
|
|---|
| 393 |
|
|---|
| 394 | #endif
|
|---|