Eneboo - Documentación para desarrolladores
src/qt/src/kernel/qfontengine_p.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qfontengine_p.h   3.3.8   edited Jan 11 16:02 $
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 QFONTENGINE_P_H
00032 #define QFONTENGINE_P_H
00033 
00034 #ifndef QT_H
00035 #include "qglobal.h"
00036 #endif // QT_H
00037 
00038 #ifdef Q_WS_WIN
00039 #include "qt_windows.h"
00040 #include "qptrdict.h"
00041 #endif
00042 
00043 #include "qtextengine_p.h"
00044 
00045 class QPaintDevice;
00046 
00047 struct glyph_metrics_t;
00048 class QChar;
00049 typedef unsigned short glyph_t;
00050 struct qoffset_t;
00051 typedef int advance_t;
00052 class QOpenType;
00053 struct TransformedFont;
00054 
00055 #if defined( Q_WS_X11 ) || defined( Q_WS_WIN) || defined( Q_WS_MAC )
00056 class QFontEngine : public QShared
00057 {
00058 public:
00059     enum Error {
00060         NoError,
00061         OutOfMemory
00062     };
00063 
00064     enum Type {
00065         // X11 types
00066         Box,
00067         XLFD,
00068         LatinXLFD,
00069         Xft,
00070 
00071         // MS Windows types
00072         Win,
00073         Uniscribe,
00074 
00075         // Apple MacOS types
00076         Mac,
00077 
00078         // Trolltech QWS types
00079         QWS
00080     };
00081 
00082     QFontEngine() {
00083         count = 0; cache_count = 0;
00084 #ifdef Q_WS_X11
00085         transformed_fonts = 0;
00086 #endif
00087     }
00088     virtual ~QFontEngine();
00089 
00090     /* returns 0 as glyph index for non existant glyphs */
00091     virtual Error stringToCMap( const QChar *str, int len, glyph_t *glyphs,
00092                                 advance_t *advances, int *nglyphs, bool mirrored ) const = 0;
00093 
00094 #ifdef Q_WS_X11
00095     virtual int cmap() const { return -1; }
00096     virtual QOpenType *openType() const { return 0; }
00097 #endif
00098 
00099     virtual void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags ) = 0;
00100 
00101     virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
00102                                          const advance_t *advances,
00103                                          const qoffset_t *offsets, int numGlyphs ) = 0;
00104     virtual glyph_metrics_t boundingBox( glyph_t glyph ) = 0;
00105 
00106     virtual int ascent() const = 0;
00107     virtual int descent() const = 0;
00108     virtual int leading() const = 0;
00109 
00110     virtual int lineThickness() const;
00111     virtual int underlinePosition() const;
00112 
00113     virtual int maxCharWidth() const = 0;
00114     virtual int minLeftBearing() const { return 0; }
00115     virtual int minRightBearing() const { return 0; }
00116 
00117     virtual const char *name() const = 0;
00118 
00119     virtual bool canRender( const QChar *string,  int len ) = 0;
00120 
00121     virtual void setScale( double ) {}
00122     virtual double scale() const { return 1.; }
00123 
00124     virtual Type type() const = 0;
00125 
00126     QFontDef fontDef;
00127     uint cache_cost; // amount of mem used in kb by the font
00128     int cache_count;
00129 
00130 #ifdef Q_WS_WIN
00131     HDC dc() const;
00132     void getGlyphIndexes( const QChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const;
00133     void getCMap();
00134 
00135     QCString _name;
00136     HDC         hdc;
00137     HFONT       hfont;
00138     LOGFONT     logfont;
00139     uint        stockFont   : 1;
00140     uint        paintDevice : 1;
00141     uint        useTextOutA : 1;
00142     uint        ttf         : 1;
00143     uint        symbol      : 1;
00144     union {
00145         TEXTMETRICW     w;
00146         TEXTMETRICA     a;
00147     } tm;
00148     int         lw;
00149     unsigned char *cmap;
00150     void *script_cache;
00151     static QPtrDict<QFontEngine> cacheDict;
00152     short lbearing;
00153     short rbearing;
00154 #endif // Q_WS_WIN
00155 #ifdef Q_WS_X11
00156     TransformedFont *transformed_fonts;
00157 #endif
00158 };
00159 #elif defined( Q_WS_QWS )
00160 class QGfx;
00161 
00162 class QFontEngine : public QShared
00163 {
00164 public:
00165     QFontEngine( const QFontDef&, const QPaintDevice * = 0 );
00166    ~QFontEngine();
00167     /*QMemoryManager::FontID*/ void *handle() const;
00168 
00169     enum Type {
00170         // X11 types
00171         Box,
00172         XLFD,
00173         Xft,
00174 
00175         // MS Windows types
00176         Win,
00177         Uniscribe,
00178 
00179         // Apple MacOS types
00180         Mac,
00181 
00182         // Trolltech QWS types
00183         Qws
00184     };
00185 
00186     enum TextFlags {
00187         Underline = 0x01,
00188         Overline  = 0x02,
00189         StrikeOut = 0x04
00190     };
00191 
00192     enum Error {
00193         NoError,
00194         OutOfMemory
00195     };
00196     /* returns 0 as glyph index for non existant glyphs */
00197     Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00198 
00199     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00200 
00201     glyph_metrics_t boundingBox( const glyph_t *glyphs,
00202                                const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00203     glyph_metrics_t boundingBox( glyph_t glyph );
00204 
00205     int ascent() const;
00206     int descent() const;
00207     int leading() const;
00208     int maxCharWidth() const;
00209     int minLeftBearing() const;
00210     int minRightBearing() const;
00211     int underlinePosition() const;
00212     int lineThickness() const;
00213 
00214     Type type() { return Qws; }
00215 
00216     bool canRender( const QChar *string,  int len );
00217     inline const char *name() const { return 0; }
00218     QFontDef fontDef;
00219     /*QMemoryManager::FontID*/ void *id;
00220     int cache_cost;
00221     int cache_count;
00222     int scale;
00223 };
00224 #endif // WIN || X11 || MAC
00225 
00226 
00227 
00228 enum IndicFeatures {
00229     CcmpFeature,
00230     InitFeature,
00231     NuktaFeature,
00232     AkhantFeature,
00233     RephFeature,
00234     BelowFormFeature,
00235     HalfFormFeature,
00236     PostFormFeature,
00237     VattuFeature,
00238     PreSubstFeature,
00239     AboveSubstFeature,
00240     BelowSubstFeature,
00241     PostSubstFeature,
00242     HalantFeature
00243 };
00244 
00245 #if defined(Q_WS_X11) || defined(Q_WS_WIN)
00246 class QFontEngineBox : public QFontEngine
00247 {
00248 public:
00249     QFontEngineBox( int size );
00250     ~QFontEngineBox();
00251 
00252     Error stringToCMap( const QChar *str,  int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00253 
00254     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00255 
00256     virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
00257                                     const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00258     glyph_metrics_t boundingBox( glyph_t glyph );
00259 
00260     int ascent() const;
00261     int descent() const;
00262     int leading() const;
00263     int maxCharWidth() const;
00264     int minLeftBearing() const { return 0; }
00265     int minRightBearing() const { return 0; }
00266 
00267 #ifdef Q_WS_X11
00268     int cmap() const;
00269 #endif
00270     const char *name() const;
00271 
00272     bool canRender( const QChar *string,  int len );
00273 
00274     Type type() const;
00275     inline int size() const { return _size; }
00276 
00277 private:
00278     friend class QFontPrivate;
00279     int _size;
00280 };
00281 #endif
00282 
00283 #ifdef Q_WS_X11
00284 #include "qt_x11_p.h"
00285 
00286 
00287 struct TransformedFont
00288 {
00289     float xx;
00290     float xy;
00291     float yx;
00292     float yy;
00293     union {
00294         Font xlfd_font;
00295 #ifndef QT_NO_XFTFREETYPE
00296         XftFont *xft_font;
00297 #endif
00298     };
00299     TransformedFont *next;
00300 };
00301 
00302 #ifndef QT_NO_XFTFREETYPE
00303 #include <ft2build.h>
00304 #include FT_FREETYPE_H
00305 #include "ftxopen.h"
00306 
00307 class QTextCodec;
00308 
00309 class QFontEngineXft : public QFontEngine
00310 {
00311 public:
00312     QFontEngineXft( XftFont *font, XftPattern *pattern, int cmap );
00313     ~QFontEngineXft();
00314 
00315     QOpenType *openType() const;
00316 
00317     Error stringToCMap( const QChar *str,  int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00318 
00319     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00320 
00321     virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
00322                                     const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00323     glyph_metrics_t boundingBox( glyph_t glyph );
00324 
00325     int ascent() const;
00326     int descent() const;
00327     int leading() const;
00328     int lineThickness() const;
00329     int underlinePosition() const;
00330     int maxCharWidth() const;
00331     int minLeftBearing() const;
00332     int minRightBearing() const;
00333 
00334     int cmap() const;
00335     const char *name() const;
00336 
00337     void setScale( double scale );
00338     double scale() const { return _scale; }
00339 
00340     bool canRender( const QChar *string,  int len );
00341 
00342     Type type() const;
00343     XftPattern *pattern() const { return _pattern; }
00344     FT_Face face() const { return _face; }
00345     XftFont *font() const { return _font; }
00346 
00347     void recalcAdvances( int len, glyph_t *glyphs, advance_t *advances );
00348 
00349 private:
00350     friend class QFontPrivate;
00351     friend class QOpenType;
00352     XftFont *_font;
00353     XftPattern *_pattern;
00354     FT_Face _face;
00355     QOpenType *_openType;
00356     int _cmap;
00357     short lbearing;
00358     short rbearing;
00359     float _scale;
00360     enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
00361     unsigned char widthCache[widthCacheSize];
00362     glyph_t cmapCache[cmapCacheSize];
00363 };
00364 #endif
00365 
00366 class QFontEngineLatinXLFD;
00367 
00368 class QFontEngineXLFD : public QFontEngine
00369 {
00370 public:
00371     QFontEngineXLFD( XFontStruct *fs, const char *name, int cmap );
00372     ~QFontEngineXLFD();
00373 
00374     Error stringToCMap( const QChar *str,  int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00375 
00376     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00377 
00378     virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
00379                                     const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00380     glyph_metrics_t boundingBox( glyph_t glyph );
00381 
00382     int ascent() const;
00383     int descent() const;
00384     int leading() const;
00385     int maxCharWidth() const;
00386     int minLeftBearing() const;
00387     int minRightBearing() const;
00388 
00389     int cmap() const;
00390     const char *name() const;
00391 
00392     bool canRender( const QChar *string,  int len );
00393 
00394     void setScale( double scale );
00395     double scale() const { return _scale; }
00396     Type type() const;
00397 
00398     Qt::HANDLE handle() const { return (Qt::HANDLE) _fs->fid; }
00399 
00400 private:
00401     friend class QFontPrivate;
00402     XFontStruct *_fs;
00403     QCString _name;
00404     QTextCodec *_codec;
00405     float _scale; // needed for printing, to correctly scale font metrics for bitmap fonts
00406     int _cmap;
00407     short lbearing;
00408     short rbearing;
00409     enum XlfdTransformations {
00410         XlfdTrUnknown,
00411         XlfdTrSupported,
00412         XlfdTrUnsupported
00413     };
00414     XlfdTransformations xlfd_transformations;
00415 
00416     friend class QFontEngineLatinXLFD;
00417 };
00418 
00419 class QFontEngineLatinXLFD : public QFontEngine
00420 {
00421 public:
00422     QFontEngineLatinXLFD( XFontStruct *xfs, const char *name, int cmap );
00423     ~QFontEngineLatinXLFD();
00424 
00425     Error stringToCMap( const QChar *str,  int len, glyph_t *glyphs,
00426                         advance_t *advances, int *nglyphs, bool mirrored ) const;
00427 
00428     void draw( QPainter *p, int x, int y, const QTextEngine *engine,
00429                const QScriptItem *si, int textFlags );
00430 
00431     virtual glyph_metrics_t boundingBox( const glyph_t *glyphs,
00432                                          const advance_t *advances,
00433                                          const qoffset_t *offsets, int numGlyphs );
00434     glyph_metrics_t boundingBox( glyph_t glyph );
00435 
00436     int ascent() const;
00437     int descent() const;
00438     int leading() const;
00439     int maxCharWidth() const;
00440     int minLeftBearing() const;
00441     int minRightBearing() const;
00442 
00443     int cmap() const { return -1; } // ###
00444     const char *name() const;
00445 
00446     bool canRender( const QChar *string,  int len );
00447 
00448     void setScale( double scale );
00449     double scale() const { return _engines[0]->scale(); }
00450     Type type() const { return LatinXLFD; }
00451 
00452     Qt::HANDLE handle() const { return ((QFontEngineXLFD *) _engines[0])->handle(); }
00453 
00454 private:
00455     void findEngine( const QChar &ch );
00456 
00457     QFontEngine **_engines;
00458     int _count;
00459 
00460     glyph_t   glyphIndices [0x200];
00461     advance_t glyphAdvances[0x200];
00462     glyph_t euroIndex;
00463     advance_t euroAdvance;
00464 };
00465 
00466 class QScriptItem;
00467 class QTextEngine;
00468 
00469 #ifndef QT_NO_XFTFREETYPE
00470 
00471 #include "qscriptengine_p.h"
00472 #include "qtextengine_p.h"
00473 #include <ft2build.h>
00474 #include FT_FREETYPE_H
00475 #include "ftxopen.h"
00476 
00477 enum { PositioningProperties = 0x80000000 };
00478 
00479 class QOpenType
00480 {
00481 public:
00482     QOpenType(QFontEngineXft *fe);
00483     ~QOpenType();
00484 
00485     struct Features {
00486         uint tag;
00487         uint property;
00488     };
00489 
00490     bool supportsScript(unsigned int script) {
00491         Q_ASSERT(script < QFont::NScripts);
00492         return supported_scripts[script];
00493     }
00494     void selectScript(unsigned int script, const Features *features = 0);
00495 
00496     bool shape(QShaperItem *item, const unsigned int *properties = 0);
00497     bool positionAndAdd(QShaperItem *item, bool doLogClusters = TRUE);
00498 
00499     OTL_GlyphItem glyphs() const { return otl_buffer->in_string; }
00500     int len() const { return otl_buffer->in_length; }
00501     void setProperty(int index, uint property) { otl_buffer->in_string[index].properties = property; }
00502 
00503 
00504 private:
00505     bool checkScript(unsigned int script);
00506     QFontEngine *fontEngine;
00507     FT_Face face;
00508     TTO_GDEF gdef;
00509     TTO_GSUB gsub;
00510     TTO_GPOS gpos;
00511     bool supported_scripts[QFont::NScripts];
00512     FT_ULong current_script;
00513     bool positioned : 1;
00514     OTL_Buffer otl_buffer;
00515     GlyphAttributes *tmpAttributes;
00516     unsigned int *tmpLogClusters;
00517     int length;
00518     int orig_nglyphs;
00519     int loadFlags;
00520 };
00521 
00522 #endif // QT_NO_XFTFREETYPE
00523 
00524 #elif defined( Q_WS_MAC )
00525 #include "qt_mac.h"
00526 #include <qmap.h>
00527 #include <qcache.h>
00528 
00529 class QFontEngineMac : public QFontEngine
00530 {
00531 #if 0
00532     ATSFontMetrics *info;
00533 #else
00534     FontInfo *info;
00535 #endif
00536     int psize;
00537     FMFontFamily fmfam;
00538     QMacFontInfo *internal_fi;
00539     mutable ATSUTextLayout mTextLayout;
00540     enum { widthCacheSize = 0x500 };
00541     mutable unsigned char widthCache[widthCacheSize];
00542     friend class QFont;
00543     friend class QGLContext;
00544     friend class QFontPrivate;
00545     friend class QMacSetFontInfo;
00546 
00547 public:
00548     QFontEngineMac();
00549     ~QFontEngineMac();
00550 
00551     Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00552 
00553     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00554 
00555     glyph_metrics_t boundingBox( const glyph_t *glyphs,
00556                                const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00557     glyph_metrics_t boundingBox( glyph_t glyph );
00558 
00559     int ascent() const { return (int)info->ascent; }
00560     int descent() const { return (int)info->descent; }
00561     int leading() const { return (int)info->leading; }
00562 #if 0
00563     int maxCharWidth() const { return (int)info->maxAdvanceWidth; }
00564 #else
00565     int maxCharWidth() const { return info->widMax; }
00566 #endif
00567 
00568     const char *name() const { return "ATSUI"; }
00569 
00570     bool canRender( const QChar *string,  int len );
00571 
00572     Type type() const { return QFontEngine::Mac; }
00573 
00574     void calculateCost();
00575 
00576     enum { WIDTH=0x01, DRAW=0x02, EXISTS=0x04 };
00577     int doTextTask(const QChar *s, int pos, int use_len, int len, uchar task, int =-1, int y=-1,
00578                    QPaintDevice *dev=NULL, const QRegion *rgn=NULL) const;
00579 };
00580 
00581 #elif defined( Q_WS_WIN )
00582 
00583 class QFontEngineWin : public QFontEngine
00584 {
00585 public:
00586     QFontEngineWin( const char *name, HDC, HFONT, bool, LOGFONT );
00587 
00588     Error stringToCMap( const QChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const;
00589 
00590     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00591 
00592     glyph_metrics_t boundingBox( const glyph_t *glyphs,
00593                                const advance_t *advances, const qoffset_t *offsets, int numGlyphs );
00594     glyph_metrics_t boundingBox( glyph_t glyph );
00595 
00596     int ascent() const;
00597     int descent() const;
00598     int leading() const;
00599     int maxCharWidth() const;
00600     int minLeftBearing() const;
00601     int minRightBearing() const;
00602 
00603     const char *name() const;
00604 
00605     bool canRender( const QChar *string,  int len );
00606 
00607     Type type() const;
00608 
00609     enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 };
00610     unsigned char widthCache[widthCacheSize];
00611 };
00612 
00613 #if 0
00614 class QFontEngineUniscribe : public QFontEngineWin
00615 {
00616 public:
00617     void draw( QPainter *p, int x, int y, const QTextEngine *engine, const QScriptItem *si, int textFlags );
00618     bool canRender( const QChar *string,  int len );
00619 
00620     Type type() const;
00621 };
00622 #endif
00623 
00624 #endif // Q_WS_WIN
00625 
00626 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'