source: trunk/src/kernel/qtextengine_p.h@ 7

Last change on this file since 7 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1/****************************************************************************
2** $Id: qtextengine_p.h 2 2005-11-16 15:49:26Z 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
46class QFontPrivate;
47class QString;
48
49class QOpenType;
50class 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
57struct 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 )
84typedef unsigned short glyph_t;
85
86struct qoffset_t {
87 short x;
88 short y;
89};
90
91typedef int advance_t;
92
93struct 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
111typedef unsigned short glyph_t;
112
113struct qoffset_t {
114 short x;
115 short y;
116};
117
118typedef int advance_t;
119
120struct 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
141typedef unsigned short glyph_t;
142
143struct qoffset_t {
144 int x;
145 int y;
146};
147
148typedef int advance_t;
149
150struct 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
171inline 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#endif
181
182// enum and struct are made to be compatible with Uniscribe, dont change unless you know what you're doing.
183struct GlyphAttributes {
184 // highest value means highest priority for justification. Justification is done by first inserting kashidas
185 // starting with the highest priority positions, then stretching spaces, afterwards extending inter char
186 // spacing, and last spacing between arabic words.
187 // NoJustification is for example set for arabic where no Kashida can be inserted or for diacritics.
188 enum Justification {
189 NoJustification= 0, // Justification can't be applied at this glyph
190 Arabic_Space = 1, // This glyph represents a space in an Arabic item
191 Character = 2, // Inter-character justification point follows this glyph
192 Space = 4, // This glyph represents a blank outside an Arabic run
193 Arabic_Normal = 7, // Normal Middle-Of-Word glyph that connects to the right (begin)
194 Arabic_Kashida = 8, // Kashida(U+640) in middle of word
195 Arabic_Alef = 9, // Final form of Alef-like (U+627, U+625, U+623, U+632)
196 Arabic_Ha = 10, // Final Form Of Ha (U+647)
197 Arabic_Ra = 11, // Final Form Of Ra (U+631)
198 Arabic_Ba = 12, // Middle-Of-Word Form Of Ba (U+628)
199 Arabic_Bara = 13, // Ligature Of Alike (U+628,U+631)
200 Arabic_Seen = 14 // Highest Priority: Initial Shape Of Seen(U+633) (End)
201 };
202 unsigned short justification :4; // Justification class
203 unsigned short clusterStart :1; // First glyph of representation of cluster
204 unsigned short mark :1; // needs to be positioned around base char
205 unsigned short zeroWidth :1; // ZWJ, ZWNJ etc, with no width
206 unsigned short reserved :1;
207 unsigned short combiningClass :8;
208};
209
210// also this is compatible to uniscribe. Do not change.
211struct QCharAttributes {
212 uchar softBreak :1; // Potential linebreak point _before_ this character
213 uchar whiteSpace :1; // A unicode whitespace character, except NBSP, ZWNBSP
214 uchar charStop :1; // Valid cursor position (for left/right arrow)
215 uchar wordStop :1; // Valid cursor position (for ctrl + left/right arrow)
216 uchar invalid :1;
217 uchar reserved :3;
218};
219
220class QFontEngine;
221
222struct QScriptItem
223{
224 inline QScriptItem() : position( 0 ), isSpace( FALSE ), isTab( FALSE ),
225 isObject( FALSE ), hasPositioning( FALSE ),
226 descent( -1 ), ascent( -1 ), width( -1 ),
227 x( 0 ), y( 0 ), num_glyphs( 0 ), glyph_data_offset( 0 ),
228 fontEngine( 0 ) { }
229 int position;
230 QScriptAnalysis analysis;
231 unsigned short isSpace : 1;
232 unsigned short isTab : 1;
233 unsigned short isObject : 1;
234 unsigned short hasPositioning : 1;
235 unsigned short reserved : 12;
236 short descent;
237 int ascent;
238 int width;
239 int x;
240 int y;
241 int num_glyphs;
242 int glyph_data_offset;
243 QFontEngine *fontEngine;
244};
245
246struct QScriptItemArrayPrivate
247{
248 unsigned int alloc;
249 unsigned int size;
250 QScriptItem items[1];
251};
252
253class QScriptItemArray
254{
255public:
256 QScriptItemArray() : d( 0 ) {}
257 ~QScriptItemArray();
258
259 inline QScriptItem &operator[] (int i) const {return d->items[i]; }
260 inline void append( const QScriptItem &item ) {
261 if ( d->size == d->alloc )
262 resize( d->size + 1 );
263 d->items[d->size] = item;
264 d->size++;
265 }
266 inline int size() const { return d ? d->size : 0; }
267
268 void resize( int s );
269 void clear();
270
271 QScriptItemArrayPrivate *d;
272private:
273#ifdef Q_DISABLE_COPY
274 QScriptItemArray( const QScriptItemArray & );
275 QScriptItemArray &operator = ( const QScriptItemArray & );
276#endif
277};
278
279class QFontPrivate;
280
281class QTextEngine {
282public:
283 QTextEngine( const QString &str, QFontPrivate *f );
284 ~QTextEngine();
285
286 enum Mode {
287 Full = 0x00,
288 NoBidi = 0x01,
289 SingleLine = 0x02,
290 WidthOnly = 0x07
291 };
292
293 void itemize( int mode = Full );
294
295 static void bidiReorder( int numRuns, const Q_UINT8 *levels, int *visualOrder );
296
297 const QCharAttributes *attributes();
298 void shape( int item ) const;
299
300 // ### we need something for justification
301
302 enum Edge {
303 Leading,
304 Trailing
305 };
306
307 int width( int charFrom, int numChars ) const;
308 glyph_metrics_t boundingBox( int from, int len ) const;
309
310 QScriptItemArray items;
311 QString string;
312 QFontPrivate *fnt;
313 int lineWidth;
314 int widthUsed;
315 int firstItemInLine;
316 int currentItem;
317 QChar::Direction direction : 5;
318 unsigned int haveCharAttributes : 1;
319 unsigned int widthOnly : 1;
320 unsigned int reserved : 25;
321
322 int length( int item ) const {
323 const QScriptItem &si = items[item];
324 int from = si.position;
325 item++;
326 return ( item < items.size() ? items[item].position : string.length() ) - from;
327 }
328 void splitItem( int item, int pos );
329
330 unsigned short *logClustersPtr;
331 glyph_t *glyphPtr;
332 advance_t *advancePtr;
333 qoffset_t *offsetsPtr;
334 GlyphAttributes *glyphAttributesPtr;
335
336 inline unsigned short *logClusters( const QScriptItem *si ) const
337 { return logClustersPtr+si->position; }
338 inline glyph_t *glyphs( const QScriptItem *si ) const
339 { return glyphPtr+si->glyph_data_offset; }
340 inline advance_t *advances( const QScriptItem *si ) const
341 { return advancePtr+si->glyph_data_offset; }
342 inline qoffset_t *offsets( const QScriptItem *si ) const
343 { return offsetsPtr+si->glyph_data_offset; }
344 inline GlyphAttributes *glyphAttributes( const QScriptItem *si ) const
345 { return glyphAttributesPtr+si->glyph_data_offset; }
346
347 void reallocate( int totalGlyphs );
348 inline void ensureSpace( int nGlyphs ) const {
349 if ( num_glyphs - used < nGlyphs )
350 ((QTextEngine *)this)->reallocate( ( (used + nGlyphs + 16) >> 4 ) << 4 );
351 }
352
353 int allocated;
354 void **memory;
355 int num_glyphs;
356 int used;
357};
358
359#endif
Note: See TracBrowser for help on using the repository browser.