src/gui/text/qfontengine_p.h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QFONTENGINE_P_H
       
    43 #define QFONTENGINE_P_H
       
    44 
       
    45 //
       
    46 //  W A R N I N G
       
    47 //  -------------
       
    48 //
       
    49 // This file is not part of the Qt API.  It exists purely as an
       
    50 // implementation detail.  This header file may change from version to
       
    51 // version without notice, or even be removed.
       
    52 //
       
    53 // We mean it.
       
    54 //
       
    55 
       
    56 #include "QtCore/qglobal.h"
       
    57 #include "QtCore/qatomic.h"
       
    58 #include <QtCore/qvarlengtharray.h>
       
    59 #include "private/qtextengine_p.h"
       
    60 #include "private/qfont_p.h"
       
    61 
       
    62 #ifdef Q_WS_WIN
       
    63 #   include "QtCore/qt_windows.h"
       
    64 #endif
       
    65 
       
    66 #ifdef Q_WS_MAC
       
    67 #   include "private/qt_mac_p.h"
       
    68 #   include "QtCore/qmap.h"
       
    69 #   include "QtCore/qcache.h"
       
    70 #   include "private/qcore_mac_p.h"
       
    71 #endif
       
    72 
       
    73 #include <private/qfontengineglyphcache_p.h>
       
    74 
       
    75 struct glyph_metrics_t;
       
    76 typedef unsigned int glyph_t;
       
    77 
       
    78 QT_BEGIN_NAMESPACE
       
    79 
       
    80 class QChar;
       
    81 class QPainterPath;
       
    82 
       
    83 class QTextEngine;
       
    84 struct QGlyphLayout;
       
    85 
       
    86 #define MAKE_TAG(ch1, ch2, ch3, ch4) (\
       
    87     (((quint32)(ch1)) << 24) | \
       
    88     (((quint32)(ch2)) << 16) | \
       
    89     (((quint32)(ch3)) << 8) | \
       
    90     ((quint32)(ch4)) \
       
    91    )
       
    92 
       
    93 
       
    94 class Q_GUI_EXPORT QFontEngine : public QObject
       
    95 {
       
    96 public:
       
    97     enum Type {
       
    98         Box,
       
    99         Multi,
       
   100 
       
   101         // X11 types
       
   102         XLFD,
       
   103 
       
   104         // MS Windows types
       
   105         Win,
       
   106 
       
   107         // Apple Mac OS types
       
   108         Mac,
       
   109 
       
   110         // QWS types
       
   111         Freetype,
       
   112         QPF1,
       
   113         QPF2,
       
   114         Proxy,
       
   115 
       
   116         // S60 types
       
   117         S60FontEngine, // Cannot be simply called "S60". Reason is qt_s60Data.h
       
   118 
       
   119         TestFontEngine = 0x1000
       
   120     };
       
   121 
       
   122     QFontEngine();
       
   123     virtual ~QFontEngine();
       
   124 
       
   125     // all of these are in unscaled metrics if the engine supports uncsaled metrics,
       
   126     // otherwise in design metrics
       
   127     struct Properties {
       
   128         QByteArray postscriptName;
       
   129         QByteArray copyright;
       
   130         QRectF boundingBox;
       
   131         QFixed emSquare;
       
   132         QFixed ascent;
       
   133         QFixed descent;
       
   134         QFixed leading;
       
   135         QFixed italicAngle;
       
   136         QFixed capHeight;
       
   137         QFixed lineWidth;
       
   138     };
       
   139     virtual Properties properties() const;
       
   140     virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
       
   141     QByteArray getSfntTable(uint /*tag*/) const;
       
   142     virtual bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const { return false; }
       
   143 
       
   144     struct FaceId {
       
   145         FaceId() : index(0), encoding(0) {}
       
   146         QByteArray filename;
       
   147         int index;
       
   148         int encoding;
       
   149     };
       
   150     virtual FaceId faceId() const { return FaceId(); }
       
   151     enum SynthesizedFlags {
       
   152         SynthesizedItalic = 0x1,
       
   153         SynthesizedBold = 0x2,
       
   154         SynthesizedStretch = 0x4
       
   155     };
       
   156     virtual int synthesized() const { return 0; }
       
   157 
       
   158     virtual QFixed emSquareSize() const { return ascent(); }
       
   159 
       
   160     /* returns 0 as glyph index for non existant glyphs */
       
   161     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const = 0;
       
   162 
       
   163     /**
       
   164      * This is a callback from harfbuzz. The font engine uses the font-system in use to find out the
       
   165      * advances of each glyph and set it on the layout.
       
   166      */
       
   167     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const {}
       
   168     virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   169 
       
   170 #if !defined(Q_WS_X11) && !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
       
   171     virtual void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si) = 0;
       
   172 #endif
       
   173     virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int nglyphs,
       
   174                                  QPainterPath *path, QTextItem::RenderFlags flags);
       
   175     void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags,
       
   176                            QVarLengthArray<glyph_t> &glyphs_out, QVarLengthArray<QFixedPoint> &positions);
       
   177 
       
   178     virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags);
       
   179     void addBitmapFontToPath(qreal x, qreal y, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags);
       
   180     /**
       
   181      * Create a qimage with the alpha values for the glyph.
       
   182      * Returns an image indexed_8 with index values ranging from 0=fully transparant to 255=opaque
       
   183      */
       
   184     virtual QImage alphaMapForGlyph(glyph_t);
       
   185     virtual QImage alphaMapForGlyph(glyph_t, const QTransform &t);
       
   186     virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
       
   187 
       
   188     virtual void removeGlyphFromCache(glyph_t);
       
   189 
       
   190     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs) = 0;
       
   191     virtual glyph_metrics_t boundingBox(glyph_t glyph) = 0;
       
   192     virtual glyph_metrics_t boundingBox(glyph_t glyph, const QTransform &matrix);
       
   193     glyph_metrics_t tightBoundingBox(const QGlyphLayout &glyphs);
       
   194 
       
   195     virtual QFixed ascent() const = 0;
       
   196     virtual QFixed descent() const = 0;
       
   197     virtual QFixed leading() const = 0;
       
   198     virtual QFixed xHeight() const;
       
   199     virtual QFixed averageCharWidth() const;
       
   200 
       
   201     virtual QFixed lineThickness() const;
       
   202     virtual QFixed underlinePosition() const;
       
   203 
       
   204     virtual qreal maxCharWidth() const = 0;
       
   205     virtual qreal minLeftBearing() const { return qreal(); }
       
   206     virtual qreal minRightBearing() const { return qreal(); }
       
   207 
       
   208     virtual const char *name() const = 0;
       
   209 
       
   210     virtual bool canRender(const QChar *string, int len) = 0;
       
   211 
       
   212     virtual Type type() const = 0;
       
   213 
       
   214     virtual int glyphCount() const;
       
   215 
       
   216     HB_Font harfbuzzFont() const;
       
   217     HB_Face harfbuzzFace() const;
       
   218 
       
   219     virtual HB_Error getPointInOutline(HB_Glyph glyph, int flags, hb_uint32 point, HB_Fixed *xpos, HB_Fixed *ypos, hb_uint32 *nPoints);
       
   220 
       
   221     void setGlyphCache(void *key, QFontEngineGlyphCache *data);
       
   222     void setGlyphCache(QFontEngineGlyphCache::Type key, QFontEngineGlyphCache *data);
       
   223     QFontEngineGlyphCache *glyphCache(void *key, const QTransform &transform) const;
       
   224     QFontEngineGlyphCache *glyphCache(QFontEngineGlyphCache::Type key, const QTransform &transform) const;
       
   225 
       
   226     static const uchar *getCMap(const uchar *table, uint tableSize, bool *isSymbolFont, int *cmapSize);
       
   227     static quint32 getTrueTypeGlyphIndex(const uchar *cmap, uint unicode);
       
   228 
       
   229     QAtomicInt ref;
       
   230     QFontDef fontDef;
       
   231     uint cache_cost; // amount of mem used in kb by the font
       
   232     int cache_count;
       
   233     uint fsType : 16;
       
   234     bool symbol;
       
   235     mutable HB_FontRec hbFont;
       
   236     mutable HB_Face hbFace;
       
   237 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
       
   238     struct KernPair {
       
   239         uint left_right;
       
   240         QFixed adjust;
       
   241 
       
   242         inline bool operator<(const KernPair &other) const
       
   243         {
       
   244             return left_right < other.left_right;
       
   245         }
       
   246     };
       
   247     QVector<KernPair> kerning_pairs;
       
   248     void loadKerningPairs(QFixed scalingFactor);
       
   249 #endif
       
   250 
       
   251     int glyphFormat;
       
   252 
       
   253 protected:
       
   254     static const QVector<QRgb> &grayPalette();
       
   255 
       
   256 private:
       
   257     /// remove old entries from the glyph cache. Helper method for the setGlyphCache ones.
       
   258     void expireGlyphCache();
       
   259 
       
   260     GlyphPointerHash m_glyphPointerHash;
       
   261     GlyphIntHash m_glyphIntHash;
       
   262     mutable QList<QFontEngineGlyphCache*> m_glyphCacheQueue;
       
   263 };
       
   264 
       
   265 inline bool operator ==(const QFontEngine::FaceId &f1, const QFontEngine::FaceId &f2)
       
   266 {
       
   267     return (f1.index == f2.index) && (f1.encoding == f2.encoding) && (f1.filename == f2.filename);
       
   268 }
       
   269 
       
   270 inline uint qHash(const QFontEngine::FaceId &f)
       
   271 {
       
   272     return qHash((f.index << 16) + f.encoding) + qHash(f.filename);
       
   273 }
       
   274 
       
   275 
       
   276 class QGlyph;
       
   277 
       
   278 #if defined(Q_WS_QWS)
       
   279 
       
   280 #ifndef QT_NO_QWS_QPF
       
   281 
       
   282 class QFontEngineQPF1Data;
       
   283 
       
   284 class QFontEngineQPF1 : public QFontEngine
       
   285 {
       
   286 public:
       
   287     QFontEngineQPF1(const QFontDef&, const QString &fn);
       
   288    ~QFontEngineQPF1();
       
   289 
       
   290     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
       
   291     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   292 
       
   293     virtual void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
       
   294     virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
       
   295 
       
   296     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
       
   297     virtual glyph_metrics_t boundingBox(glyph_t glyph);
       
   298 
       
   299     virtual QFixed ascent() const;
       
   300     virtual QFixed descent() const;
       
   301     virtual QFixed leading() const;
       
   302     virtual qreal maxCharWidth() const;
       
   303     virtual qreal minLeftBearing() const;
       
   304     virtual qreal minRightBearing() const;
       
   305     virtual QFixed underlinePosition() const;
       
   306     virtual QFixed lineThickness() const;
       
   307 
       
   308     virtual Type type() const;
       
   309 
       
   310     virtual bool canRender(const QChar *string, int len);
       
   311     inline const char *name() const { return 0; }
       
   312     virtual QImage alphaMapForGlyph(glyph_t);
       
   313 
       
   314 
       
   315     QFontEngineQPF1Data *d;
       
   316 };
       
   317 #endif // QT_NO_QWS_QPF
       
   318 
       
   319 #endif // QWS
       
   320 
       
   321 
       
   322 class QFontEngineBox : public QFontEngine
       
   323 {
       
   324 public:
       
   325     QFontEngineBox(int size);
       
   326     ~QFontEngineBox();
       
   327 
       
   328     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
       
   329     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   330 
       
   331 #if !defined(Q_WS_X11) && !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
       
   332     void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
       
   333 #endif
       
   334     virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
       
   335 
       
   336     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
       
   337     virtual glyph_metrics_t boundingBox(glyph_t glyph);
       
   338 
       
   339     virtual QFixed ascent() const;
       
   340     virtual QFixed descent() const;
       
   341     virtual QFixed leading() const;
       
   342     virtual qreal maxCharWidth() const;
       
   343     virtual qreal minLeftBearing() const { return 0; }
       
   344     virtual qreal minRightBearing() const { return 0; }
       
   345     virtual QImage alphaMapForGlyph(glyph_t);
       
   346 
       
   347 #ifdef Q_WS_X11
       
   348     int cmap() const;
       
   349 #endif
       
   350     virtual const char *name() const;
       
   351 
       
   352     virtual bool canRender(const QChar *string, int len);
       
   353 
       
   354     virtual Type type() const;
       
   355     inline int size() const { return _size; }
       
   356 
       
   357 private:
       
   358     friend class QFontPrivate;
       
   359     int _size;
       
   360 };
       
   361 
       
   362 class QFontEngineMulti : public QFontEngine
       
   363 {
       
   364 public:
       
   365     explicit QFontEngineMulti(int engineCount);
       
   366     ~QFontEngineMulti();
       
   367 
       
   368     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
       
   369                       QTextEngine::ShaperFlags flags) const;
       
   370 
       
   371     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
       
   372     virtual glyph_metrics_t boundingBox(glyph_t glyph);
       
   373 
       
   374     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   375     virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   376     virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags);
       
   377 
       
   378     virtual QFixed ascent() const;
       
   379     virtual QFixed descent() const;
       
   380     virtual QFixed leading() const;
       
   381     virtual QFixed xHeight() const;
       
   382     virtual QFixed averageCharWidth() const;
       
   383     virtual QImage alphaMapForGlyph(glyph_t);
       
   384 
       
   385     virtual QFixed lineThickness() const;
       
   386     virtual QFixed underlinePosition() const;
       
   387     virtual qreal maxCharWidth() const;
       
   388     virtual qreal minLeftBearing() const;
       
   389     virtual qreal minRightBearing() const;
       
   390 
       
   391     virtual inline Type type() const
       
   392     { return QFontEngine::Multi; }
       
   393 
       
   394     virtual bool canRender(const QChar *string, int len);
       
   395     inline virtual const char *name() const
       
   396     { return "Multi"; }
       
   397 
       
   398     QFontEngine *engine(int at) const
       
   399     {Q_ASSERT(at < engines.size()); return engines.at(at); }
       
   400 
       
   401 
       
   402 protected:
       
   403     friend class QPSPrintEnginePrivate;
       
   404     friend class QPSPrintEngineFontMulti;
       
   405     virtual void loadEngine(int at) = 0;
       
   406     QVector<QFontEngine *> engines;
       
   407 };
       
   408 
       
   409 #if defined(Q_WS_MAC)
       
   410 
       
   411 struct QCharAttributes;
       
   412 class QFontEngineMacMulti;
       
   413 #  if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
       
   414 class QCoreTextFontEngineMulti;
       
   415 class QCoreTextFontEngine : public QFontEngine
       
   416 {
       
   417 public:
       
   418     QCoreTextFontEngine(CTFontRef font, const QFontDef &def,
       
   419                         QCoreTextFontEngineMulti *multiEngine = 0);
       
   420     ~QCoreTextFontEngine();
       
   421     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
       
   422     virtual void recalcAdvances(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   423 
       
   424     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
       
   425     virtual glyph_metrics_t boundingBox(glyph_t glyph);
       
   426 
       
   427     virtual QFixed ascent() const;
       
   428     virtual QFixed descent() const;
       
   429     virtual QFixed leading() const;
       
   430     virtual QFixed xHeight() const;
       
   431     virtual qreal maxCharWidth() const;
       
   432     virtual QFixed averageCharWidth() const;
       
   433 
       
   434     virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
       
   435                                  QPainterPath *path, QTextItem::RenderFlags);
       
   436 
       
   437     virtual const char *name() const { return "QCoreTextFontEngine"; }
       
   438 
       
   439     virtual bool canRender(const QChar *string, int len);
       
   440 
       
   441     virtual int synthesized() const { return synthesisFlags; }
       
   442 
       
   443     virtual Type type() const { return QFontEngine::Mac; }
       
   444 
       
   445     void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
       
   446 
       
   447     virtual FaceId faceId() const;
       
   448     virtual bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const;
       
   449     virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
       
   450     virtual QImage alphaMapForGlyph(glyph_t);
       
   451     virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
       
   452     virtual qreal minRightBearing() const;
       
   453     virtual qreal minLeftBearing() const;
       
   454 
       
   455 
       
   456 private:
       
   457     QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
       
   458     CTFontRef ctfont;
       
   459     CGFontRef cgFont;
       
   460     QCoreTextFontEngineMulti *parentEngine;
       
   461     int synthesisFlags;
       
   462     friend class QCoreTextFontEngineMulti;
       
   463 };
       
   464 
       
   465 class QCoreTextFontEngineMulti : public QFontEngineMulti
       
   466 {
       
   467 public:
       
   468     QCoreTextFontEngineMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef,
       
   469                              const QFontDef &fontDef, bool kerning);
       
   470     ~QCoreTextFontEngineMulti();
       
   471 
       
   472     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
       
   473                               QTextEngine::ShaperFlags flags) const;
       
   474     bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
       
   475                       QTextEngine::ShaperFlags flags,
       
   476                       unsigned short *logClusters, const HB_CharAttributes *charAttributes) const;
       
   477 
       
   478 
       
   479     virtual void recalcAdvances(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   480     virtual void doKerning(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   481 
       
   482     virtual const char *name() const { return "CoreText"; }
       
   483 protected:
       
   484     virtual void loadEngine(int at);
       
   485 
       
   486 private:
       
   487     inline const QCoreTextFontEngine *engineAt(int i) const
       
   488     { return static_cast<const QCoreTextFontEngine *>(engines.at(i)); }
       
   489 
       
   490     uint fontIndexForFont(CTFontRef id) const;
       
   491     CTFontRef ctfont;
       
   492     mutable QCFType<CFMutableDictionaryRef> attributeDict;
       
   493 
       
   494     friend class QFontDialogPrivate;
       
   495 };
       
   496 #  endif //MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
       
   497 
       
   498 #ifndef QT_MAC_USE_COCOA
       
   499 class QFontEngineMac : public QFontEngine
       
   500 {
       
   501     friend class QFontEngineMacMulti;
       
   502 public:
       
   503     QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine = 0);
       
   504     virtual ~QFontEngineMac();
       
   505 
       
   506     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *numGlyphs, QTextEngine::ShaperFlags flags) const;
       
   507     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   508 
       
   509     virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
       
   510     virtual glyph_metrics_t boundingBox(glyph_t glyph);
       
   511 
       
   512     virtual QFixed ascent() const;
       
   513     virtual QFixed descent() const;
       
   514     virtual QFixed leading() const;
       
   515     virtual QFixed xHeight() const;
       
   516     virtual qreal maxCharWidth() const;
       
   517     virtual QFixed averageCharWidth() const;
       
   518 
       
   519     virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
       
   520                                  QPainterPath *path, QTextItem::RenderFlags);
       
   521 
       
   522     virtual const char *name() const { return "QFontEngineMac"; }
       
   523 
       
   524     virtual bool canRender(const QChar *string, int len);
       
   525 
       
   526     virtual int synthesized() const { return synthesisFlags; }
       
   527 
       
   528     virtual Type type() const { return QFontEngine::Mac; }
       
   529 
       
   530     void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
       
   531 
       
   532     virtual FaceId faceId() const;
       
   533     virtual QByteArray getSfntTable(uint tag) const;
       
   534     virtual Properties properties() const;
       
   535     virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
       
   536     virtual QImage alphaMapForGlyph(glyph_t);
       
   537     virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
       
   538 
       
   539 private:
       
   540     QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
       
   541 
       
   542     ATSUFontID fontID;
       
   543     QCFType<CGFontRef> cgFont;
       
   544     ATSUStyle style;
       
   545     int synthesisFlags;
       
   546     mutable QGlyphLayout kashidaGlyph;
       
   547     QFontEngineMacMulti *multiEngine;
       
   548     mutable const unsigned char *cmap;
       
   549     mutable bool symbolCMap;
       
   550     mutable QByteArray cmapTable;
       
   551     CGAffineTransform transform;
       
   552     QFixed m_ascent;
       
   553     QFixed m_descent;
       
   554     QFixed m_leading;
       
   555     qreal m_maxCharWidth;
       
   556     QFixed m_xHeight;
       
   557     QFixed m_averageCharWidth;
       
   558 };
       
   559 
       
   560 class QFontEngineMacMulti : public QFontEngineMulti
       
   561 {
       
   562     friend class QFontEngineMac;
       
   563 public:
       
   564     // internal
       
   565     struct ShaperItem
       
   566     {
       
   567         inline ShaperItem() : string(0), from(0), length(0),
       
   568         log_clusters(0), charAttributes(0) {}
       
   569 
       
   570         const QChar *string;
       
   571         int from;
       
   572         int length;
       
   573         QGlyphLayout glyphs;
       
   574         unsigned short *log_clusters;
       
   575         const HB_CharAttributes *charAttributes;
       
   576         QTextEngine::ShaperFlags flags;
       
   577     };
       
   578 
       
   579     QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning);
       
   580     virtual ~QFontEngineMacMulti();
       
   581 
       
   582     virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
       
   583     bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,
       
   584                       unsigned short *logClusters, const HB_CharAttributes *charAttributes) const;
       
   585 
       
   586     virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   587     virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
       
   588 
       
   589     virtual const char *name() const { return "ATSUI"; }
       
   590 
       
   591     virtual bool canRender(const QChar *string, int len);
       
   592 
       
   593     inline ATSUFontID macFontID() const { return fontID; }
       
   594 
       
   595 protected:
       
   596     virtual void loadEngine(int at);
       
   597 
       
   598 private:
       
   599     inline const QFontEngineMac *engineAt(int i) const
       
   600     { return static_cast<const QFontEngineMac *>(engines.at(i)); }
       
   601 
       
   602     bool stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const;
       
   603 
       
   604     int fontIndexForFontID(ATSUFontID id) const;
       
   605 
       
   606     ATSUFontID fontID;
       
   607     uint kerning : 1;
       
   608 
       
   609     mutable ATSUTextLayout textLayout;
       
   610     mutable ATSUStyle style;
       
   611     CGAffineTransform transform;
       
   612 };
       
   613 #endif //!QT_MAC_USE_COCOA
       
   614 #endif
       
   615 
       
   616 class QTestFontEngine : public QFontEngineBox
       
   617 {
       
   618 public:
       
   619     QTestFontEngine(int size) : QFontEngineBox(size) {}
       
   620     virtual Type type() const { return TestFontEngine; }
       
   621 };
       
   622 
       
   623 QT_END_NAMESPACE
       
   624 
       
   625 #ifdef Q_WS_WIN
       
   626 #   include "private/qfontengine_win_p.h"
       
   627 #endif
       
   628 
       
   629 #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
       
   630 #   include "private/qfontengine_ft_p.h"
       
   631 #endif
       
   632 
       
   633 #endif // QFONTENGINE_P_H