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#include "qfontenginemultifontconfig_p.h"
5
6#include <QtGui/private/qfontengine_ft_p.h>
7
8QT_BEGIN_NAMESPACE
9
10QFontEngineMultiFontConfig::QFontEngineMultiFontConfig(QFontEngine *fe, int script)
11 : QFontEngineMulti(fe, script)
12{
13}
14
15QFontEngineMultiFontConfig::~QFontEngineMultiFontConfig()
16{
17 for (FcPattern *pattern : std::as_const(t&: cachedMatchPatterns)) {
18 if (pattern)
19 FcPatternDestroy(p: pattern);
20 }
21}
22
23bool QFontEngineMultiFontConfig::shouldLoadFontEngineForCharacter(int at, uint ucs4) const
24{
25 bool charSetHasChar = true;
26 FcPattern *matchPattern = getMatchPatternForFallback(at: at - 1);
27 if (matchPattern != nullptr) {
28 FcCharSet *charSet;
29 FcPatternGetCharSet(p: matchPattern, FC_CHARSET, n: 0, c: &charSet);
30 charSetHasChar = FcCharSetHasChar(fcs: charSet, ucs4);
31 }
32
33 return charSetHasChar;
34}
35
36
37FcPattern * QFontEngineMultiFontConfig::getMatchPatternForFallback(int fallBackIndex) const
38{
39 Q_ASSERT(fallBackIndex < fallbackFamilyCount());
40 if (fallbackFamilyCount() > cachedMatchPatterns.size())
41 cachedMatchPatterns.resize(size: fallbackFamilyCount());
42 FcPattern *ret = cachedMatchPatterns.at(i: fallBackIndex);
43 if (ret)
44 return ret;
45 FcPattern *requestPattern = FcPatternCreate();
46 FcValue value;
47 value.type = FcTypeString;
48 QByteArray cs = fallbackFamilyAt(at: fallBackIndex).toUtf8();
49 value.u.s = reinterpret_cast<const FcChar8 *>(cs.data());
50 FcPatternAdd(p: requestPattern, FC_FAMILY, value, append: true);
51 FcResult result;
52 ret = FcFontMatch(config: nullptr, p: requestPattern, result: &result);
53 cachedMatchPatterns.insert(i: fallBackIndex, t: ret);
54 FcPatternDestroy(p: requestPattern);
55 return ret;
56}
57
58QT_END_NAMESPACE
59

source code of qtbase/src/gui/text/unix/qfontenginemultifontconfig.cpp