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

source code of qtbase/src/gui/text/qrawfont_p.h