Krita Source Code Documentation
Loading...
Searching...
No Matches
KoCSSFontInfo.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KOCSSFONTINFO_H
7#define KOCSSFONTINFO_H
8
9#include <QFont>
10#include <QMap>
11#include <kritaflake_export.h>
12#include <boost/operators.hpp>
13
21struct KRITAFLAKE_EXPORT KoCSSFontInfo: public boost::equality_comparable<KoCSSFontInfo> {
22
24
25 double size = -1;
26 bool automaticOpticalSizing = true;
27 double fontSizeAdjust = 0.0; // 1.0 would mean that the x-height is the same as the specified font-size, allowing scaling by x-height.
28 double weight = 400;
29 double width = 100;
30
31 QFont::Style slantMode = QFont::StyleNormal;
32 bool autoSlant = true;
33 double slantValue = 0.0;
34
35 QMap<QString, double> axisSettings;
36
37 QMap<QString, double> computedAxisSettings() const {
38 QMap<QString, double> settings;
39 settings.insert("wght", weight);
40 settings.insert("wdth", width);
41 if (automaticOpticalSizing) {
42 settings.insert("opsz", size);
43 }
44 if (slantMode == QFont::StyleItalic) {
45 settings.insert("ital", 1);
46 } else if (slantMode == QFont::StyleOblique) {
47 settings.insert("slnt", -(autoSlant? 14.0: slantValue));
48 } else {
49 settings.insert("ital", 0);
50 }
51 for (auto it = axisSettings.begin(); it != axisSettings.end(); it++) {
52 settings.insert(it.key(), it.value());
53 }
54
55 return settings;
56 }
57
58 bool operator==(const KoCSSFontInfo &rhs) const {
59 bool sizeMatch = automaticOpticalSizing? true: qFuzzyCompare(size, rhs.size);
60 bool slantMatch = autoSlant == rhs.autoSlant? true: qFuzzyCompare(slantValue, rhs.slantValue);
61 return families == rhs.families
62 && automaticOpticalSizing == rhs.automaticOpticalSizing
63 && sizeMatch
64 && qFuzzyCompare(weight, rhs.weight)
65 && qFuzzyCompare(width, rhs.width)
66 && slantMode == rhs.slantMode
67 && slantMatch
68 && axisSettings == rhs.axisSettings;
69 }
70};
71
72#endif // KOCSSFONTINFO_H
static bool qFuzzyCompare(half p1, half p2)
The KoCSSFontInfo class Convenience struct to make it easier to use KoFontRegistry....
QMap< QString, double > computedAxisSettings() const
QStringList families
bool automaticOpticalSizing
< Size in Pt.
QMap< QString, double > axisSettings
QFont::Style slantMode
bool operator==(const KoCSSFontInfo &rhs) const