source: trunk/src/kernel/qfontengine_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: 15.9 KB
Line 
1/****************************************************************************
2** $Id: qfontengine_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 QFONTENGINE_P_H
32#define QFONTENGINE_P_H
33
34#ifndef QT_H
35#include "qglobal.h"
36#endif // QT_H
37
38#ifdef Q_WS_WIN
39#include "qt_windows.h"
40#endif
41
42#include "qtextengine_p.h"
43
44class QPaintDevice;
45
46struct glyph_metrics_t;
47class QChar;
48typedef unsigned short glyph_t;
49struct qoffset_t;
50typedef int advance_t;
51class QOpenType;
52struct TransformedFont;
53
54#if defined( Q_WS_X11 ) || defined( Q_WS_WIN) || defined( Q_WS_MAC )
55class QFontEngine : public QShared
56{
57public:
58 enum Error {
59 NoError,
60 OutOfMemory
61 };
62
63 enum Type {
64 // X11 types
65 Box,
66 XLFD,
67 LatinXLFD,
68 Xft,
69
70 // MS Windows types
71 Win,
72 Uniscribe,
73
74 // Apple MacOS types
75 Mac,
76
77 // Trolltech QWS types
78 QWS
79 };
80
81 QFontEngine() {
82 count = 0; cache_count = 0;
83#ifdef Q_WS_X11
84 transformed_fonts = 0;
85#endif
86 }
87 virtual ~QFontEngine();
88
89 /* returns 0 as glyph index for non existant glyphs */
90 virtual Error stringToCMap( const QChar *str, int len, glyph_t *glyphs,
91 advance_t *advances, int *nglyphs, bool mirrored ) const = 0;
92
93#ifdef Q_WS_X11
94 virtual int cmap() const { return -1; }
95 virtual QOpenType *openType() const { return 0; }
96#endif
97
98 virtual void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags ) = 0;
99
100 virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
101 const advance_t *advances,
102 const qoffset_t *offsets, int numGlyphs ) = 0;
103 virtual glyph_metrics_t boundingBox( glyph_t glyph ) = 0;
104
105 virtual int ascent() const = 0;
106 virtual int descent() const = 0;
107 virtual int leading() const = 0;
108
109 virtual int lineThickness() const;
110 virtual int underlinePosition() const;
111
112 virtual int maxCharWidth() const = 0;
113 virtual int minLeftBearing() const { return 0; }
114 virtual int minRightBearing() const { return 0; }
115
116 virtual const char *name() const = 0;
117
118 virtual bool canRender( const QChar *string, int len ) = 0;
119
120 virtual void setScale( double ) {}
121 virtual double scale() const { return 1.; }
122
123 virtual Type type() const = 0;
124
125 QFontDef fontDef;
126 uint cache_cost; // amount of mem used in kb by the font
127 int cache_count;
128
129#ifdef Q_WS_WIN
130 HDC dc() const;
131 void getGlyphIndexes( const QChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const;
132 void getCMap();
133
134 QCString _name;
135 HDC hdc;
136 HFONT hfont;
137 LOGFONT logfont;
138 uint stockFont : 1;
139 uint paintDevice : 1;
140 uint useTextOutA : 1;
141 uint ttf : 1;
142 uint symbol : 1;
143 union {
144 TEXTMETRICW w;
145 TEXTMETRICA a;
146 } tm;
147 int lw;
148 unsigned char *cmap;
149 void *script_cache;
150 short lbearing;
151 short rbearing;
152#endif // Q_WS_WIN
153#ifdef Q_WS_X11
154 TransformedFont *transformed_fonts;
155#endif
156};
157#elif defined( Q_WS_QWS )
158class QGfx;
159
160class QFontEngine : public QShared
161{
162public:
163 QFontEngine( const QFontDef&, const QPaintDevice * = 0 );
164 ~QFontEngine();
165 /*QMemoryManager::FontID*/ void *handle() const;
166
167 enum Type {
168 // X11 types
169 Box,
170 XLFD,
171 Xft,
172
173 // MS Windows types
174 Win,
175 Uniscribe,
176
177 // Apple MacOS types
178 Mac,
179
180 // Trolltech QWS types
181 Qws
182 };
183
184 enum TextFlags {
185 Underline = 0x01,
186 Overline = 0x02,
187 StrikeOut = 0x04
188 };
189
190 enum Error {
191 NoError,
192 OutOfMemory
193 };
194 /* returns 0 as glyph index for non existant glyphs */
195 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
196
197 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
198
199 glyph_metrics_t boundingBox( const glyph_t *glyphs,
200 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
201 glyph_metrics_t boundingBox( glyph_t glyph );
202
203 int ascent() const;
204 int descent() const;
205 int leading() const;
206 int maxCharWidth() const;
207 int minLeftBearing() const;
208 int minRightBearing() const;
209 int underlinePosition() const;
210 int lineThickness() const;
211
212 Type type() { return Qws; }
213
214 bool canRender( const QChar *string, int len );
215 inline const char *name() const { return 0; }
216 QFontDef fontDef;
217 /*QMemoryManager::FontID*/ void *id;
218 int cache_cost;
219 int cache_count;
220 int scale;
221};
222#endif // WIN || X11 || MAC
223
224
225
226enum IndicFeatures {
227 CcmpFeature,
228 InitFeature,
229 NuktaFeature,
230 AkhantFeature,
231 RephFeature,
232 BelowFormFeature,
233 HalfFormFeature,
234 PostFormFeature,
235 VattuFeature,
236 PreSubstFeature,
237 AboveSubstFeature,
238 BelowSubstFeature,
239 PostSubstFeature,
240 HalantFeature
241};
242
243#if defined(Q_WS_X11) || defined(Q_WS_WIN)
244class QFontEngineBox : public QFontEngine
245{
246public:
247 QFontEngineBox( int size );
248 ~QFontEngineBox();
249
250 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
251
252 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
253
254 virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
255 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
256 glyph_metrics_t boundingBox( glyph_t glyph );
257
258 int ascent() const;
259 int descent() const;
260 int leading() const;
261 int maxCharWidth() const;
262 int minLeftBearing() const { return 0; }
263 int minRightBearing() const { return 0; }
264
265#ifdef Q_WS_X11
266 int cmap() const;
267#endif
268 const char *name() const;
269
270 bool canRender( const QChar *string, int len );
271
272 Type type() const;
273 inline int size() const { return _size; }
274
275private:
276 friend class QFontPrivate;
277 int _size;
278};
279#endif
280
281#ifdef Q_WS_X11
282#include "qt_x11_p.h"
283
284
285struct TransformedFont
286{
287 float xx;
288 float xy;
289 float yx;
290 float yy;
291 union {
292 Font xlfd_font;
293#ifndef QT_NO_XFTFREETYPE
294 XftFont *xft_font;
295#endif
296 };
297 TransformedFont *next;
298};
299
300#ifndef QT_NO_XFTFREETYPE
301#include <ft2build.h>
302#include FT_FREETYPE_H
303#include "ftxopen.h"
304
305class QTextCodec;
306
307class QFontEngineXft : public QFontEngine
308{
309public:
310 QFontEngineXft( XftFont *font, XftPattern *pattern, int cmap );
311 ~QFontEngineXft();
312
313 QOpenType *openType() const;
314
315 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
316
317 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
318
319 virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
320 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
321 glyph_metrics_t boundingBox( glyph_t glyph );
322
323 int ascent() const;
324 int descent() const;
325 int leading() const;
326 int lineThickness() const;
327 int underlinePosition() const;
328 int maxCharWidth() const;
329 int minLeftBearing() const;
330 int minRightBearing() const;
331
332 int cmap() const;
333 const char *name() const;
334
335 void setScale( double scale );
336 double scale() const { return _scale; }
337
338 bool canRender( const QChar *string, int len );
339
340 Type type() const;
341 XftPattern *pattern() const { return _pattern; }
342
343 void recalcAdvances( int len, glyph_t *glyphs, advance_t *advances );
344
345private:
346 friend class QFontPrivate;
347 XftFont *_font;
348 XftPattern *_pattern;
349 FT_Face _face;
350 QOpenType *_openType;
351 int _cmap;
352 short lbearing;
353 short rbearing;
354 float _scale;
355 enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
356 unsigned char widthCache[widthCacheSize];
357 glyph_t cmapCache[cmapCacheSize];
358};
359#endif
360
361class QFontEngineLatinXLFD;
362
363class QFontEngineXLFD : public QFontEngine
364{
365public:
366 QFontEngineXLFD( XFontStruct *fs, const char *name, int cmap );
367 ~QFontEngineXLFD();
368
369 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
370
371 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
372
373 virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
374 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
375 glyph_metrics_t boundingBox( glyph_t glyph );
376
377 int ascent() const;
378 int descent() const;
379 int leading() const;
380 int maxCharWidth() const;
381 int minLeftBearing() const;
382 int minRightBearing() const;
383
384 int cmap() const;
385 const char *name() const;
386
387 bool canRender( const QChar *string, int len );
388
389 void setScale( double scale );
390 double scale() const { return _scale; }
391 Type type() const;
392
393 Qt::HANDLE handle() const { return (Qt::HANDLE) _fs->fid; }
394
395private:
396 friend class QFontPrivate;
397 XFontStruct *_fs;
398 QCString _name;
399 QTextCodec *_codec;
400 float _scale; // needed for printing, to correctly scale font metrics for bitmap fonts
401 int _cmap;
402 short lbearing;
403 short rbearing;
404 enum XlfdTransformations {
405 XlfdTrUnknown,
406 XlfdTrSupported,
407 XlfdTrUnsupported
408 };
409 XlfdTransformations xlfd_transformations;
410
411 friend class QFontEngineLatinXLFD;
412};
413
414class QFontEngineLatinXLFD : public QFontEngine
415{
416public:
417 QFontEngineLatinXLFD( XFontStruct *xfs, const char *name, int cmap );
418 ~QFontEngineLatinXLFD();
419
420 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs,
421 advance_t *advances, int *nglyphs, bool mirrored ) const;
422
423 void draw( QPainter *p, int x, int y, const QTextEngine *engine,
424 const QScriptItem *si, int textFlags );
425
426 virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
427 const advance_t *advances,
428 const qoffset_t *offsets, int numGlyphs );
429 glyph_metrics_t boundingBox( glyph_t glyph );
430
431 int ascent() const;
432 int descent() const;
433 int leading() const;
434 int maxCharWidth() const;
435 int minLeftBearing() const;
436 int minRightBearing() const;
437
438 int cmap() const { return -1; } // ###
439 const char *name() const;
440
441 bool canRender( const QChar *string, int len );
442
443 void setScale( double scale );
444 double scale() const { return _engines[0]->scale(); }
445 Type type() const { return LatinXLFD; }
446
447 Qt::HANDLE handle() const { return ((QFontEngineXLFD *) _engines[0])->handle(); }
448
449private:
450 void findEngine( const QChar &ch );
451
452 QFontEngine **_engines;
453 int _count;
454
455 glyph_t glyphIndices [0x200];
456 advance_t glyphAdvances[0x200];
457 glyph_t euroIndex;
458 advance_t euroAdvance;
459};
460
461class QScriptItem;
462class QTextEngine;
463
464#ifndef QT_NO_XFTFREETYPE
465class QOpenType
466{
467public:
468 QOpenType( FT_Face face );
469 ~QOpenType();
470
471 bool supportsScript( unsigned int script );
472
473 void applyGSUBFeature(unsigned int feature, bool *where = 0);
474 void applyGPOSFeatures();
475
476
477 void init(glyph_t *glyphs, GlyphAttributes *glyphAttributes, int num_glyphs,
478 unsigned short *logClusters, int len, int char_offset = 0);
479 void appendTo(QTextEngine *engine, QScriptItem *si, bool doLogClusters = TRUE);
480
481 const int *mapping(int &len);
482 inline void setLength(int len) { str->length = len; }
483 unsigned short *glyphs() { return str->string; }
484private:
485 bool loadTables( FT_ULong script);
486
487 FT_Face face;
488 TTO_GDEF gdef;
489 TTO_GSUB gsub;
490 TTO_GPOS gpos;
491 FT_UShort script_index;
492 FT_ULong current_script;
493 bool hasGDef : 1;
494 bool hasGSub : 1;
495 bool hasGPos : 1;
496 bool positioned : 1;
497 TTO_GSUB_String *str;
498 TTO_GSUB_String *tmp;
499 TTO_GPOS_Data *positions;
500 GlyphAttributes *tmpAttributes;
501 unsigned short *tmpLogClusters;
502 int length;
503 int orig_nglyphs;
504};
505#endif // QT_NO_XFTFREETYPE
506
507#elif defined( Q_WS_MAC )
508#include "qt_mac.h"
509#include <qmap.h>
510#include <qcache.h>
511
512class QFontEngineMac : public QFontEngine
513{
514#if 0
515 ATSFontMetrics *info;
516#else
517 FontInfo *info;
518#endif
519 int psize;
520 short fnum;
521 QMacFontInfo *internal_fi;
522 mutable ATSUTextLayout mTextLayout;
523 enum { widthCacheSize = 0x500 };
524 mutable unsigned char widthCache[widthCacheSize];
525 friend class QFont;
526 friend class QGLContext;
527 friend class QFontPrivate;
528 friend class QMacSetFontInfo;
529
530public:
531 QFontEngineMac();
532 ~QFontEngineMac();
533
534 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
535
536 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
537
538 glyph_metrics_t boundingBox( const glyph_t *glyphs,
539 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
540 glyph_metrics_t boundingBox( glyph_t glyph );
541
542 int ascent() const { return (int)info->ascent; }
543 int descent() const { return (int)info->descent; }
544 int leading() const { return (int)info->leading; }
545#if 0
546 int maxCharWidth() const { return (int)info->maxAdvanceWidth; }
547#else
548 int maxCharWidth() const { return info->widMax; }
549#endif
550
551 const char *name() const { return "ATSUI"; }
552
553 bool canRender( const QChar *string, int len );
554
555 Type type() const { return QFontEngine::Mac; }
556
557 void calculateCost();
558
559 enum { WIDTH=0x01, DRAW=0x02, EXISTS=0x04 };
560 int doTextTask(const QChar *s, int pos, int use_len, int len, uchar task, int =-1, int y=-1,
561 QPaintDevice *dev=NULL, const QRegion *rgn=NULL) const;
562};
563
564#elif defined( Q_WS_WIN )
565
566class QFontEngineWin : public QFontEngine
567{
568public:
569 QFontEngineWin( const char *name, HDC, HFONT, bool, LOGFONT );
570
571 Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
572
573 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
574
575 glyph_metrics_t boundingBox( const glyph_t *glyphs,
576 const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
577 glyph_metrics_t boundingBox( glyph_t glyph );
578
579 int ascent() const;
580 int descent() const;
581 int leading() const;
582 int maxCharWidth() const;
583 int minLeftBearing() const;
584 int minRightBearing() const;
585
586 const char *name() const;
587
588 bool canRender( const QChar *string, int len );
589
590 Type type() const;
591
592 enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
593 unsigned char widthCache[widthCacheSize];
594};
595
596#if 0
597class QFontEngineUniscribe : public QFontEngineWin
598{
599public:
600 void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
601 bool canRender( const QChar *string, int len );
602
603 Type type() const;
604};
605#endif
606
607#endif // Q_WS_WIN
608
609#endif
Note: See TracBrowser for help on using the repository browser.