Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Try to speed up the opentype feature model for the text properties docker.

Wolthera van Hövell tot Westerflier08bce67973ac
diff --git a/libs/flake/text/KoFontGlyphModel.cpp b/libs/flake/text/KoFontGlyphModel.cpp
index 1ecb57a2e2..31e3941600 100644
--- a/libs/flake/text/KoFontGlyphModel.cpp
+++ b/libs/flake/text/KoFontGlyphModel.cpp
@@ -101,7 +101,7 @@ struct KoFontGlyphModel::Private {
return vsData;
}
- static QMap<QString, KoOpenTypeFeatureInfo> getOpenTypeTables(FT_FaceSP face, QVector<CodePointInfo> &charMap, QMap<QString, KoOpenTypeFeatureInfo> previousFeatureInfo, bool gpos, QStringList locales, QLatin1String lang = QLatin1String()) {
+ static QMap<QString, KoOpenTypeFeatureInfo> getOpenTypeTables(FT_FaceSP face, QVector<CodePointInfo> &charMap, QMap<QString, KoOpenTypeFeatureInfo> previousFeatureInfo, bool gpos, bool samplesOnly, QStringList locales, QLatin1String lang = QLatin1String()) {
// All of this was referenced from Inkscape's OpenTypeUtil.cpp::readOpenTypeGsubTable
QMap<QString, KoOpenTypeFeatureInfo> featureInfo = previousFeatureInfo;
hb_face_t_sp hbFace(hb_ft_face_create_referenced(face.data()));
@@ -291,6 +291,9 @@ struct KoFontGlyphModel::Private {
if (samples.size() < 6 && addSample) {
samples.append(QString::fromUcs4(&gci.ucs, 1));
}
+ if (samples.size() >= 6 && samplesOnly) {
+ break;
+ }
}
lookUpsProcessed.append(lookUpIndex);
if (info.sample.isEmpty() && !samples.isEmpty()) {
@@ -484,7 +487,7 @@ static bool sortBlocks(const KoUnicodeBlockData &a, const KoUnicodeBlockData &b)
return a.start < b.start;
}
-void KoFontGlyphModel::setFace(FT_FaceSP face, QLatin1String language)
+void KoFontGlyphModel::setFace(FT_FaceSP face, QLatin1String language, bool samplesOnly)
{
beginResetModel();
d->codePoints = Private::charMap(face);
@@ -509,8 +512,8 @@ void KoFontGlyphModel::setFace(FT_FaceSP face, QLatin1String language)
}
}
std::sort(d->blocks.begin(), d->blocks.end(), sortBlocks);
- d->featureData = Private::getOpenTypeTables(face, d->codePoints, QMap<QString, KoOpenTypeFeatureInfo>() ,false, KLocalizedString::languages(), language);
- d->featureData = Private::getOpenTypeTables(face, d->codePoints, d->featureData, true, KLocalizedString::languages(), language);
+ d->featureData = Private::getOpenTypeTables(face, d->codePoints, QMap<QString, KoOpenTypeFeatureInfo>() , false, samplesOnly, KLocalizedString::languages(), language);
+ d->featureData = Private::getOpenTypeTables(face, d->codePoints, d->featureData, true, samplesOnly, KLocalizedString::languages(), language);
endResetModel();
}
diff --git a/libs/flake/text/KoFontGlyphModel.h b/libs/flake/text/KoFontGlyphModel.h
index 6ae5ce02d9..7677745440 100644
--- a/libs/flake/text/KoFontGlyphModel.h
+++ b/libs/flake/text/KoFontGlyphModel.h
@@ -48,7 +48,15 @@ public:
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
QModelIndex indexForString(QString grapheme);
- void setFace(FT_FaceSP face, QLatin1String language = QLatin1String());
+
+ /**
+ * @brief setFace
+ * set the face to retrieve glyph data for.
+ * @param face -- the face.
+ * @param language -- the language for which to retrieve data for, OpenType data can have different glyphs depending on the language.
+ * @param samplesOnly -- Whether to only retrieve enough data for 6 samples, or to retrieve the full glyph layout. Turning this on speeds up loading.
+ */
+ void setFace(FT_FaceSP face, QLatin1String language = QLatin1String(), bool samplesOnly = false);
QHash<int, QByteArray> roleNames() const override;
diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
index 76bb220e12..4ede09e952 100644
--- a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp
@@ -180,7 +180,8 @@ void OpenTypeFeatureModel::setFromTextProperties(const KoSvgTextProperties &prop
if (!faces.empty()) {
QString language = props.propertyOrDefault(KoSvgTextProperties::TextLanguage).toString();
- d->glyphModel->setFace(faces.front(), QLatin1String(language.toLatin1()));
+ // NOTE: We're retrieving only enough data for 6 samples here, to speed up loading.
+ d->glyphModel->setFace(faces.front(), QLatin1String(language.toLatin1()), true);
d->allFeatures->setAvailableFeatures(d->availableFeatures());
d->fontInfo = props.cssFontInfo();
}