Krita Source Code Documentation
Loading...
Searching...
No Matches
FontStyleModel.cpp File Reference
#include "FontStyleModel.h"
#include <QDebug>
#include <resources/KoFontFamily.h>
#include <KisResourceModel.h>
#include <KoFontRegistry.h>
#include <lager/KoSvgTextPropertiesModel.h>
#include <KoCssTextUtils.h>

Go to the source code of this file.

Classes

struct  FontStyleModel::Private
 

Functions

QHash< int, KoSvgText::FontFamilyStyleInfosearchAxisTag (const QString &tag, const qreal &value, const QVector< qreal > &values, const qreal &defaultVal, const qreal &defaultValUpper, const QHash< int, KoSvgText::FontFamilyStyleInfo > &styles)
 
static bool styleLowerThan (const KoSvgText::FontFamilyStyleInfo &a, const KoSvgText::FontFamilyStyleInfo &b)
 

Variables

const QString ITALIC_TAG = "ital"
 
const QString OPTICAL_TAG = "opsz"
 
const QString SLANT_TAG = "slnt"
 
const QString WEIGHT_TAG = "wght"
 
const QString WIDTH_TAG = "wdth"
 

Function Documentation

◆ searchAxisTag()

QHash< int, KoSvgText::FontFamilyStyleInfo > searchAxisTag ( const QString & tag,
const qreal & value,
const QVector< qreal > & values,
const qreal & defaultVal,
const qreal & defaultValUpper,
const QHash< int, KoSvgText::FontFamilyStyleInfo > & styles )

Definition at line 95 of file FontStyleModel.cpp.

100 {
101 QHash<int, KoSvgText::FontFamilyStyleInfo> filteredStyles;
102 bool shouldNotReturnDefault = ((tag == ITALIC_TAG || tag == SLANT_TAG) && value != defaultVal);
103 qreal selectedValue = KoCssTextUtils::cssSelectFontStyleValue(values, value, defaultVal, defaultValUpper, shouldNotReturnDefault);
104 for (auto it = styles.begin(); it!= styles.end(); it++) {
105 qreal val = defaultVal;
106 if (it.value().instanceCoords.contains(tag)) {
107 val = it.value().instanceCoords.value(tag, defaultVal);
108 } else {
109 if (it.value().isItalic && tag == ITALIC_TAG) {
110 val = 1.0;
111 }
112 if (it.value().isOblique && it.value().isItalic && tag == SLANT_TAG) {
113 val = -14.0;
114 }
115 }
116
117 if (qFuzzyCompare(val, selectedValue)) {
118 if (shouldNotReturnDefault && qFuzzyCompare(val, defaultVal)) continue;
119 filteredStyles.insert(it.key(), it.value());
120 }
121 }
122 return filteredStyles;
123}
const QString SLANT_TAG
const QString ITALIC_TAG
float value(const T *src, size_t ch)
static qreal cssSelectFontStyleValue(const QVector< qreal > &values, const qreal targetValue, const qreal defaultValue, const qreal defaultValueUpper, const bool shouldNotReturnDefault)
cssSelectFontStyleValue Select the closest font style value from the list, following the CSS Fonts se...
static bool qFuzzyCompare(half p1, half p2)

References KoCssTextUtils::cssSelectFontStyleValue(), ITALIC_TAG, qFuzzyCompare(), SLANT_TAG, and value().

◆ styleLowerThan()

static bool styleLowerThan ( const KoSvgText::FontFamilyStyleInfo & a,
const KoSvgText::FontFamilyStyleInfo & b )
static

Definition at line 41 of file FontStyleModel.cpp.

41 {
42
43 for (auto it = a.instanceCoords.begin(); it != a.instanceCoords.end(); it++) {
44 if (it.key() == ITALIC_TAG || it.key() == SLANT_TAG) continue;
45 qreal other = b.instanceCoords.value(it.key());
46 if (it.value() < other) return true;
47 }
48 // todo: support slant and ital variation axes.
49 QFont::Style aStyle = a.isItalic? a.isOblique? QFont::StyleOblique: QFont::StyleItalic: QFont::StyleNormal;
50 QFont::Style bStyle = b.isItalic? a.isOblique? QFont::StyleOblique: QFont::StyleItalic: QFont::StyleNormal;
51 return aStyle < bStyle;
52}
QHash< QString, float > instanceCoords
Definition KoSvgText.h:816

References KoSvgText::FontFamilyStyleInfo::instanceCoords, KoSvgText::FontFamilyStyleInfo::isItalic, KoSvgText::FontFamilyStyleInfo::isOblique, ITALIC_TAG, and SLANT_TAG.

Variable Documentation

◆ ITALIC_TAG

const QString ITALIC_TAG = "ital"

Definition at line 16 of file FontStyleModel.cpp.

◆ OPTICAL_TAG

const QString OPTICAL_TAG = "opsz"

Definition at line 17 of file FontStyleModel.cpp.

◆ SLANT_TAG

const QString SLANT_TAG = "slnt"

Definition at line 15 of file FontStyleModel.cpp.

◆ WEIGHT_TAG

const QString WEIGHT_TAG = "wght"

Definition at line 13 of file FontStyleModel.cpp.

◆ WIDTH_TAG

const QString WIDTH_TAG = "wdth"

Definition at line 14 of file FontStyleModel.cpp.