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