File indexing completed on 2024-12-22 04:09:07
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KOFONTREGISTRY_H 0007 #define KOFONTREGISTRY_H 0008 0009 #include <QScopedPointer> 0010 #include <QVector> 0011 0012 #include <KoFontLibraryResourceUtils.h> 0013 0014 #include "kritaflake_export.h" 0015 0016 /** 0017 * @brief The KoFontRegistry class 0018 * A wrapper around a freetype library. 0019 * 0020 * This class abstract away loading freetype faces from css 0021 * values. Internally it uses fontconfig to get the filename 0022 * and then loads the freetype face within a mutex-lock. 0023 * 0024 * It also provides a configuration function to handle all the 0025 * size and variation axis values. 0026 */ 0027 class KRITAFLAKE_EXPORT KoFontRegistry 0028 { 0029 public: 0030 KoFontRegistry(); 0031 ~KoFontRegistry(); 0032 0033 static KoFontRegistry *instance(); 0034 0035 /** 0036 * @brief facesForCSSValues 0037 * This selects a font with fontconfig using the given 0038 * values. If "text" is not empty, it will try to select 0039 * fallback fonts as well. 0040 * 0041 * @returns a vector of loaded FT_Faces, the "lengths" vector 0042 * will be filled with the lengths of consequetive characters 0043 * a face can be set on. 0044 */ 0045 std::vector<FT_FaceUP> facesForCSSValues(const QStringList &families, 0046 QVector<int> &lengths, 0047 const QMap<QString, qreal> &axisSettings, 0048 const QString &text = "", 0049 quint32 xRes = 72, 0050 quint32 yRes = 72, 0051 qreal size = -1, 0052 qreal fontSizeAdjust = 1.0, 0053 int weight = 400, 0054 int width = 100, 0055 bool italic = false, 0056 int slant = 0, 0057 const QString &language = QString()); 0058 0059 /** 0060 * @brief configureFaces 0061 * This configures a list of faces with pointSize and 0062 * variation settings. 0063 * 0064 * Sometimes setting the size can get quite tricky (like with 0065 * bitmap fonts), so this convenience function handles all that. 0066 * 0067 * @returns whether the configuration was successful. 0068 */ 0069 bool configureFaces(const std::vector<FT_FaceUP> &faces, 0070 qreal size, 0071 qreal fontSizeAdjust, 0072 quint32 xRes, 0073 quint32 yRes, 0074 const QMap<QString, qreal> &axisSettings); 0075 0076 private: 0077 class Private; 0078 0079 friend class TestSvgText; 0080 friend class SvgTextCursorTest; 0081 0082 /** 0083 * @brief addFontFilePathToRegistery 0084 * This adds a font file to the registery. Right now only used by unittests. 0085 * 0086 * @param path the path of the font file. 0087 * @return Whether adding the font file was succesful. 0088 */ 0089 bool addFontFilePathToRegistery(const QString &path); 0090 0091 /** 0092 * @brief addFontFileDirectoryToRegistery 0093 * This adds a directory of font files to the registery. Right now only used by unittests. 0094 * @param path the path of the directory. 0095 * @return whether it was succesful. 0096 */ 0097 bool addFontFileDirectoryToRegistery(const QString &path); 0098 0099 QScopedPointer<Private> d; 0100 0101 Q_DISABLE_COPY(KoFontRegistry); 0102 }; 0103 0104 #endif // KOFONTREGISTRY_H