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++
Create glyph model and make a glyph palette to display said model.
Wolthera van Hövell tot Westerflier6a8fa1e11c9e
diff --git a/libs/flake/CMakeLists.txt b/libs/flake/CMakeLists.txtindex 44e0af96e8..aa557e6209 100644--- a/libs/flake/CMakeLists.txt+++ b/libs/flake/CMakeLists.txt@@ -237,6 +237,7 @@ set(kritaflake_SRCStext/KoFFWWSConverter.cpptext/KoFontChangeTracker.cpptext/KoWritingSystemUtils.cpp+ text/KoFontGlyphModel.cppresources/KoSvgSymbolCollectionResource.cppresources/KoGamutMask.cppdiff --git a/libs/flake/text/KoFontGlyphModel.cpp b/libs/flake/text/KoFontGlyphModel.cppnew file mode 100644index 0000000000..90d8db5b1d--- /dev/null+++ b/libs/flake/text/KoFontGlyphModel.cpp@@ -0,0 +1,270 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "KoFontGlyphModel.h"+#include <QDebug>+#include <hb.h>+#include <hb-ft.h>++struct KoFontGlyphModel::GlyphInfo {++ GlyphInfo()+ {+ }+ GlyphInfo(uint utf)+ : ucs(utf)+ {+ }+ uint ucs;+ GlyphType type = Base;+ QString baseString;+};++struct KoFontGlyphModel::CodePointInfo {+ uint ucs = -1;+ uint glyphIndex = 0;+ QString utfString = QString();++ QVector<GlyphInfo> glyphs;+};++struct KoFontGlyphModel::Private {+ QVector<CodePointInfo> codePoints;++ ~Private() = default;++ static QVector<KoFontGlyphModel::CodePointInfo> charMap(FT_FaceSP face) {+ QVector<CodePointInfo> codePoints;+ FT_UInt gindex;+ FT_ULong charcode = FT_Get_First_Char(face.data(), &gindex);++ while (gindex != 0) {+ CodePointInfo cpi;+ cpi.ucs = charcode;+ cpi.glyphIndex = gindex;+ cpi.utfString = QString::fromUcs4(&cpi.ucs, 1);+ cpi.glyphs.append(GlyphInfo(cpi.ucs));++ codePoints.append(cpi);+ charcode = FT_Get_Next_Char(face.data(), charcode, &gindex);+ }+ return codePoints;+ }++ static QMap<uint, QVector<GlyphInfo>> getVSData(FT_FaceSP face) {+ QMap<uint, QVector<GlyphInfo>> vsData;+ hb_face_t_sp hbFace(hb_ft_face_create_referenced(face.data()));+ hb_set_t_sp variationSelectors(hb_set_create());+ hb_face_collect_variation_selectors(hbFace.data(), variationSelectors.data());++ hb_codepoint_t hbVSPoint = HB_SET_VALUE_INVALID;++ while(hb_set_next(variationSelectors.data(), &hbVSPoint)) {+ hb_set_t_sp unicodes(hb_set_create());++ hb_face_collect_variation_unicodes(hbFace.data(), hbVSPoint, unicodes.data());+ hb_codepoint_t hbCodePointPoint = HB_SET_VALUE_INVALID;+ while(hb_set_next(unicodes.data(), &hbCodePointPoint)) {+ QVector<GlyphInfo> glyphs = vsData.value(hbCodePointPoint);+ GlyphInfo gci(hbCodePointPoint);+ gci.type = UnicodeVaritionSelector;+ gci.baseString = QString::fromUcs4(&hbVSPoint, 1);+ glyphs.append(gci);+ vsData.insert(hbCodePointPoint, glyphs);+ }+ }+ return vsData;+ }++ static QMap<uint, QVector<GlyphInfo>> getOpenTypeTables(FT_FaceSP face) {+ // All of this was referenced from Inkscape's OpenTypeUtil.cpp::readOpenTypeGsubTable+ QMap<uint, QVector<GlyphInfo>> otfData;+ hb_face_t_sp hbFace(hb_ft_face_create_referenced(face.data()));+ hb_tag_t table = HB_OT_TAG_GSUB;+ uint scriptCount = hb_ot_layout_table_get_script_tags(hbFace.data(), table, 0, nullptr, nullptr);+ hb_tag_t scriptTags[scriptCount];+ hb_ot_layout_table_get_script_tags(hbFace.data(), table, 0, &scriptCount, scriptTags);+ QVector<hb_tag_t> tags;+ for (uint i = 0; i < scriptCount; i++) {+ uint languageCount = hb_ot_layout_script_get_language_tags(hbFace.data(), table, i, 0, nullptr, nullptr);+ if(languageCount > 0) {++ for(uint j = 0; j < languageCount; j++) {+ uint featureCount = hb_ot_layout_language_get_feature_tags(hbFace.data(),+ table,+ i,+ j,+ 0, nullptr, nullptr);+ hb_tag_t features[featureCount];+ hb_ot_layout_language_get_feature_tags(hbFace.data(), table, i,+ j,+ 0, &featureCount, features);+ for(uint k = 0; k < featureCount; k++) {+ tags.append(features[k]);+ }+ }+ }+ }++ for (auto it = tags.begin(); it != tags.end(); it++) {+ char c[4];+ hb_tag_to_string(*it, c);+ QString tagName(c);+ uint featureIndex;+ bool found = hb_ot_layout_language_find_feature (hbFace.data(), table,+ 0,+ HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX,+ *it,+ &featureIndex );+ if (found) {+ uint lookup_indexes[32];+ uint lookup_count = 32;+ int count = hb_ot_layout_feature_get_lookups (hbFace.data(), table,+ featureIndex,+ 0,+ &lookup_count,+ lookup_indexes );+ for (int i = 0; i < count; ++i) {+ hb_set_t_sp glyphsBefore (hb_set_create());+ hb_set_t_sp glyphsInput (hb_set_create());+ hb_set_t_sp glyphsAfter (hb_set_create());+ hb_set_t_sp glyphsOutput (hb_set_create());++ hb_ot_layout_lookup_collect_glyphs (hbFace.data(), table,+ lookup_indexes[i],+ glyphsBefore.data(),+ glyphsInput.data(),+ glyphsAfter.data(),+ glyphsOutput.data() );++ GlyphInfo gci;+ gci.type = OpenType;+ gci.baseString = tagName;+ hb_codepoint_t hbGlyphPoint = HB_SET_VALUE_INVALID;+ while(hb_set_next(glyphsInput.data(), &hbGlyphPoint)) {+ QVector<GlyphInfo> glyphs = otfData.value(hbGlyphPoint);+ glyphs.append(gci);+ otfData.insert(hbGlyphPoint, glyphs);+ }++ }++ }++ }+ return otfData;+ }+};++++KoFontGlyphModel::KoFontGlyphModel(FT_FaceSP face)+ : QAbstractItemModel()+ , d(new Private)+{++ d->codePoints = Private::charMap(face);+ QMap<uint, QVector<GlyphInfo>> otfData = Private::getOpenTypeTables(face);+ QMap<uint, QVector<GlyphInfo>> VSData = Private::getVSData(face);+ for(auto it = d->codePoints.begin(); it != d->codePoints.end(); it++) {+ it->glyphs.append(VSData.value(it->ucs));+ QVector<GlyphInfo> otfTable = otfData.value(it->glyphIndex);+ for (auto glyphInfo = otfTable.begin(); glyphInfo != otfTable.end(); glyphInfo++) {+ glyphInfo->ucs = it->ucs;+ it->glyphs.append(*glyphInfo);+ }+ }++}++QVariant KoFontGlyphModel::data(const QModelIndex &index, int role) const+{+ if (!index.isValid()) {+ return QVariant();+ }+ if (role == Qt::DisplayRole) {+ if (!index.parent().isValid()) {+ return d->codePoints.value(index.row()).utfString;+ } else {+ return d->codePoints.value(index.parent().row()).glyphs.value(index.row()).baseString;+ }+ } else if (role == Qt::ToolTipRole) {+ if (!index.parent().isValid()) {+ QStringList glyphNames;+ QString base = d->codePoints.value(index.row()).utfString;+ QVector<GlyphInfo> glyphList = d->codePoints.value(index.row()).glyphs;+ glyphNames.append(QString("%1 glyph variants:").arg(glyphList.size()));+ for(auto glyph = glyphList.begin(); glyph != glyphList.end(); glyph++) {+ if (glyph->type == UnicodeVaritionSelector) {+ glyphNames.append("UVS:"+base+glyph->baseString);+ } else if (glyph->type == OpenType) {+ glyphNames.append("OTF:"+glyph->baseString);+ }+ }+ return glyphNames.join(" ");+ }+ }+ return QVariant();+}++QModelIndex KoFontGlyphModel::index(int row, int column, const QModelIndex &parent) const+{+ if (!parent.isValid()) {+ CodePointInfo cpi = d->codePoints.value(row);+ return createIndex(row, column, &cpi);+ } else {+ GlyphInfo gpi = d->codePoints.value(parent.row()).glyphs.value(row);+ return createIndex(row, column, &gpi);+ }+ return QModelIndex();+}++QModelIndex KoFontGlyphModel::parent(const QModelIndex &child) const+{+ if (!child.isValid() || static_cast<CodePointInfo*>(child.internalPointer())) {+ return QModelIndex();+ }+ GlyphInfo *gpi = static_cast<GlyphInfo*>(child.internalPointer());+ for (int i = 0; i < d->codePoints.size(); i++) {+ CodePointInfo cpi = d->codePoints.at(i);+ if (cpi.ucs == gpi->ucs) {+ return createIndex(i, 0, &cpi);+ }+ }++ return QModelIndex();+}++int KoFontGlyphModel::rowCount(const QModelIndex &parent) const+{+ if (parent.isValid()) {+ return d->codePoints.value(parent.row()).glyphs.size();+ }+ return d->codePoints.size();+}++int KoFontGlyphModel::columnCount(const QModelIndex &parent) const+{+ Q_UNUSED(parent);+ return 1;+}++bool KoFontGlyphModel::hasChildren(const QModelIndex &parent) const+{+ if (parent.isValid())+ return !d->codePoints.value(parent.row()).glyphs.isEmpty();+ return false;+}++QModelIndex KoFontGlyphModel::indexForString(QString grapheme)+{+ for (int i = 0; i < d->codePoints.size(); i++) {+ if (grapheme.toUcs4().startsWith(d->codePoints.at(i).ucs)) {+ CodePointInfo cpi = d->codePoints.at(i);+ return createIndex(i, 1, &cpi);+ }+ }+ return QModelIndex();+}diff --git a/libs/flake/text/KoFontGlyphModel.h b/libs/flake/text/KoFontGlyphModel.hnew file mode 100644index 0000000000..ff56b49c03--- /dev/null+++ b/libs/flake/text/KoFontGlyphModel.h@@ -0,0 +1,48 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KOFONTGLYPHMODEL_H+#define KOFONTGLYPHMODEL_H++#include <QAbstractItemModel>+#include "KoFontLibraryResourceUtils.h"+#include "kritaflake_export.h"++/**+ * @brief The KoFontGlyphModel class+ * Creates a tree model of all the glyphs in a given face.+ *+ * The primary parents are the basic codepoints, the children of those parents (if any),+ * are glyph variations.+ */+class KRITAFLAKE_EXPORT KoFontGlyphModel: public QAbstractItemModel+{+public:+ enum GlyphType {+ Base,+ UnicodeVaritionSelector,+ OpenType+ };++ KoFontGlyphModel(FT_FaceSP face);++ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;++ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;+ QModelIndex parent(const QModelIndex &child) const override;+ int rowCount(const QModelIndex &parent = QModelIndex()) const override;+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;+ bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;++ QModelIndex indexForString(QString grapheme);++private:+ class Private;+ struct GlyphInfo;+ struct CodePointInfo;+ QScopedPointer<Private> d;+};++#endif // KOFONTGLYPHMODEL_Hdiff --git a/libs/flake/text/KoFontLibraryResourceUtils.h b/libs/flake/text/KoFontLibraryResourceUtils.hindex 05800e13ac..1a6204399b 100644--- a/libs/flake/text/KoFontLibraryResourceUtils.h+++ b/libs/flake/text/KoFontLibraryResourceUtils.h@@ -99,5 +99,6 @@ using FT_FaceSP = KisLibraryResourcePointerWithSanityCheck<std::remove_pointer_tusing hb_font_t_sp = KisLibraryResourcePointer<hb_font_t, hb_font_destroy>;using hb_face_t_sp = KisLibraryResourcePointer<hb_face_t, hb_face_destroy>;+using hb_set_t_sp =KisLibraryResourcePointer<hb_set_t, hb_set_destroy>;#endif // KOFONTLIBRARYRESOURCEUTILS_Hdiff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txtindex 88457c6077..b2dc5eeafa 100644--- a/plugins/tools/svgtexttool/CMakeLists.txt+++ b/plugins/tools/svgtexttool/CMakeLists.txt@@ -23,6 +23,8 @@ set (SvgTextTool_SRCSSvgTextToolFactory.cppFontSizeAction.cppSvgTextShapeManagerBlocker.cpp++ glyphpalette/GlyphPaletteDialog.cpp)ki18n_wrap_ui(SvgTextTool_SRCSdiff --git a/plugins/tools/svgtexttool/SvgTextCursor.cpp b/plugins/tools/svgtexttool/SvgTextCursor.cppindex 1e217bffdb..e8e979738b 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.cpp+++ b/plugins/tools/svgtexttool/SvgTextCursor.cpp@@ -1224,6 +1224,7 @@ void SvgTextCursor::updateCursor(bool firstUpdate)d->oldCursorRect = d->shape->shapeToDocument(d->cursorShape.boundingRect());d->posIndex = d->shape->indexForPos(d->pos);d->anchorIndex = d->shape->indexForPos(d->anchor);+ emit selectionChanged();}d->cursorColor = QColor();d->cursorShape = d->shape? d->shape->cursorForPos(d->pos, d->cursorCaret, d->cursorColor): QPainterPath();diff --git a/plugins/tools/svgtexttool/SvgTextCursor.h b/plugins/tools/svgtexttool/SvgTextCursor.hindex 1f31ea9636..7f41a2547d 100644--- a/plugins/tools/svgtexttool/SvgTextCursor.h+++ b/plugins/tools/svgtexttool/SvgTextCursor.h@@ -191,6 +191,7 @@ public:Q_SIGNALS:void updateCursorDecoration(QRectF updateRect);+ void selectionChanged();private Q_SLOTS:void blinkCursor();void stopBlinkCursor();diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 8707812282..f14392fe2d 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -266,6 +266,7 @@ QWidget *SvgTextTool::createOptionWidget()connect(optionUi.btnEdit, SIGNAL(clicked(bool)), SLOT(showEditor()));connect(optionUi.btnEditSvg, SIGNAL(clicked(bool)), SLOT(showEditorSvgSource()));+ connect(optionUi.btnGlyphPalette, SIGNAL(clicked(bool)), SLOT(showGlyphPalette()));return optionWidget;}@@ -333,6 +334,37 @@ void SvgTextTool::textUpdated(KoSvgTextShape *shape, const QString &svg, const Qcanvas()->addCommand(cmd);}+void SvgTextTool::showGlyphPalette()+{+ if (!m_glyphPalette) {+ m_glyphPalette = new GlyphPaletteDialog(QApplication::activeWindow());+ m_glyphPalette->setAttribute( Qt::WA_QuitOnClose, false );++ connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateGlyphPalette()));++ m_glyphPalette->activateWindow();+ }+ if (!m_glyphPalette->isVisible()) {+ m_glyphPalette->show();+ updateGlyphPalette();+ }+}++void SvgTextTool::updateGlyphPalette()+{+ if (m_glyphPalette && m_glyphPalette->isVisible()) {+ QString grapheme = QString();+ if (m_textCursor.shape()) {+ int pos = m_textCursor.getPos();+ int pos2 = pos > 0? m_textCursor.shape()->posLeft(pos, false): m_textCursor.shape()->posRight(pos, false);+ int start = m_textCursor.shape()->indexForPos(qMin(pos, pos2));+ int end = m_textCursor.shape()->indexForPos(qMax(pos, pos2));+ grapheme = m_textCursor.shape()->plainText().mid(start, end-start);+ }+ m_glyphPalette->setGlyphModelFromProperties(m_textCursor.currentTextProperties(), grapheme);+ }+}+void SvgTextTool::slotTextEditorClosed(){// change tools to the shape selection tool when we close the text editor to allow moving and further editing of the object.diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.hindex afc68acf24..05a59b0dc9 100644--- a/plugins/tools/svgtexttool/SvgTextTool.h+++ b/plugins/tools/svgtexttool/SvgTextTool.h@@ -21,6 +21,7 @@#include <kis_signal_auto_connection.h>#include "SvgTextCursor.h"+#include "glyphpalette/GlyphPaletteDialog.h"#include <memory>@@ -111,6 +112,9 @@ private Q_SLOTS:void slotTextEditorClosed();void textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs);+ void showGlyphPalette();+ void updateGlyphPalette();+/*** @brief generateDefs* This generates a defs section with the appropriate@@ -156,6 +160,7 @@ private:};QPointer<SvgTextEditor> m_editor;+ QPointer<GlyphPaletteDialog> m_glyphPalette;QPointF m_lastMousePos;DragMode m_dragging {DragMode::None};std::unique_ptr<KoInteractionStrategy> m_interactionStrategy;diff --git a/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui b/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.uiindex db357cb61d..c5c9f0fd7f 100644--- a/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui+++ b/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui@@ -15,6 +15,32 @@</rect></property><layout class="QGridLayout" name="gridLayout">+ <item row="4" column="0">+ <widget class="QGroupBox" name="groupBoxDebug">+ <property name="title">+ <string notr="true">Debug Tools</string>+ </property>+ <layout class="QVBoxLayout" name="verticalLayout_2">+ <item>+ <widget class="QCheckBox" name="chkDbgCharBbox">+ <property name="text">+ <string notr="true">Show char bounding boxes</string>+ </property>+ <property name="checked">+ <bool>true</bool>+ </property>+ </widget>+ </item>+ <item>+ <widget class="QCheckBox" name="chkDbgLineBox">+ <property name="text">+ <string notr="true">Show line boxes</string>+ </property>+ </widget>+ </item>+ </layout>+ </widget>+ </item><item row="1" column="0"><widget class="QPushButton" name="btnEdit"><property name="text">@@ -22,6 +48,19 @@</property></widget></item>+ <item row="5" column="0">+ <spacer name="verticalSpacer">+ <property name="orientation">+ <enum>Qt::Vertical</enum>+ </property>+ <property name="sizeHint" stdset="0">+ <size>+ <width>0</width>+ <height>0</height>+ </size>+ </property>+ </spacer>+ </item><item row="0" column="0"><widget class="QGroupBox" name="defsOptions"><property name="title">@@ -287,43 +326,11 @@</property></widget></item>- <item row="4" column="0">- <spacer name="verticalSpacer">- <property name="orientation">- <enum>Qt::Vertical</enum>- </property>- <property name="sizeHint" stdset="0">- <size>- <width>0</width>- <height>0</height>- </size>- </property>- </spacer>- </item><item row="3" column="0">- <widget class="QGroupBox" name="groupBoxDebug">- <property name="title">- <string notr="true">Debug Tools</string>+ <widget class="QPushButton" name="btnGlyphPalette">+ <property name="text">+ <string>Glyph Palette</string></property>- <layout class="QVBoxLayout" name="verticalLayout_2">- <item>- <widget class="QCheckBox" name="chkDbgCharBbox">- <property name="text">- <string notr="true">Show char bounding boxes</string>- </property>- <property name="checked">- <bool>true</bool>- </property>- </widget>- </item>- <item>- <widget class="QCheckBox" name="chkDbgLineBox">- <property name="text">- <string notr="true">Show line boxes</string>- </property>- </widget>- </item>- </layout></widget></item></layout>diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qmlnew file mode 100644index 0000000000..a060085e46--- /dev/null+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml@@ -0,0 +1,73 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.0+import QtQuick.Controls 1.4+import QtQuick.Controls 2.5++Rectangle {+ id: root;+ anchors.fill: parent;+ property string titleText;+ property QtObject model;+ property alias currentIndex: charMap.currentIndex;+ SystemPalette {+ id: palette;+ colorGroup: SystemPalette.Active+ }+ color: palette.window++ Text {+ id: title+ text: titleText+ color: palette.windowText+ anchors.left: parent.left;+ anchors.right: parent.right;+ anchors.top: parent.top;+ }++ ScrollView {+ anchors.left: parent.left;+ anchors.right: parent.right;+ anchors.top: title.bottom;+ anchors.bottom: parent.bottom;+ GridView {+ id: charMap;+ model: root.model;+ focus: true;++ anchors.fill: parent;+ cellWidth: 25;+ cellHeight: 25;++ delegate: Rectangle {+ width: charMap.cellWidth;+ height: charMap.cellHeight;++ color: palette.base+ border.color: GridView.isCurrentItem? palette.highlight: palette.alternateBase;++ Text {+ clip: true;+ text: model.display+ color: palette.windowText+ anchors.centerIn: parent;+ }++ MouseArea {+ anchors.fill: parent;+ onClicked: {+ charMap.currentIndex = index;+ console.log(model.toolTip)+ }+ hoverEnabled: true;+ ToolTip.text: model.toolTip;+ ToolTip.visible: containsMouse;+ }+ }+ }+ }++}diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cppnew file mode 100644index 0000000000..1eb3b5f5a2--- /dev/null+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp@@ -0,0 +1,82 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "GlyphPaletteDialog.h"+#include <QQmlEngine>+#include <QQmlContext>+#include <QQuickItem>+#include <QHBoxLayout>+#include <KoResourcePaths.h>+#include <KoFontGlyphModel.h>+#include <KoFontRegistry.h>+#include <KoSvgText.h>++GlyphPaletteDialog::GlyphPaletteDialog(QWidget *parent): KoDialog(parent)+{+ setMinimumSize(500, 300);++ m_quickWidget = new QQuickWidget(this);+ this->setMainWidget(m_quickWidget);+ m_quickWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);+ m_quickWidget->engine()->rootContext()->setContextProperty("mainWindow", this);+ m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");+ m_quickWidget->engine()->addImportPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");++ m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib/qml/");+ m_quickWidget->engine()->addPluginPath(KoResourcePaths::getApplicationRoot() + "/lib64/qml/");++ m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);+ m_quickWidget->setSource(QUrl("qrc:/GlyphPalette.qml"));++ if (m_quickWidget->rootObject()) {+ m_quickWidget->rootObject()->setProperty("titleText", "Glyph palette");+ }+}++void GlyphPaletteDialog::setGlyphModelFromProperties(KoSvgTextProperties properties, QString text)+{+ if (m_lastUsedProperties == properties) {+ if (m_quickWidget->rootObject()) {+ KoFontGlyphModel *model = dynamic_cast<KoFontGlyphModel*>(m_quickWidget->rootObject()->property("model").value<QAbstractItemModel*>());+ if (model) {+ QModelIndex idx = model->indexForString(text);+ if (idx.isValid()) {+ m_quickWidget->rootObject()->setProperty("currentIndex", QVariant::fromValue(idx.row()));+ }+ }+ }+ return;+ }+ qreal res = 72.0;+ QVector<int> lengths;+ const QFont::Style style = QFont::Style(properties.propertyOrDefault(KoSvgTextProperties::FontStyleId).toInt());+ KoSvgText::AutoValue fontSizeAdjust = properties.propertyOrDefault(KoSvgTextProperties::FontSizeAdjustId).value<KoSvgText::AutoValue>();+ if (properties.hasProperty(KoSvgTextProperties::KraTextVersionId)) {+ fontSizeAdjust.isAuto = (properties.property(KoSvgTextProperties::KraTextVersionId).toInt() < 3);+ }+ const std::vector<FT_FaceSP> faces = KoFontRegistry::instance()->facesForCSSValues(+ properties.property(KoSvgTextProperties::FontFamiliesId).toStringList(),+ lengths,+ properties.fontAxisSettings(),+ text,+ static_cast<quint32>(res),+ static_cast<quint32>(res),+ properties.propertyOrDefault(KoSvgTextProperties::FontSizeId).toReal(),+ fontSizeAdjust.isAuto ? 1.0 : fontSizeAdjust.customValue,+ properties.propertyOrDefault(KoSvgTextProperties::FontWeightId).toInt(),+ properties.propertyOrDefault(KoSvgTextProperties::FontStretchId).toInt(),+ style != QFont::StyleNormal);+ KoFontGlyphModel *model = new KoFontGlyphModel(faces.front());+ QModelIndex idx = model->indexForString(text);+ if (m_quickWidget->rootObject()) {+ QString name = faces.front().data()->family_name;+ m_quickWidget->rootObject()->setProperty("titleText", QString("Glyph palette: "+name));+ m_quickWidget->rootObject()->setProperty("model", QVariant::fromValue(model));+ if (idx.isValid()) {+ m_quickWidget->rootObject()->setProperty("currentIndex", QVariant::fromValue(idx.row()));+ }+ }+ m_lastUsedProperties = properties;+}diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.hnew file mode 100644index 0000000000..84f248e6a8--- /dev/null+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.h@@ -0,0 +1,25 @@+/*+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef GLYPHPALETTEDIALOG_H+#define GLYPHPALETTEDIALOG_H++#include <KoDialog.h>+#include <QtQuickWidgets/QQuickWidget>+#include <KoSvgTextProperties.h>++class GlyphPaletteDialog: public KoDialog+{+ Q_OBJECT+public:+ GlyphPaletteDialog(QWidget *parent = nullptr);++ void setGlyphModelFromProperties(KoSvgTextProperties properties, QString text = QString());+private:+ QQuickWidget *m_quickWidget {0};+ KoSvgTextProperties m_lastUsedProperties;+};++#endif // GLYPHPALETTEDIALOG_Hdiff --git a/plugins/tools/svgtexttool/svgtexttool.qrc b/plugins/tools/svgtexttool/svgtexttool.qrcindex 7057a91912..1ba8d1419f 100644--- a/plugins/tools/svgtexttool/svgtexttool.qrc+++ b/plugins/tools/svgtexttool/svgtexttool.qrc@@ -1,20 +1,16 @@-<!DOCTYPE RCC>-<!--- SPDX-FileCopyrightText: none- SPDX-License-Identifier: CC0-1.0--->-<RCC version="1.0">+<RCC><qresource prefix="/kxmlgui5"><file alias="svgtexttool.xmlgui">svgtexttool.xmlgui</file></qresource><qresource prefix="/">- <file>tool_text_basic.xpm</file>- <file>tool_text_inline_horizontal.xpm</file>- <file>tool_text_inline_vertical.xpm</file>- <file>tool_text_on_path.xpm</file>- <file>tool_text_in_shape.xpm</file>- <file>tool_text_i_beam_horizontal.xpm</file>- <file>tool_text_i_beam_vertical.xpm</file>- <file>tool_text_i_beam_horizontal_done.xpm</file>+ <file>tool_text_basic.xpm</file>+ <file>tool_text_inline_horizontal.xpm</file>+ <file>tool_text_inline_vertical.xpm</file>+ <file>tool_text_on_path.xpm</file>+ <file>tool_text_in_shape.xpm</file>+ <file>tool_text_i_beam_horizontal.xpm</file>+ <file>tool_text_i_beam_vertical.xpm</file>+ <file>tool_text_i_beam_horizontal_done.xpm</file>+ <file alias="GlyphPalette.qml">glyphpalette/GlyphPalette.qml</file></qresource></RCC>