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