1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtGui module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QFONTENGINE_MAC_P_H 43 #define QFONTENGINE_MAC_P_H 44 45 #include <private/qfontengine_p.h> 46 47 #ifndef QT_MAC_USE_COCOA 48 49 QT_BEGIN_NAMESPACE 50 51 class QFontEngineMacMulti; 52 class QFontEngineMac : public QFontEngine 53 { 54 friend class QFontEngineMacMulti; 55 public: 56 QFontEngineMac(ATSUStyle baseStyle, ATSUFontID fontID, const QFontDef &def, QFontEngineMacMulti *multiEngine = 0); 57 virtual ~QFontEngineMac(); 58 59 virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *numGlyphs, QTextEngine::ShaperFlags flags) const; 60 virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const; 61 62 virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs); 63 virtual glyph_metrics_t boundingBox(glyph_t glyph); 64 65 virtual QFixed ascent() const; 66 virtual QFixed descent() const; 67 virtual QFixed leading() const; 68 virtual QFixed xHeight() const; 69 virtual qreal maxCharWidth() const; 70 virtual QFixed averageCharWidth() const; 71 72 virtual void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs, 73 QPainterPath *path, QTextItem::RenderFlags); 74 name()75 virtual const char *name() const { return "QFontEngineMac"; } 76 77 virtual bool canRender(const QChar *string, int len); 78 synthesized()79 virtual int synthesized() const { return synthesisFlags; } 80 type()81 virtual Type type() const { return QFontEngine::Mac; } 82 83 void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight); 84 85 virtual FaceId faceId() const; 86 virtual QByteArray getSfntTable(uint tag) const; 87 virtual Properties properties() const; 88 virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics); 89 virtual QImage alphaMapForGlyph(glyph_t); 90 virtual QImage alphaRGBMapForGlyph(glyph_t, QFixed subPixelPosition, int margin, const QTransform &t); 91 92 private: 93 QImage imageForGlyph(glyph_t glyph, int margin, bool colorful); 94 95 ATSUFontID fontID; 96 QCFType<CGFontRef> cgFont; 97 ATSUStyle style; 98 int synthesisFlags; 99 mutable QGlyphLayout kashidaGlyph; 100 QFontEngineMacMulti *multiEngine; 101 mutable const unsigned char *cmap; 102 mutable bool symbolCMap; 103 mutable QByteArray cmapTable; 104 CGAffineTransform transform; 105 QFixed m_ascent; 106 QFixed m_descent; 107 QFixed m_leading; 108 qreal m_maxCharWidth; 109 QFixed m_xHeight; 110 QFixed m_averageCharWidth; 111 mutable int cmapSize; 112 }; 113 114 class QFontEngineMacMulti : public QFontEngineMulti 115 { 116 friend class QFontEngineMac; 117 public: 118 // internal 119 struct ShaperItem 120 { ShaperItemShaperItem121 inline ShaperItem() : string(0), from(0), length(0), 122 log_clusters(0), charAttributes(0) {} 123 124 const QChar *string; 125 int from; 126 int length; 127 QGlyphLayout glyphs; 128 unsigned short *log_clusters; 129 const HB_CharAttributes *charAttributes; 130 QTextEngine::ShaperFlags flags; 131 }; 132 133 QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning); 134 virtual ~QFontEngineMacMulti(); 135 136 virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const; 137 bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, 138 unsigned short *logClusters, const HB_CharAttributes *charAttributes, QScriptItem *) const; 139 140 virtual void recalcAdvances(QGlyphLayout *, QTextEngine::ShaperFlags) const; 141 virtual void doKerning(QGlyphLayout *, QTextEngine::ShaperFlags) const; 142 name()143 virtual const char *name() const { return "ATSUI"; } 144 145 virtual bool canRender(const QChar *string, int len); 146 macFontID()147 inline ATSUFontID macFontID() const { return fontID; } 148 149 protected: 150 virtual void loadEngine(int at); 151 152 private: engineAt(int i)153 inline const QFontEngineMac *engineAt(int i) const 154 { return static_cast<const QFontEngineMac *>(engines.at(i)); } 155 156 bool stringToCMapInternal(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags, ShaperItem *item) const; 157 158 int fontIndexForFontID(ATSUFontID id) const; 159 160 ATSUFontID fontID; 161 uint kerning : 1; 162 163 mutable ATSUTextLayout textLayout; 164 mutable ATSUStyle style; 165 CGAffineTransform transform; 166 }; 167 168 QT_END_NAMESPACE 169 170 #endif //!QT_MAC_USE_COCOA 171 172 #endif // QFONTENGINE_MAC_P_H 173