Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfontengine_coretext_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFONTENGINE_CORETEXT_P_H
5#define QFONTENGINE_CORETEXT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <private/qfontengine_p.h>
19#include <private/qcore_mac_p.h>
20#include <QtCore/qloggingcategory.h>
21
22#ifdef Q_OS_MACOS
23#include <ApplicationServices/ApplicationServices.h>
24#else
25#include <CoreText/CoreText.h>
26#include <CoreGraphics/CoreGraphics.h>
27#endif
28
30
31class Q_GUI_EXPORT QCoreTextFontEngine : public QFontEngine
32{
33 Q_GADGET
34
35public:
36 QCoreTextFontEngine(CTFontRef font, const QFontDef &def);
37 QCoreTextFontEngine(CGFontRef font, const QFontDef &def);
38 ~QCoreTextFontEngine();
39
40 int glyphCount() const override;
41 glyph_t glyphIndex(uint ucs4) const override;
42 QString glyphName(glyph_t index) const override;
43 glyph_t findGlyph(QLatin1StringView name) const override;
44 int stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, ShaperFlags flags) const override;
45 void recalcAdvances(QGlyphLayout *, ShaperFlags) const override;
46
47 glyph_metrics_t boundingBox(glyph_t glyph) override;
48
49 QFixed capHeight() const override;
50 QFixed xHeight() const override;
51 qreal maxCharWidth() const override;
52 QFixed averageCharWidth() const override;
53
54 void addGlyphsToPath(glyph_t *glyphs, QFixedPoint *positions, int numGlyphs,
55 QPainterPath *path, QTextItem::RenderFlags) override;
56
57 bool canRender(const QChar *string, int len) const override;
58
59 int synthesized() const override { return synthesisFlags; }
60 bool supportsHorizontalSubPixelPositions() const override { return true; }
61 bool supportsVerticalSubPixelPositions() const override { return false; }
62
63 QFixed lineThickness() const override;
64 QFixed underlinePosition() const override;
65
66 void draw(CGContextRef ctx, qreal x, qreal y, const QTextItemInt &ti, int paintDeviceHeight);
67
68 FaceId faceId() const override;
69 bool getSfntTableData(uint /*tag*/, uchar * /*buffer*/, uint * /*length*/) const override;
70 void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) override;
71 QImage alphaMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition) override;
72 QImage alphaMapForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition, const QTransform &t) override;
73 QImage alphaRGBMapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t) override;
74 glyph_metrics_t alphaMapBoundingBox(glyph_t glyph, const QFixedPoint &, const QTransform &matrix, GlyphFormat) override;
75 QImage bitmapForGlyph(glyph_t, const QFixedPoint &subPixelPosition, const QTransform &t, const QColor &color) override;
76 QFixed emSquareSize() const override;
77 void doKerning(QGlyphLayout *g, ShaperFlags flags) const override;
78
79 bool supportsTransformation(const QTransform &transform) const override;
80 bool expectsGammaCorrectedBlending() const override;
81
82 QFontEngine *cloneWithSize(qreal pixelSize) const override;
83 Qt::HANDLE handle() const override;
84 int glyphMargin(QFontEngine::GlyphFormat format) override { Q_UNUSED(format); return 0; }
85
86 QFontEngine::Properties properties() const override;
87
88 QList<QFontVariableAxis> variableAxes() const override;
89
90 enum FontSmoothing { Disabled, Subpixel, Grayscale };
91 Q_ENUM(FontSmoothing);
92
93 static FontSmoothing fontSmoothing();
94 static qreal fontSmoothingGamma();
95
96 static bool ct_getSfntTable(void *user_data, uint tag, uchar *buffer, uint *length);
97 static QFont::Weight qtWeightFromCFWeight(float value);
98
99 static QCoreTextFontEngine *create(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference, const QMap<QFont::Tag, float> &variableAxisValue);
100
101protected:
102 QCoreTextFontEngine(const QFontDef &def);
103 void init();
104 QImage imageForGlyph(glyph_t glyph, const QFixedPoint &subPixelPosition, const QTransform &m, const QColor &color = QColor());
105 void loadAdvancesForGlyphs(QVarLengthArray<CGGlyph> &cgGlyphs, QGlyphLayout *glyphs) const;
106 bool hasColorGlyphs() const;
107 bool shouldAntialias() const;
108 bool shouldSmoothFont() const;
109 void initializeHeightMetrics() const override;
110
111 QCFType<CTFontRef> ctfont;
112 QCFType<CGFontRef> cgFont;
113 int synthesisFlags;
114 CGAffineTransform transform;
115 QFixed avgCharWidth;
116 QFixed underlineThickness;
117 QFixed underlinePos;
118 QFontEngine::FaceId face_id;
119 mutable bool kerningPairsLoaded;
120 QList<QFontVariableAxis> variableAxisList;
121};
122
123CGAffineTransform Q_GUI_EXPORT qt_transform_from_fontdef(const QFontDef &fontDef);
124
125QT_END_NAMESPACE
126
127#endif // QFONTENGINE_CORETEXT_P_H
CFArrayRef fallbacksForDescriptor(CTFontDescriptorRef descriptor)
CGAffineTransform qt_transform_from_fontdef(const QFontDef &fontDef)
static NSString *const kQtFontDataAttribute
static Q_DECL_UNUSED QDebug operator<<(QDebug debug, const FontDescription &fd)
CTFontDescriptorRef descriptorForFamily(const QString &familyName)
static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd)
static CTFontUIFontType fontTypeFromTheme(QPlatformTheme::Font f)
static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f)
CTFontDescriptorRef descriptorForFamily(const char *familyName)
CTFontDescriptorRef descriptorForFontType(CTFontUIFontType uiType)
T * descriptorAttribute(CTFontDescriptorRef descriptor, CFStringRef name)
CTFontDescriptorRef descriptorForStyle(QFont::StyleHint styleHint)
Q_FORWARD_DECLARE_CF_TYPE(CTFont)
Q_FORWARD_DECLARE_CF_TYPE(CTFontDescriptor)
QDebug Q_GUI_EXPORT & operator<<(QDebug &s, const QVectorPath &path)
QSupportedWritingSystems writingSystems