Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFFWWSConverter.cpp File Reference
#include "KoFFWWSConverter.h"
#include <KisForest.h>
#include <KisStaticInitializer.h>
#include <kis_assert.h>
#include <hb.h>
#include <hb-ft.h>
#include <QFileInfo>
#include <KoWritingSystemUtils.h>
#include <KoCssTextUtils.h>

Go to the source code of this file.

Classes

struct  FontFamilyNode
 
struct  FontFamilySizeInfo
 The FontFamilySizeInfo class Some font-families have different designs for different sizes. These are largely differences in weight, spacing and small glyph changes. There's four places opentype stores the design size information: More...
 
struct  KoFFWWSConverter::Private
 

Functions

KoFontFamilyWWSRepresentation createRepresentation (KisForest< FontFamilyNode >::child_iterator wws, KisForest< FontFamilyNode >::child_iterator typographic, bool singleFamily)
 
QVector< FontFamilyNodefindNodesByAxis (const QVector< FontFamilyNode > &nodes, const QString axisTag, const qreal &value, const qreal &defaultValue, const qreal &defaultValueUpper)
 
QDebug operator<< (QDebug dbg, const FontFamilyNode &node)
 
QDebug operator<< (QDebug dbg, const FontFamilySizeInfo &info)
 
KisForest< FontFamilyNode >::composition_iterator searchNodes (KisForest< FontFamilyNode >::composition_iterator it, KisForest< FontFamilyNode >::composition_iterator endIt, const QString family)
 

Variables

const QString ITALIC_TAG = "ital"
 
const QString OPTICAL_TAG = "opsz"
 
constexpr unsigned OS2_BOLD = 1u << 5
 Is italic.
 
constexpr unsigned OS2_ITALIC = 1u << 0
 
constexpr unsigned OS2_OBLIQUE = 1u << 9
 Indicates that the given font is primarily a WWS family and requires no further processing.
 
constexpr unsigned OS2_REGULAR = 1u << 6
 Is bold.
 
constexpr unsigned OS2_USE_TYPO_METRICS = 1u << 7
 
constexpr unsigned OS2_WWS = 1u << 8
 Is truly regular (instead of italic or oblique)
 
const QString SLANT_TAG = "slnt"
 
const QString WEIGHT_TAG = "wght"
 
const QString WIDTH_TAG = "wdth"
 

Function Documentation

◆ createRepresentation()

KoFontFamilyWWSRepresentation createRepresentation ( KisForest< FontFamilyNode >::child_iterator wws,
KisForest< FontFamilyNode >::child_iterator typographic,
bool singleFamily )

Definition at line 872 of file KoFFWWSConverter.cpp.

872 {
873 KoFontFamilyWWSRepresentation representation;
874 representation.fontFamilyName = wws->fontFamily;
875 representation.localizedFontFamilyNames = wws->localizedFontFamilies;
876 if (!singleFamily) {
877 // This funnels the typographic family to the resource, so that resources may potentially be sorted by their typographic family.
878 representation.typographicFamilyName = typographic->fontFamily;
879 representation.localizedTypographicFamily = typographic->localizedFontFamilies;
880 representation.localizedTypographicStyles = wws->localizedTypographicStyle;
881 }
882 representation.isVariable = wws->isVariable;
883 representation.colorBitMap = wws->colorBitMap;
884 representation.colorClrV0 = wws->colorClrV0;
885 representation.colorClrV1 = wws->colorClrV1;
886 representation.colorSVG = wws->colorSVG;
887 representation.type = wws->type;
888
889 for (auto subFamily = childBegin(wws); subFamily != childEnd(wws); subFamily++) {
891 if (subFamily == childBegin(wws)
892 || representation.lastModified < subFamily->lastModified) {
893 representation.lastModified = subFamily->lastModified;
894 }
895 representation.sampleStrings.insert(subFamily->sampleStrings);
896 Q_FOREACH(const QLocale &locale, subFamily->supportedLanguages) {
897 if (!representation.supportedLanguages.contains(locale)) {
898 representation.supportedLanguages.append(locale);
899 }
900 }
901
902 for (int a = 0; a < subFamily->axes.size(); a++) {
903 QString key = subFamily->axes.keys().at(a);
904 KoSvgText::FontFamilyAxis axis = subFamily->axes.value(key);
905 KoSvgText::FontFamilyAxis mainAxis = representation.axes.value(key);
906 mainAxis.min = qMin(mainAxis.min, axis.min);
907 mainAxis.defaultValue = axis.defaultValue;
908 mainAxis.max = qMax(mainAxis.max, axis.max);
909 mainAxis.localizedLabels.insert(axis.localizedLabels);
910 mainAxis.tag = axis.tag;
911 mainAxis.axisHidden = axis.axisHidden;
912 representation.axes.insert(mainAxis.tag, mainAxis);
913
914 if (!subFamily->isVariable) {
915 style.instanceCoords.insert(key, axis.value);
916 }
917 }
918 if (!subFamily->isVariable) {
919 if (!subFamily->localizedWWSStyle.isEmpty()) {
920 style.localizedLabels = subFamily->localizedWWSStyle;
921 } else if (!subFamily->localizedTypographicStyle.isEmpty()) {
922 style.localizedLabels = subFamily->localizedTypographicStyle;
923 } else if (!subFamily->localizedFontStyle.isEmpty()) {
924 style.localizedLabels = subFamily->localizedFontStyle;
925 } else {
926 style.localizedLabels.insert(QLocale(QLocale::English), subFamily->fontStyle);
927 }
928 style.isItalic = subFamily->isItalic;
929 style.isOblique = subFamily->isOblique;
930 representation.styles.append(style);
931 } else {
932 for (int i = 0; i < subFamily->styleInfo.size(); i++) {
933 KoSvgText::FontFamilyStyleInfo styleInfo = subFamily->styleInfo.at(i);
934 if (!styleInfo.localizedLabels.isEmpty()) {
935 styleInfo.isItalic = subFamily->isItalic;
936 styleInfo.isOblique = subFamily->isOblique;
937 representation.styles.append(styleInfo);
938 }
939 }
940 }
941 }
942 return representation;
943}
ChildIterator< value_type, is_const > childBegin(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:290
ChildIterator< value_type, is_const > childEnd(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:300
QList< KoSvgText::FontFamilyStyleInfo > styles
QHash< QString, KoSvgText::FontFamilyAxis > axes
KoSvgText::FontFormatType type
QDateTime lastModified
Value of the most recently modified font family. Used for updates.
QHash< QLocale, QString > localizedTypographicStyles
QList< QLocale > supportedLanguages
sample string used to generate the preview;
QHash< QString, QString > sampleStrings
QHash< QLocale, QString > localizedTypographicFamily
QHash< QLocale, QString > localizedFontFamilyNames
QHash< QLocale, QString > localizedLabels
Definition KoSvgText.h:777
QHash< QString, float > instanceCoords
Definition KoSvgText.h:816
QHash< QLocale, QString > localizedLabels
Definition KoSvgText.h:815

References KoFontFamilyWWSRepresentation::axes, KoSvgText::FontFamilyAxis::axisHidden, KoFontFamilyWWSRepresentation::colorBitMap, KoFontFamilyWWSRepresentation::colorClrV0, KoFontFamilyWWSRepresentation::colorClrV1, KoFontFamilyWWSRepresentation::colorSVG, KoSvgText::FontFamilyAxis::defaultValue, KoFontFamilyWWSRepresentation::fontFamilyName, KoSvgText::FontFamilyStyleInfo::instanceCoords, KoSvgText::FontFamilyStyleInfo::isItalic, KoSvgText::FontFamilyStyleInfo::isOblique, KoFontFamilyWWSRepresentation::isVariable, KoFontFamilyWWSRepresentation::lastModified, KoFontFamilyWWSRepresentation::localizedFontFamilyNames, KoSvgText::FontFamilyAxis::localizedLabels, KoSvgText::FontFamilyStyleInfo::localizedLabels, KoFontFamilyWWSRepresentation::localizedTypographicFamily, KoFontFamilyWWSRepresentation::localizedTypographicStyles, KoSvgText::FontFamilyAxis::max, KoSvgText::FontFamilyAxis::min, KoFontFamilyWWSRepresentation::sampleStrings, KoFontFamilyWWSRepresentation::styles, KoFontFamilyWWSRepresentation::supportedLanguages, KoSvgText::FontFamilyAxis::tag, KoFontFamilyWWSRepresentation::type, KoFontFamilyWWSRepresentation::typographicFamilyName, and KoSvgText::FontFamilyAxis::value.

◆ findNodesByAxis()

QVector< FontFamilyNode > findNodesByAxis ( const QVector< FontFamilyNode > & nodes,
const QString axisTag,
const qreal & value,
const qreal & defaultValue,
const qreal & defaultValueUpper )

Definition at line 1037 of file KoFFWWSConverter.cpp.

1037 {
1038 QVector<FontFamilyNode> candidates;
1039 QVector<qreal> values;
1040 Q_FOREACH (const FontFamilyNode &node, nodes) {
1041 qreal selectingVal = defaultValue;
1042
1043 if (node.axes.keys().contains(axisTag)) {
1044 KoSvgText::FontFamilyAxis axis = node.axes.value(axisTag);
1045 selectingVal = axis.value;
1046 if (axis.variableAxis) {
1047 if (value >= axis.min && value <= axis.max) {
1048 candidates.append(node);
1049 selectingVal = value;
1050 } else {
1051 values.append(axis.min);
1052 values.append(axis.max);
1053 }
1054 continue;
1055 }
1056 values.append(selectingVal);
1057 }
1058 }
1059 // We found some variable fonts already, so lets return early.
1060 if (!candidates.isEmpty()) {
1061 return candidates;
1062 }
1063
1064 // follow the CSS Fonts selection mechanism.
1065 bool shouldNotReturnDefault = ((axisTag == ITALIC_TAG || axisTag == SLANT_TAG) && value != defaultValue);
1066 qreal selectedValue = KoCssTextUtils::cssSelectFontStyleValue(values, value, defaultValue, defaultValueUpper, shouldNotReturnDefault);
1067
1068 Q_FOREACH (const FontFamilyNode &node, nodes) {
1069 if (node.axes.keys().contains(axisTag)) {
1070 KoSvgText::FontFamilyAxis axis = node.axes.value(axisTag);
1071 if (axis.value == selectedValue) {
1072 candidates.append(node);
1073 }
1074 } else if (value == defaultValue && !shouldNotReturnDefault) {
1075 candidates.append(node);
1076 }
1077 }
1078 return candidates;
1079}
float value(const T *src, size_t ch)
const QString SLANT_TAG
const QString ITALIC_TAG
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...
QHash< QString, KoSvgText::FontFamilyAxis > axes
axes While typical font-files within the same family are defined by having a single weight or width,...

References FontFamilyNode::axes, KoCssTextUtils::cssSelectFontStyleValue(), ITALIC_TAG, KoSvgText::FontFamilyAxis::max, KoSvgText::FontFamilyAxis::min, SLANT_TAG, KoSvgText::FontFamilyAxis::value, value(), and KoSvgText::FontFamilyAxis::variableAxis.

◆ operator<<() [1/2]

QDebug operator<< ( QDebug dbg,
const FontFamilyNode & node )

Definition at line 217 of file KoFFWWSConverter.cpp.

217 {
218 dbg.nospace() << node.debugInfo();
219 return dbg.space();
220}
QStringList debugInfo() const

References FontFamilyNode::debugInfo().

◆ operator<<() [2/2]

QDebug operator<< ( QDebug dbg,
const FontFamilySizeInfo & info )

Definition at line 60 of file KoFFWWSConverter.cpp.

60 {
61 dbg.nospace() << info.debugInfo();
62 return dbg.space();
63}
QString debugInfo() const

References FontFamilySizeInfo::debugInfo().

◆ searchNodes()

KisForest< FontFamilyNode >::composition_iterator searchNodes ( KisForest< FontFamilyNode >::composition_iterator it,
KisForest< FontFamilyNode >::composition_iterator endIt,
const QString family )

Definition at line 961 of file KoFFWWSConverter.cpp.

961 {
962 QString familySimplified = family;
963 QString familyLower = family.toLower();
964 // Qt's fontdatabase would add the vendor in [] behind the font name, when there were duplicates,
965 // though sometimes there was no such explanation, so we should check against that...
966 if (family.endsWith("]") && family.contains("[")) {
967 familySimplified = family.split("[", Qt::SkipEmptyParts).first().trimmed().toLower();
968 }
969 for (; it != endIt; it++) {
970 if (it.state() == KisForestDetail::Enter) {
971 continue;
972 }
973
974 if (childBegin(it) == childEnd(it)) {
975 // For the lowest nodes, we only want to test the full name.
976 QStringList local = it->localizedFullName.values();
977 if (local.contains(familySimplified, Qt::CaseInsensitive)
978 || local.contains(familyLower, Qt::CaseInsensitive)) {
979 break;
980 } else {
981 continue;
982 }
983 }
984
985 QStringList local = it->localizedFontFamilies.values();
986 QString itFamilyLower = QString(it->fontFamily).toLower();
987 if (itFamilyLower == familySimplified
988 || itFamilyLower == familyLower
989 || local.contains(familySimplified, Qt::CaseInsensitive)
990 || local.contains(familyLower, Qt::CaseInsensitive)) {
991 break;
992 }
993
994 }
995 return it;
996}
traversal_state state() const
Definition KisForest.h:516

References KisForestDetail::Enter, and KisForestDetail::CompositionIterator< T, is_const >::state().

Variable Documentation

◆ ITALIC_TAG

const QString ITALIC_TAG = "ital"

Definition at line 280 of file KoFFWWSConverter.cpp.

◆ OPTICAL_TAG

const QString OPTICAL_TAG = "opsz"

Definition at line 281 of file KoFFWWSConverter.cpp.

◆ OS2_BOLD

constexpr unsigned OS2_BOLD = 1u << 5
constexpr

Is italic.

Definition at line 271 of file KoFFWWSConverter.cpp.

◆ OS2_ITALIC

constexpr unsigned OS2_ITALIC = 1u << 0
constexpr

Definition at line 270 of file KoFFWWSConverter.cpp.

◆ OS2_OBLIQUE

constexpr unsigned OS2_OBLIQUE = 1u << 9
constexpr

Indicates that the given font is primarily a WWS family and requires no further processing.

Definition at line 274 of file KoFFWWSConverter.cpp.

◆ OS2_REGULAR

constexpr unsigned OS2_REGULAR = 1u << 6
constexpr

Is bold.

Definition at line 272 of file KoFFWWSConverter.cpp.

◆ OS2_USE_TYPO_METRICS

constexpr unsigned OS2_USE_TYPO_METRICS = 1u << 7
constexpr

Definition at line 275 of file KoFFWWSConverter.cpp.

◆ OS2_WWS

constexpr unsigned OS2_WWS = 1u << 8
constexpr

Is truly regular (instead of italic or oblique)

Definition at line 273 of file KoFFWWSConverter.cpp.

◆ SLANT_TAG

const QString SLANT_TAG = "slnt"

Definition at line 279 of file KoFFWWSConverter.cpp.

◆ WEIGHT_TAG

const QString WEIGHT_TAG = "wght"

Definition at line 277 of file KoFFWWSConverter.cpp.

◆ WIDTH_TAG

const QString WIDTH_TAG = "wdth"

Definition at line 278 of file KoFFWWSConverter.cpp.