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