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