[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 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>
|
---|
[561] | 59 | #include <QtCore/QLinkedList>
|
---|
[2] | 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 |
|
---|
[561] | 74 | #include <private/qfontengineglyphcache_p.h>
|
---|
[2] | 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 |
|
---|
[561] | 111 | // QWS types
|
---|
[2] | 112 | Freetype,
|
---|
| 113 | QPF1,
|
---|
| 114 | QPF2,
|
---|
| 115 | Proxy,
|
---|
[561] | 116 |
|
---|
| 117 | // S60 types
|
---|
| 118 | S60FontEngine, // Cannot be simply called "S60". Reason is qt_s60Data.h
|
---|
| 119 |
|
---|
[2] | 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 |
|
---|
[846] | 161 | /* returns 0 as glyph index for non existent glyphs */
|
---|
[2] | 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 |
|
---|
[561] | 171 | #if !defined(Q_WS_X11) && !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN) && !defined(Q_WS_PM)
|
---|
[2] | 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.
|
---|
[846] | 183 | * Returns an image indexed_8 with index values ranging from 0=fully transparent to 255=opaque
|
---|
[2] | 184 | */
|
---|
[561] | 185 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
[2] | 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 |
|
---|
[769] | 209 | virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
|
---|
| 210 |
|
---|
[2] | 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);
|
---|
[561] | 225 | QFontEngineGlyphCache *glyphCache(void *key, QFontEngineGlyphCache::Type type, const QTransform &transform) const;
|
---|
[2] | 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 |
|
---|
[846] | 230 | static QByteArray convertToPostscriptFontFamilyName(const QByteArray &fontFamily);
|
---|
| 231 |
|
---|
[2] | 232 | QAtomicInt ref;
|
---|
| 233 | QFontDef fontDef;
|
---|
| 234 | uint cache_cost; // amount of mem used in kb by the font
|
---|
| 235 | int cache_count;
|
---|
| 236 | uint fsType : 16;
|
---|
| 237 | bool symbol;
|
---|
| 238 | mutable HB_FontRec hbFont;
|
---|
| 239 | mutable HB_Face hbFace;
|
---|
[561] | 240 | #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN) || defined(Q_WS_PM)
|
---|
[2] | 241 | struct KernPair {
|
---|
| 242 | uint left_right;
|
---|
| 243 | QFixed adjust;
|
---|
| 244 |
|
---|
| 245 | inline bool operator<(const KernPair &other) const
|
---|
| 246 | {
|
---|
| 247 | return left_right < other.left_right;
|
---|
| 248 | }
|
---|
| 249 | };
|
---|
| 250 | QVector<KernPair> kerning_pairs;
|
---|
| 251 | void loadKerningPairs(QFixed scalingFactor);
|
---|
| 252 | #endif
|
---|
| 253 |
|
---|
| 254 | int glyphFormat;
|
---|
| 255 |
|
---|
[561] | 256 | protected:
|
---|
| 257 | static const QVector<QRgb> &grayPalette();
|
---|
[846] | 258 | QFixed lastRightBearing(const QGlyphLayout &glyphs, bool round = false);
|
---|
[561] | 259 |
|
---|
[2] | 260 | private:
|
---|
[561] | 261 | struct GlyphCacheEntry {
|
---|
| 262 | void *context;
|
---|
| 263 | QFontEngineGlyphCache *cache;
|
---|
| 264 | bool operator==(const GlyphCacheEntry &other) { return context == other.context && cache == other.cache; }
|
---|
| 265 | };
|
---|
[2] | 266 |
|
---|
[561] | 267 | mutable QLinkedList<GlyphCacheEntry> m_glyphCaches;
|
---|
[2] | 268 | };
|
---|
| 269 |
|
---|
| 270 | inline bool operator ==(const QFontEngine::FaceId &f1, const QFontEngine::FaceId &f2)
|
---|
| 271 | {
|
---|
| 272 | return (f1.index == f2.index) && (f1.encoding == f2.encoding) && (f1.filename == f2.filename);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | inline uint qHash(const QFontEngine::FaceId &f)
|
---|
| 276 | {
|
---|
| 277 | return qHash((f.index << 16) + f.encoding) + qHash(f.filename);
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 | class QGlyph;
|
---|
| 282 |
|
---|
| 283 | #if defined(Q_WS_QWS)
|
---|
| 284 |
|
---|
| 285 | #ifndef QT_NO_QWS_QPF
|
---|
| 286 |
|
---|
| 287 | class QFontEngineQPF1Data;
|
---|
| 288 |
|
---|
| 289 | class QFontEngineQPF1 : public QFontEngine
|
---|
| 290 | {
|
---|
| 291 | public:
|
---|
| 292 | QFontEngineQPF1(const QFontDef&, const QString &fn);
|
---|
| 293 | ~QFontEngineQPF1();
|
---|
| 294 |
|
---|
| 295 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
|
---|
| 296 | virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 297 |
|
---|
| 298 | virtual void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
|
---|
| 299 | virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
|
---|
| 300 |
|
---|
| 301 | virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
|
---|
| 302 | virtual glyph_metrics_t boundingBox(glyph_t glyph);
|
---|
| 303 |
|
---|
| 304 | virtual QFixed ascent() const;
|
---|
| 305 | virtual QFixed descent() const;
|
---|
| 306 | virtual QFixed leading() const;
|
---|
| 307 | virtual qreal maxCharWidth() const;
|
---|
| 308 | virtual qreal minLeftBearing() const;
|
---|
| 309 | virtual qreal minRightBearing() const;
|
---|
| 310 | virtual QFixed underlinePosition() const;
|
---|
| 311 | virtual QFixed lineThickness() const;
|
---|
| 312 |
|
---|
| 313 | virtual Type type() const;
|
---|
| 314 |
|
---|
| 315 | virtual bool canRender(const QChar *string, int len);
|
---|
| 316 | inline const char *name() const { return 0; }
|
---|
| 317 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
| 318 |
|
---|
| 319 |
|
---|
| 320 | QFontEngineQPF1Data *d;
|
---|
| 321 | };
|
---|
| 322 | #endif // QT_NO_QWS_QPF
|
---|
| 323 |
|
---|
| 324 | #endif // QWS
|
---|
| 325 |
|
---|
| 326 |
|
---|
| 327 | class QFontEngineBox : public QFontEngine
|
---|
| 328 | {
|
---|
| 329 | public:
|
---|
| 330 | QFontEngineBox(int size);
|
---|
| 331 | ~QFontEngineBox();
|
---|
| 332 |
|
---|
| 333 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
|
---|
| 334 | virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 335 |
|
---|
[561] | 336 | #if !defined(Q_WS_X11) && !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN) && !defined(Q_WS_PM)
|
---|
[2] | 337 | void draw(QPaintEngine *p, qreal x, qreal y, const QTextItemInt &si);
|
---|
| 338 | #endif
|
---|
| 339 | virtual void addOutlineToPath(qreal x, qreal y, const QGlyphLayout &glyphs, QPainterPath *path, QTextItem::RenderFlags flags);
|
---|
| 340 |
|
---|
| 341 | virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
|
---|
| 342 | virtual glyph_metrics_t boundingBox(glyph_t glyph);
|
---|
| 343 |
|
---|
| 344 | virtual QFixed ascent() const;
|
---|
| 345 | virtual QFixed descent() const;
|
---|
| 346 | virtual QFixed leading() const;
|
---|
| 347 | virtual qreal maxCharWidth() const;
|
---|
| 348 | virtual qreal minLeftBearing() const { return 0; }
|
---|
| 349 | virtual qreal minRightBearing() const { return 0; }
|
---|
| 350 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
| 351 |
|
---|
| 352 | #ifdef Q_WS_X11
|
---|
| 353 | int cmap() const;
|
---|
| 354 | #endif
|
---|
| 355 | virtual const char *name() const;
|
---|
| 356 |
|
---|
| 357 | virtual bool canRender(const QChar *string, int len);
|
---|
| 358 |
|
---|
| 359 | virtual Type type() const;
|
---|
| 360 | inline int size() const { return _size; }
|
---|
| 361 |
|
---|
| 362 | private:
|
---|
| 363 | friend class QFontPrivate;
|
---|
| 364 | int _size;
|
---|
| 365 | };
|
---|
| 366 |
|
---|
[561] | 367 | class QFontEngineMulti : public QFontEngine
|
---|
[2] | 368 | {
|
---|
| 369 | public:
|
---|
| 370 | explicit QFontEngineMulti(int engineCount);
|
---|
| 371 | ~QFontEngineMulti();
|
---|
| 372 |
|
---|
| 373 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
|
---|
| 374 | QTextEngine::ShaperFlags flags) const;
|
---|
| 375 |
|
---|
| 376 | virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
|
---|
| 377 | virtual glyph_metrics_t boundingBox(glyph_t glyph);
|
---|
| 378 |
|
---|
| 379 | virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 380 | virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 381 | virtual void addOutlineToPath(qreal, qreal, const QGlyphLayout &, QPainterPath *, QTextItem::RenderFlags flags);
|
---|
[769] | 382 | virtual void getGlyphBearings(glyph_t glyph, qreal *leftBearing = 0, qreal *rightBearing = 0);
|
---|
[2] | 383 |
|
---|
| 384 | virtual QFixed ascent() const;
|
---|
| 385 | virtual QFixed descent() const;
|
---|
| 386 | virtual QFixed leading() const;
|
---|
| 387 | virtual QFixed xHeight() const;
|
---|
| 388 | virtual QFixed averageCharWidth() const;
|
---|
| 389 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
| 390 |
|
---|
| 391 | virtual QFixed lineThickness() const;
|
---|
| 392 | virtual QFixed underlinePosition() const;
|
---|
| 393 | virtual qreal maxCharWidth() const;
|
---|
| 394 | virtual qreal minLeftBearing() const;
|
---|
| 395 | virtual qreal minRightBearing() const;
|
---|
| 396 |
|
---|
| 397 | virtual inline Type type() const
|
---|
| 398 | { return QFontEngine::Multi; }
|
---|
| 399 |
|
---|
| 400 | virtual bool canRender(const QChar *string, int len);
|
---|
| 401 | inline virtual const char *name() const
|
---|
| 402 | { return "Multi"; }
|
---|
| 403 |
|
---|
[561] | 404 | QFontEngine *engine(int at) const
|
---|
| 405 | {Q_ASSERT(at < engines.size()); return engines.at(at); }
|
---|
[2] | 406 |
|
---|
[561] | 407 |
|
---|
[2] | 408 | protected:
|
---|
| 409 | friend class QPSPrintEnginePrivate;
|
---|
| 410 | friend class QPSPrintEngineFontMulti;
|
---|
| 411 | virtual void loadEngine(int at) = 0;
|
---|
| 412 | QVector<QFontEngine *> engines;
|
---|
| 413 | };
|
---|
| 414 |
|
---|
| 415 | #if defined(Q_WS_MAC)
|
---|
| 416 |
|
---|
| 417 | struct QCharAttributes;
|
---|
| 418 | class QFontEngineMacMulti;
|
---|
| 419 | # if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
---|
| 420 | class QCoreTextFontEngineMulti;
|
---|
| 421 | class QCoreTextFontEngine : public QFontEngine
|
---|
| 422 | {
|
---|
| 423 | public:
|
---|
| 424 | QCoreTextFontEngine(CTFontRef font, const QFontDef &def,
|
---|
| 425 | QCoreTextFontEngineMulti *multiEngine = 0);
|
---|
| 426 | ~QCoreTextFontEngine();
|
---|
| 427 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
|
---|
| 428 | virtual void recalcAdvances(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 429 |
|
---|
| 430 | virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
|
---|
| 431 | virtual glyph_metrics_t boundingBox(glyph_t glyph);
|
---|
| 432 |
|
---|
| 433 | virtual QFixed ascent() const;
|
---|
| 434 | virtual QFixed descent() const;
|
---|
| 435 | virtual QFixed leading() const;
|
---|
| 436 | virtual QFixed xHeight() const;
|
---|
| 437 | virtual qreal maxCharWidth() const;
|
---|
| 438 | virtual QFixed averageCharWidth() const;
|
---|
| 439 |
|
---|
| 440 | virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
|
---|
| 441 | QPainterPath *path, QTextItem::RenderFlags);
|
---|
| 442 |
|
---|
| 443 | virtual const char *name() const { return "QCoreTextFontEngine"; }
|
---|
| 444 |
|
---|
| 445 | virtual bool canRender(const QChar *string, int len);
|
---|
| 446 |
|
---|
| 447 | virtual int synthesized() const { return synthesisFlags; }
|
---|
| 448 |
|
---|
| 449 | virtual Type type() const { return QFontEngine::Mac; }
|
---|
| 450 |
|
---|
| 451 | void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
|
---|
| 452 |
|
---|
| 453 | virtual FaceId faceId() const;
|
---|
| 454 | virtual bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const;
|
---|
| 455 | virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
|
---|
| 456 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
[561] | 457 | virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
|
---|
[2] | 458 | virtual qreal minRightBearing() const;
|
---|
| 459 | virtual qreal minLeftBearing() const;
|
---|
| 460 |
|
---|
| 461 |
|
---|
| 462 | private:
|
---|
[561] | 463 | QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
|
---|
[2] | 464 | CTFontRef ctfont;
|
---|
| 465 | CGFontRef cgFont;
|
---|
| 466 | QCoreTextFontEngineMulti *parentEngine;
|
---|
| 467 | int synthesisFlags;
|
---|
[846] | 468 | CGAffineTransform transform;
|
---|
[2] | 469 | friend class QCoreTextFontEngineMulti;
|
---|
| 470 | };
|
---|
| 471 |
|
---|
| 472 | class QCoreTextFontEngineMulti : public QFontEngineMulti
|
---|
| 473 | {
|
---|
| 474 | public:
|
---|
| 475 | QCoreTextFontEngineMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef,
|
---|
| 476 | const QFontDef &fontDef, bool kerning);
|
---|
| 477 | ~QCoreTextFontEngineMulti();
|
---|
| 478 |
|
---|
| 479 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
|
---|
| 480 | QTextEngine::ShaperFlags flags) const;
|
---|
| 481 | bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs,
|
---|
| 482 | QTextEngine::ShaperFlags flags,
|
---|
| 483 | unsigned short *logClusters, const HB_CharAttributes *charAttributes) const;
|
---|
| 484 |
|
---|
| 485 |
|
---|
| 486 | virtual void recalcAdvances(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 487 | virtual void doKerning(int , QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 488 |
|
---|
| 489 | virtual const char *name() const { return "CoreText"; }
|
---|
| 490 | protected:
|
---|
| 491 | virtual void loadEngine(int at);
|
---|
| 492 |
|
---|
| 493 | private:
|
---|
| 494 | inline const QCoreTextFontEngine *engineAt(int i) const
|
---|
| 495 | { return static_cast<const QCoreTextFontEngine *>(engines.at(i)); }
|
---|
| 496 |
|
---|
| 497 | uint fontIndexForFont(CTFontRef id) const;
|
---|
| 498 | CTFontRef ctfont;
|
---|
| 499 | mutable QCFType<CFMutableDictionaryRef> attributeDict;
|
---|
[846] | 500 | CGAffineTransform transform;
|
---|
[2] | 501 | friend class QFontDialogPrivate;
|
---|
| 502 | };
|
---|
| 503 | # endif //MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
|
---|
| 504 |
|
---|
| 505 | #ifndef QT_MAC_USE_COCOA
|
---|
| 506 | class QFontEngineMac : public QFontEngine
|
---|
| 507 | {
|
---|
| 508 | friend class QFontEngineMacMulti;
|
---|
| 509 | public:
|
---|
| 510 | QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine = 0);
|
---|
| 511 | virtual ~QFontEngineMac();
|
---|
| 512 |
|
---|
| 513 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *numGlyphs, QTextEngine::ShaperFlags flags) const;
|
---|
| 514 | virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 515 |
|
---|
| 516 | virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs);
|
---|
| 517 | virtual glyph_metrics_t boundingBox(glyph_t glyph);
|
---|
| 518 |
|
---|
| 519 | virtual QFixed ascent() const;
|
---|
| 520 | virtual QFixed descent() const;
|
---|
| 521 | virtual QFixed leading() const;
|
---|
| 522 | virtual QFixed xHeight() const;
|
---|
| 523 | virtual qreal maxCharWidth() const;
|
---|
| 524 | virtual QFixed averageCharWidth() const;
|
---|
| 525 |
|
---|
| 526 | virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
|
---|
| 527 | QPainterPath *path, QTextItem::RenderFlags);
|
---|
| 528 |
|
---|
| 529 | virtual const char *name() const { return "QFontEngineMac"; }
|
---|
| 530 |
|
---|
| 531 | virtual bool canRender(const QChar *string, int len);
|
---|
| 532 |
|
---|
| 533 | virtual int synthesized() const { return synthesisFlags; }
|
---|
| 534 |
|
---|
| 535 | virtual Type type() const { return QFontEngine::Mac; }
|
---|
| 536 |
|
---|
| 537 | void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
|
---|
| 538 |
|
---|
| 539 | virtual FaceId faceId() const;
|
---|
| 540 | virtual QByteArray getSfntTable(uint tag) const;
|
---|
| 541 | virtual Properties properties() const;
|
---|
| 542 | virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics);
|
---|
| 543 | virtual QImage alphaMapForGlyph(glyph_t);
|
---|
[561] | 544 | virtual QImage alphaRGBMapForGlyph(glyph_t, int margin, const QTransform &t);
|
---|
[2] | 545 |
|
---|
| 546 | private:
|
---|
[561] | 547 | QImage imageForGlyph(glyph_t glyph, int margin, bool colorful);
|
---|
| 548 |
|
---|
[2] | 549 | ATSUFontID fontID;
|
---|
| 550 | QCFType<CGFontRef> cgFont;
|
---|
| 551 | ATSUStyle style;
|
---|
| 552 | int synthesisFlags;
|
---|
| 553 | mutable QGlyphLayout kashidaGlyph;
|
---|
| 554 | QFontEngineMacMulti *multiEngine;
|
---|
| 555 | mutable const unsigned char *cmap;
|
---|
| 556 | mutable bool symbolCMap;
|
---|
| 557 | mutable QByteArray cmapTable;
|
---|
| 558 | CGAffineTransform transform;
|
---|
| 559 | QFixed m_ascent;
|
---|
| 560 | QFixed m_descent;
|
---|
| 561 | QFixed m_leading;
|
---|
| 562 | qreal m_maxCharWidth;
|
---|
| 563 | QFixed m_xHeight;
|
---|
| 564 | QFixed m_averageCharWidth;
|
---|
| 565 | };
|
---|
| 566 |
|
---|
| 567 | class QFontEngineMacMulti : public QFontEngineMulti
|
---|
| 568 | {
|
---|
| 569 | friend class QFontEngineMac;
|
---|
| 570 | public:
|
---|
| 571 | // internal
|
---|
| 572 | struct ShaperItem
|
---|
| 573 | {
|
---|
| 574 | inline ShaperItem() : string(0), from(0), length(0),
|
---|
| 575 | log_clusters(0), charAttributes(0) {}
|
---|
| 576 |
|
---|
| 577 | const QChar *string;
|
---|
| 578 | int from;
|
---|
| 579 | int length;
|
---|
| 580 | QGlyphLayout glyphs;
|
---|
| 581 | unsigned short *log_clusters;
|
---|
| 582 | const HB_CharAttributes *charAttributes;
|
---|
| 583 | QTextEngine::ShaperFlags flags;
|
---|
| 584 | };
|
---|
| 585 |
|
---|
| 586 | QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning);
|
---|
| 587 | virtual ~QFontEngineMacMulti();
|
---|
| 588 |
|
---|
| 589 | virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const;
|
---|
| 590 | bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags,
|
---|
| 591 | unsigned short *logClusters, const HB_CharAttributes *charAttributes) const;
|
---|
| 592 |
|
---|
| 593 | virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 594 | virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const;
|
---|
| 595 |
|
---|
| 596 | virtual const char *name() const { return "ATSUI"; }
|
---|
| 597 |
|
---|
| 598 | virtual bool canRender(const QChar *string, int len);
|
---|
| 599 |
|
---|
| 600 | inline ATSUFontID macFontID() const { return fontID; }
|
---|
| 601 |
|
---|
| 602 | protected:
|
---|
| 603 | virtual void loadEngine(int at);
|
---|
| 604 |
|
---|
| 605 | private:
|
---|
| 606 | inline const QFontEngineMac *engineAt(int i) const
|
---|
| 607 | { return static_cast<const QFontEngineMac *>(engines.at(i)); }
|
---|
| 608 |
|
---|
| 609 | bool stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const;
|
---|
| 610 |
|
---|
| 611 | int fontIndexForFontID(ATSUFontID id) const;
|
---|
| 612 |
|
---|
| 613 | ATSUFontID fontID;
|
---|
| 614 | uint kerning : 1;
|
---|
| 615 |
|
---|
| 616 | mutable ATSUTextLayout textLayout;
|
---|
| 617 | mutable ATSUStyle style;
|
---|
| 618 | CGAffineTransform transform;
|
---|
| 619 | };
|
---|
| 620 | #endif //!QT_MAC_USE_COCOA
|
---|
| 621 | #endif
|
---|
| 622 |
|
---|
| 623 | class QTestFontEngine : public QFontEngineBox
|
---|
| 624 | {
|
---|
| 625 | public:
|
---|
| 626 | QTestFontEngine(int size) : QFontEngineBox(size) {}
|
---|
| 627 | virtual Type type() const { return TestFontEngine; }
|
---|
| 628 | };
|
---|
| 629 |
|
---|
| 630 | QT_END_NAMESPACE
|
---|
| 631 |
|
---|
| 632 | #ifdef Q_WS_WIN
|
---|
| 633 | # include "private/qfontengine_win_p.h"
|
---|
| 634 | #endif
|
---|
| 635 |
|
---|
[561] | 636 | #if defined(Q_OS_SYMBIAN) && !defined(QT_NO_FREETYPE)
|
---|
| 637 | # include "private/qfontengine_ft_p.h"
|
---|
| 638 | #endif
|
---|
| 639 |
|
---|
[2] | 640 | #endif // QFONTENGINE_P_H
|
---|