/src/qtbase/src/gui/text/qrawfont_p.h
Line | Count | Source |
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 QRAWFONTPRIVATE_P_H |
5 | | #define QRAWFONTPRIVATE_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 <QtGui/private/qtguiglobal_p.h> |
19 | | #include "qrawfont.h" |
20 | | |
21 | | #include "qfontengine_p.h" |
22 | | #include <QtCore/qthread.h> |
23 | | #include <QtCore/qthreadstorage.h> |
24 | | |
25 | | #if !defined(QT_NO_RAWFONT) |
26 | | |
27 | | QT_BEGIN_NAMESPACE |
28 | | |
29 | | namespace { class CustomFontFileLoader; } |
30 | | class Q_GUI_EXPORT QRawFontPrivate |
31 | | { |
32 | | public: |
33 | | QRawFontPrivate() |
34 | 0 | : fontEngine(nullptr) |
35 | 0 | , hintingPreference(QFont::PreferDefaultHinting) |
36 | 0 | , thread(nullptr) |
37 | 0 | {} |
38 | | |
39 | | QRawFontPrivate(const QRawFontPrivate &other) |
40 | 0 | : fontEngine(other.fontEngine) |
41 | 0 | , hintingPreference(other.hintingPreference) |
42 | 0 | , thread(other.thread) |
43 | 0 | { |
44 | 0 | #ifndef QT_NO_DEBUG |
45 | 0 | Q_ASSERT(fontEngine == nullptr || thread == QThread::currentThread()); |
46 | 0 | #endif |
47 | 0 | if (fontEngine != nullptr) |
48 | 0 | fontEngine->ref.ref(); |
49 | 0 | } |
50 | | |
51 | | ~QRawFontPrivate() |
52 | 0 | { |
53 | 0 | #ifndef QT_NO_DEBUG |
54 | 0 | Q_ASSERT(ref.loadRelaxed() == 0); |
55 | 0 | #endif |
56 | 0 | cleanUp(); |
57 | 0 | } |
58 | | |
59 | | inline void cleanUp() |
60 | 0 | { |
61 | 0 | setFontEngine(nullptr); |
62 | 0 | hintingPreference = QFont::PreferDefaultHinting; |
63 | 0 | } |
64 | | |
65 | | inline bool isValid() const |
66 | 0 | { |
67 | 0 | #ifndef QT_NO_DEBUG |
68 | 0 | Q_ASSERT(fontEngine == nullptr || thread == QThread::currentThread()); |
69 | 0 | #endif |
70 | 0 | return fontEngine != nullptr; |
71 | 0 | } |
72 | | |
73 | | inline void setFontEngine(QFontEngine *engine) |
74 | 0 | { |
75 | 0 | #ifndef QT_NO_DEBUG |
76 | 0 | Q_ASSERT(fontEngine == nullptr || thread == QThread::currentThread()); |
77 | 0 | #endif |
78 | 0 | if (fontEngine == engine) |
79 | 0 | return; |
80 | | |
81 | 0 | if (fontEngine != nullptr) { |
82 | 0 | if (!fontEngine->ref.deref()) |
83 | 0 | delete fontEngine; |
84 | 0 | #ifndef QT_NO_DEBUG |
85 | 0 | thread = nullptr; |
86 | 0 | #endif |
87 | 0 | } |
88 | |
|
89 | 0 | fontEngine = engine; |
90 | |
|
91 | 0 | if (fontEngine != nullptr) { |
92 | 0 | fontEngine->ref.ref(); |
93 | 0 | #ifndef QT_NO_DEBUG |
94 | 0 | thread = QThread::currentThread(); |
95 | 0 | Q_ASSERT(thread); |
96 | 0 | #endif |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | void loadFromData(const QByteArray &fontData, |
101 | | qreal pixelSize, |
102 | | QFont::HintingPreference hintingPreference); |
103 | | |
104 | 0 | static QRawFontPrivate *get(const QRawFont &font) { return font.d.data(); } |
105 | | |
106 | | QFontEngine *fontEngine; |
107 | | QFont::HintingPreference hintingPreference; |
108 | | QAtomicInt ref; |
109 | | |
110 | | private: |
111 | | QThread *thread; |
112 | | }; |
113 | | |
114 | | QT_END_NAMESPACE |
115 | | |
116 | | #endif // QT_NO_RAWFONT |
117 | | |
118 | | #endif // QRAWFONTPRIVATE_P_H |