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++

Implement functions to convert KoSvgTextShapes to Inline and Preformatted text.

Wolthera van Hövell tot Westerflier96fd1ac6e4cb
diff --git a/libs/flake/tests/TestSvgText.cpp b/libs/flake/tests/TestSvgText.cpp
index efb61e39cc..e80393b1e8 100644
--- a/libs/flake/tests/TestSvgText.cpp
+++ b/libs/flake/tests/TestSvgText.cpp
@@ -3259,6 +3259,47 @@ void TestSvgText::testRemoveTransforms()
QVERIFY(caret.p1().toPoint() == caretp1);
}
+void TestSvgText::testApplyWhiteSpace_data()
+{
+ QTest::addColumn<QString>("svg");
+ QTest::addColumn<QString>("result");
+
+ QTest::addRow("normal") << "<text style=\"white-space:normal\"> Text \n test </text>" << "Text test";
+ QTest::addRow("nowrap") << "<text style=\"white-space:nowrap\"> Text \n test </text>" << "Text test";
+ QTest::addRow("pre-line") << "<text style=\"white-space:pre-line\"> Text \n test </text>" << "Text \ntest ";
+ QTest::addRow("pre-wrap") << "<text style=\"white-space:pre-wrap\"> Text \n test </text>" << " Text \n test ";
+ QTest::addRow("nested") << "<text style=\"white-space:pre-line\"> Text \n <tspan style=\"white-space:pre-wrap\"> test</tspan> </text>" << "Text \n test";
+ QTest::addRow("xml:preserve") << "<text xml:space=\"preserve\"> Text \n\ttest </text>" << " Text test ";
+}
+
+void TestSvgText::testApplyWhiteSpace()
+{
+ QFETCH(QString, svg);
+ QFETCH(QString, result);
+
+ KoSvgTextShape *textShape = new KoSvgTextShape();
+ KoSvgTextShapeMarkupConverter converter(textShape);
+ converter.convertFromSvg(svg, QString(), QRectF(0, 0, 300, 300), 72.0);
+
+ textShape->d->applyWhiteSpace(textShape->d->textData);
+ textShape->relayout();
+ QVERIFY2(textShape->plainText() == result, QString("Apply whitespace result is incorrect: \"%1\"").arg(textShape->plainText()).toLatin1());
+}
+
+void TestSvgText::testInsertNewLinesAtAnchors()
+{
+ const QString svg = "<text style=\"white-space:pre-wrap\"><tspan x=\"0\" y=\"0\">Text</tspan><tspan x=\"0\" y=\"12\">\ntest</tspan><tspan x=\"0\" y=\"24\">text</tspan></text>";
+ const QString result = "Text\ntest\ntext";
+ //TODO: test text path and nested transforms.
+
+ KoSvgTextShape *textShape = new KoSvgTextShape();
+ KoSvgTextShapeMarkupConverter converter(textShape);
+ converter.convertFromSvg(svg, QString(), QRectF(0, 0, 300, 300), 72.0);
+
+ textShape->convertCharTransformsToPreformatted();
+ QVERIFY2(textShape->plainText() == result, QString("Insert newlines result is incorrect: \"%1\"").arg(textShape->plainText()).toLatin1());
+}
+
#include "kistest.h"
diff --git a/libs/flake/tests/TestSvgText.h b/libs/flake/tests/TestSvgText.h
index f8a68cbd47..11762d7594 100644
--- a/libs/flake/tests/TestSvgText.h
+++ b/libs/flake/tests/TestSvgText.h
@@ -130,6 +130,11 @@ private Q_SLOTS:
void testRemoveTransforms_data();
void testRemoveTransforms();
+
+ void testApplyWhiteSpace_data();
+ void testApplyWhiteSpace();
+
+ void testInsertNewLinesAtAnchors();
};
#endif // TESTSVGTEXT_H
diff --git a/libs/flake/text/KoCssTextUtils.h b/libs/flake/text/KoCssTextUtils.h
index 942fde2953..fb666e5315 100644
--- a/libs/flake/text/KoCssTextUtils.h
+++ b/libs/flake/text/KoCssTextUtils.h
@@ -91,7 +91,8 @@ public:
*
* @param text the text to check against, this text will be transformed if
* the collapse method requires that.
- * @param collapseMethod the white-space/text-space-collapse method.
+ * @param collapseMethod the white-space/text-space-collapse method,
+ * with the key indicating the position in the string at which it starts.
* @return A vector of booleans the size of the input text that marks
* whether the character should be collapsed.
*/
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 805ed1daa0..d81ce8fd2a 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -1286,6 +1286,28 @@ void KoSvgTextShape::notifyMarkupChanged()
}
}
+void KoSvgTextShape::convertCharTransformsToPreformatted(const bool makeInlineSize)
+{
+ const int inlineSize = writingMode() == KoSvgText::HorizontalTB? outlineRect().width(): outlineRect().height();
+ d->applyWhiteSpace(d->textData, true);
+ d->insertNewLinesAtAnchors(d->textData, !d->shapesInside.isEmpty());
+
+ KoSvgTextProperties props = this->propertiesForPos(-1);
+ if (makeInlineSize) {
+ KoSvgText::AutoValue val;
+ val.customValue = inlineSize;
+ val.isAuto = false;
+ if (!props.hasProperty(KoSvgTextProperties::InlineSizeId)) {
+ props.setProperty(KoSvgTextProperties::InlineSizeId, QVariant::fromValue(val));
+ }
+ } else {
+ props.removeProperty(KoSvgTextProperties::InlineSizeId);
+ }
+ // NOTE: applyWhiteSpace and insertNewLines don't notify changes,
+ // so setProperties is the only thing triggering relayout();
+ setPropertiesAtPos(-1, props);
+}
+
#include "KoXmlWriter.h"
bool KoSvgTextShape::saveSvg(SvgSavingContext &context)
{
diff --git a/libs/flake/text/KoSvgTextShape.h b/libs/flake/text/KoSvgTextShape.h
index 62b44cbbfd..9e74c95496 100644
--- a/libs/flake/text/KoSvgTextShape.h
+++ b/libs/flake/text/KoSvgTextShape.h
@@ -438,6 +438,15 @@ public:
/// Notify that the markup has changed.
void notifyMarkupChanged();
+ /*--------------- Converter functions ---------------*/
+
+ /**
+ * @brief convertCharTransformsToPreformatted
+ *
+ * @param makeInlineSize -- whether to have inline size applied.
+ */
+ void convertCharTransformsToPreformatted(const bool makeInlineSize = false);
+
/*--------------- Loading / Saving ------------------*/
/// Saves SVG data.
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 6c029a5200..fec0893250 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -510,10 +510,10 @@ public:
CharacterResult &charResult, const KoSvgText::TextRendering rendering);
void clearAssociatedOutlines();
- void resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement,
+ static void resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement,
QString text, QVector<CharacterResult> &result, int &currentIndex,
bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved,
- QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps);
+ QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps, bool withControls = true);
void applyTextLength(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QVector<CharacterResult> &result, int &currentIndex, int &resolvedDescendentNodes, bool isHorizontal,
const KoSvgTextProperties resolvedProps, const KoSvgText::ResolutionHandler &resHandler);
@@ -695,25 +695,33 @@ public:
* @brief collapsedWhiteSpacesForText
* This returns the collapsed spaces for a given piece of text, without transforms.
* @param tree -- text data tree.
+ * @param allText -- some collapseMethods modify the text. This is a pointer that sets the modified text.
* @param alsoCollapseLowSurrogate -- whether to mark utf16 surrogates as collapsed too.
* @return list of collapsed characters
*/
- static QVector<bool> collapsedWhiteSpacesForText(KisForest<KoSvgTextContentElement> &tree, const bool alsoCollapseLowSurrogate = false) {
- QString allText;
+ static QVector<bool> collapsedWhiteSpacesForText(KisForest<KoSvgTextContentElement> &tree, QString &allText, const bool alsoCollapseLowSurrogate = false) {
QMap<int, KoSvgText::TextSpaceCollapse> collapseModes;
- for (auto it = tree.depthFirstTailBegin(); it != tree.depthFirstTailEnd(); it++) {
- const int children = childCount(siblingCurrent(it));
- if (children == 0) {
- QString text = it->text;
- KoSvgText::TextSpaceCollapse collapse = KoSvgText::TextSpaceCollapse(it->properties.propertyOrDefault(KoSvgTextProperties::TextCollapseId).toInt());
- collapseModes.insert(allText.size(), collapse);
- allText += text;
+ QList<KoSvgTextProperties> parentProps = {KoSvgTextProperties::defaultProperties()};
+ for (auto it = tree.compositionBegin(); it != tree.compositionEnd(); it++) {
+ if (it.state() == KisForestDetail::Enter) {
+ KoSvgTextProperties ownProperties = it->properties;
+ ownProperties.inheritFrom(parentProps.last());
+ parentProps.append(ownProperties);
+
+ const int children = childCount(siblingCurrent(it));
+ if (children == 0) {
+ QString text = it->text;
+ KoSvgText::TextSpaceCollapse collapse = KoSvgText::TextSpaceCollapse(parentProps.last().propertyOrDefault(KoSvgTextProperties::TextCollapseId).toInt());
+ collapseModes.insert(allText.size(), collapse);
+ allText += text;
+ }
} else {
- break;
+ parentProps.pop_back();
}
}
QVector<bool> collapsed = KoCssTextUtils::collapseSpaces(&allText, collapseModes);
+
if (alsoCollapseLowSurrogate) {
for (int i = 0; i < allText.size(); i++) {
if (i > 0 && allText.at(i).isLowSurrogate() && allText.at(i-1).isHighSurrogate()) {
@@ -736,7 +744,8 @@ public:
* @param length -- end to remove from.
*/
static void removeTransforms(KisForest<KoSvgTextContentElement> &tree, const int start, const int length) {
- QVector<bool> collapsedCharacters = collapsedWhiteSpacesForText(tree, true);
+ QString all;
+ QVector<bool> collapsedCharacters = collapsedWhiteSpacesForText(tree, all, true);
auto root = tree.childBegin();
removeTransformsImpl(root, 0, start, length, collapsedCharacters);
@@ -790,7 +799,8 @@ public:
* transform because it is at the start of a text element.
*/
static void insertTransforms(KisForest<KoSvgTextContentElement> &tree, const int start, const int length, const bool allowSkipFirst) {
- QVector<bool> collapsedCharacters = collapsedWhiteSpacesForText(tree, true);
+ QString all;
+ QVector<bool> collapsedCharacters = collapsedWhiteSpacesForText(tree, all, true);
auto root = tree.childBegin();
insertTransformsImpl(root, 0, start, length, collapsedCharacters, allowSkipFirst);
@@ -841,6 +851,119 @@ public:
return currentLength;
}
+ /**
+ * @brief applyWhiteSpace
+ * CSS Whitespace processes whitespaces so that duplicate white spaces and
+ * unecessary hard breaks get removed from the text. Within the text layout
+ * we avoid removing the white spaces. However, when converting between text
+ * types it can be useful to remove these spaces.
+ * This function actually applies the white space rule to the active text.
+ * @param tree -- tree to apply the whitespace rule onto.
+ * @param convertToPreWrapped -- switch all whitespace rules to pre-wrapped.
+ */
+ void applyWhiteSpace(KisForest<KoSvgTextContentElement> &tree, const bool convertToPreWrapped = false) {
+ QString allText;
+ QVector<bool> collapsed = collapsedWhiteSpacesForText(tree, allText, false);
+
+ auto end = std::make_reverse_iterator(tree.childBegin());
+ auto begin = std::make_reverse_iterator(tree.childEnd());
+
+ for (; begin != end; begin++) {
+ applyWhiteSpaceImpl(begin, collapsed, allText, convertToPreWrapped);
+ }
+ if (convertToPreWrapped) {
+ tree.childBegin()->properties.setProperty(KoSvgTextProperties::TextCollapseId, QVariant::fromValue(KoSvgText::Preserve));
+ tree.childBegin()->properties.setProperty(KoSvgTextProperties::TextWrapId, QVariant::fromValue(KoSvgText::Wrap));
+ }
+ }
+
+ void applyWhiteSpaceImpl(std::reverse_iterator<KisForest<KoSvgTextContentElement>::child_iterator> current, QVector<bool> &collapsed, QString &allText, const bool convertToPreWrapped) {
+ auto base = current.base();
+ // It seems that .base() refers to the next entry instead of the pointer,
+ // which is coherent with the template implementation of "operator*" here:
+ // https://en.cppreference.com/w/cpp/iterator/reverse_iterator.html
+ base--;
+ if(base != siblingEnd(base)) {
+ auto end = std::make_reverse_iterator(childBegin(base));
+ auto begin = std::make_reverse_iterator(childEnd(base));
+ for (; begin != end; begin++) {
+ applyWhiteSpaceImpl(begin, collapsed, allText, convertToPreWrapped);
+ }
+ }
+
+ if (!current->text.isEmpty()) {
+ const int total = current->text.size();
+ QString currentText = allText.right(total);
+
+ for (int i = 0; i < total; i++) {
+ const int j = total - (i+1);
+ const bool col = collapsed.takeLast();
+ if (col) {
+ currentText.remove(j, 1);
+ }
+
+ }
+ current->text = currentText;
+ allText.chop(total);
+ }
+ if (convertToPreWrapped) {
+ current->properties.removeProperty(KoSvgTextProperties::TextCollapseId);
+ current->properties.removeProperty(KoSvgTextProperties::TextWrapId);
+ }
+ }
+
+ /**
+ * @brief insertNewLinesAtAnchors
+ * Resolves character transforms and then inserts new lines at each
+ * transform that creates a new chunk.
+ * @param tree -- tree to apply to.
+ * @param shapesInside -- whether we're wrapping in shape.
+ */
+ static void insertNewLinesAtAnchors(KisForest<KoSvgTextContentElement> &tree, bool shapesInside = false) {
+ QString all;
+ QVector<bool> collapsed = collapsedWhiteSpacesForText(tree, all, false);
+ QVector<CharacterResult> result(all.size());
+ int globalIndex = 0;
+ const KoSvgTextProperties props = tree.childBegin()->properties;
+ KoSvgText::WritingMode mode = KoSvgText::WritingMode(props.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());
+ bool isHorizontal = mode == KoSvgText::HorizontalTB;
+ bool isWrapped = (props.hasProperty(KoSvgTextProperties::InlineSizeId) || shapesInside);
+ QVector<KoSvgText::CharTransformation> resolvedTransforms(all.size());
+ resolveTransforms(tree.childBegin(), all, result, globalIndex, isHorizontal, isWrapped, false, resolvedTransforms, collapsed, KoSvgTextProperties::defaultProperties(), false);
+
+ auto end = std::make_reverse_iterator(tree.childBegin());
+ auto begin = std::make_reverse_iterator(tree.childEnd());
+
+ for (; begin != end; begin++) {
+ insertNewLinesAtAnchorsImpl(begin, resolvedTransforms);
+ }
+ }
+
+ static void insertNewLinesAtAnchorsImpl(std::reverse_iterator<KisForest<KoSvgTextContentElement>::child_iterator> current, QVector<KoSvgText::CharTransformation> &resolvedTransforms) {
+ auto base = current.base();
+ base--;
+ if(base != siblingEnd(base)) {
+ auto end = std::make_reverse_iterator(childBegin(base));
+ auto begin = std::make_reverse_iterator(childEnd(base));
+ for (; begin != end; begin++) {
+ insertNewLinesAtAnchorsImpl(begin, resolvedTransforms);
+ }
+ }
+
+ if (!current->text.isEmpty()) {
+ const int total = current->text.size();
+
+ for (int i = 0; i < total; i++) {
+ const int j = total - (i+1);
+ KoSvgText::CharTransformation transform = resolvedTransforms.takeLast();
+ if (transform.startsNewChunk() && !resolvedTransforms.isEmpty() && current->text.at(j) != QChar::LineFeed) {
+ current->text.insert(j, "\n");
+ }
+ }
+ }
+ current->localTransformations.clear();
+ }
+
/**
* @brief cleanUp
* This cleans up the tree by...
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index 541c4a2f42..3a741950a4 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -246,7 +246,7 @@ void KoSvgTextShape::Private::relayout()
resolvedTransforms[0].xPos = 0;
resolvedTransforms[0].yPos = 0;
}
- this->resolveTransforms(textData.childBegin(), text, result, globalIndex, isHorizontal, wrapped, false, resolvedTransforms, collapseChars, KoSvgTextProperties::defaultProperties());
+ this->resolveTransforms(textData.childBegin(), text, result, globalIndex, isHorizontal, wrapped, false, resolvedTransforms, collapseChars, KoSvgTextProperties::defaultProperties(), true);
// pass everything to a css-compatible text-layout algortihm.
raqm_t_sp layout(raqm_create());
@@ -854,15 +854,17 @@ void KoSvgTextShape::Private::clearAssociatedOutlines()
* @brief KoSvgTextShape::Private::resolveTransforms
* This resolves transforms and applies whitespace collapse.
*/
-
const QString bidiControls = "\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069";
-void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QString text, QVector<CharacterResult> &result, int &currentIndex, bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps) {
-
+void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement,
+ QString text, QVector<CharacterResult> &result, int &currentIndex,
+ bool isHorizontal, bool wrapped, bool textInPath,
+ QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars,
+ const KoSvgTextProperties resolvedProps, bool withControls) {
QVector<KoSvgText::CharTransformation> local = currentTextElement->localTransformations;
int index = currentIndex;
- int j = index + numChars(currentTextElement, true, resolvedProps);
+ int j = index + numChars(currentTextElement, withControls, resolvedProps);
if (currentTextElement->textPath) {
textInPath = true;
@@ -905,7 +907,7 @@ void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElemen
KoSvgTextProperties props = currentTextElement->properties;
props.inheritFrom(resolvedProps, true);
for (auto child = KisForestDetail::childBegin(currentTextElement); child != KisForestDetail::childEnd(currentTextElement); child++) {
- resolveTransforms(child, text, result, currentIndex, isHorizontal, false, textInPath, resolved, collapsedChars, props);
+ resolveTransforms(child, text, result, currentIndex, isHorizontal, false, textInPath, resolved, collapsedChars, props, withControls);
}
diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txt
index 393e3c74f6..3e7c539970 100644
--- a/plugins/tools/svgtexttool/CMakeLists.txt
+++ b/plugins/tools/svgtexttool/CMakeLists.txt
@@ -23,6 +23,7 @@ set (SvgTextTool_SRCS
SvgTextToolFactory.cpp
FontSizeAction.cpp
SvgTextShapeManagerBlocker.cpp
+ SvgConvertTextTypeCommand.cpp
glyphpalette/GlyphPaletteDialog.cpp
glyphpalette/GlyphPaletteProxyModel.cpp
diff --git a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpp b/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpp
new file mode 100644
index 0000000000..123c085c60
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.cpp
@@ -0,0 +1,35 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#include "SvgConvertTextTypeCommand.h"
+
+SvgConvertTextTypeCommand::SvgConvertTextTypeCommand(KoSvgTextShape *shape, ConversionType type, KUndo2Command *parent)
+ : KUndo2Command(parent)
+ , m_shape(shape)
+ , m_conversionType(type)
+{
+ setText(kundo2_i18n("Convert Text Type"));
+}
+
+void SvgConvertTextTypeCommand::redo()
+{
+ QRectF updateRect = m_shape->boundingRect();
+ m_textData = m_shape->getMemento();
+
+ if (m_conversionType == ToPreFormatted) {
+ m_shape->convertCharTransformsToPreformatted(false);
+ } else if (m_conversionType == ToInlineSize) {
+ m_shape->convertCharTransformsToPreformatted(true);
+ }
+
+ m_shape->updateAbsolute( updateRect| m_shape->boundingRect());
+}
+
+void SvgConvertTextTypeCommand::undo()
+{
+ QRectF updateRect = m_shape->boundingRect();
+ m_shape->setMemento(m_textData, 0, 0);
+ m_shape->updateAbsolute( updateRect| m_shape->boundingRect());
+}
diff --git a/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.h b/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.h
new file mode 100644
index 0000000000..4ab37a5e2e
--- /dev/null
+++ b/plugins/tools/svgtexttool/SvgConvertTextTypeCommand.h
@@ -0,0 +1,47 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+#ifndef SVGCONVERTTEXTTYPECOMMAND_H
+#define SVGCONVERTTEXTTYPECOMMAND_H
+
+#include <kundo2command.h>
+#include "kritatoolsvgtext_export.h"
+#include <KoSvgTextShape.h>
+
+/**
+ * @brief The SvgConvertTextTypeCommand class
+ * This command allows textshapes to be converted between
+ * preformatted and inline size types.
+ *
+ * Internally, this applies white space, inserts new lines
+ * for each new text chunk, and finally, assigns an inline-size if
+ * necessary.
+ */
+class KRITATOOLSVGTEXT_EXPORT SvgConvertTextTypeCommand : public KUndo2Command
+{
+public:
+ enum ConversionType {
+ ToPreFormatted, ///< Apply whitespace, convert whitespace rule to pre-wrapped, insert newlines at chunk starts and remove character transforms. Removes InlineSize.
+ ToInlineSize ///< Same as ToPreFormatted, except adds an inline-size.
+ };
+
+ SvgConvertTextTypeCommand(KoSvgTextShape *shape, ConversionType type, KUndo2Command *parent = 0);
+ ~SvgConvertTextTypeCommand() override = default;
+
+ void redo() override;
+
+ void undo() override;
+
+ //int id() const override;
+ //bool mergeWith(const KUndo2Command *other) override;
+
+private:
+ KoSvgTextShape *m_shape;
+ KoSvgTextShapeMementoSP m_textData;
+
+ ConversionType m_conversionType;
+};
+
+#endif // SVGCONVERTTEXTTYPECOMMAND_H
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 93137e2ff7..e1587feb6d 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -19,6 +19,7 @@
#include "SvgTextChangeCommand.h"
#include "SvgTextEditor.h"
#include "SvgTextRemoveCommand.h"
+#include "SvgConvertTextTypeCommand.h"
#include <QPainterPath>
#include <QGridLayout>
@@ -269,6 +270,9 @@ QWidget *SvgTextTool::createOptionWidget()
connect(optionUi.btnEditSvg, SIGNAL(clicked(bool)), SLOT(showEditorSvgSource()));
connect(optionUi.btnGlyphPalette, SIGNAL(clicked(bool)), SLOT(showGlyphPalette()));
+ connect(optionUi.convertPreFormatBtn, SIGNAL(clicked(bool)), this, SLOT(slotConvertToPreformatted()));
+ connect(optionUi.convertInlineBtn, SIGNAL(clicked(bool)), this, SLOT(slotConvertToInlineSize()));
+
return optionWidget;
}
@@ -536,6 +540,21 @@ void SvgTextTool::slotUpdateCursorDecoration(QRectF updateRect)
}
}
+void SvgTextTool::slotConvertToPreformatted() {
+ if (selectedShape()) {
+ SvgConvertTextTypeCommand *cmd = new SvgConvertTextTypeCommand(selectedShape(), SvgConvertTextTypeCommand::ToPreFormatted);
+ canvas()->addCommand(cmd);
+ }
+}
+
+void SvgTextTool::slotConvertToInlineSize()
+{
+ if (selectedShape()) {
+ SvgConvertTextTypeCommand *cmd = new SvgConvertTextTypeCommand(selectedShape(), SvgConvertTextTypeCommand::ToInlineSize);
+ canvas()->addCommand(cmd);
+ }
+}
+
QFont SvgTextTool::defaultFont() const
{
int size = QFontDatabase::standardSizes().at(optionUi.defPointSize->currentIndex() > -1 ? optionUi.defPointSize->currentIndex() : 0);
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index ba403c1047..ba8f9c716c 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -156,6 +156,9 @@ private Q_SLOTS:
*/
void slotUpdateCursorDecoration(QRectF updateRect);
+ void slotConvertToPreformatted();
+ void slotConvertToInlineSize();
+
private:
enum class DragMode {
diff --git a/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui b/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui
index c5c9f0fd7f..161cb35982 100644
--- a/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui
+++ b/plugins/tools/svgtexttool/WdgSvgTextOptionWidget.ui
@@ -15,7 +15,34 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="4" column="0">
+ <item row="6" 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="QPushButton" name="btnGlyphPalette">
+ <property name="text">
+ <string>Glyph Palette</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="btnEditSvg">
+ <property name="text">
+ <string>Edit SVG Source</string>
+ </property>
+ </widget>
+ </item>
+ <item row="5" column="0">
<widget class="QGroupBox" name="groupBoxDebug">
<property name="title">
<string notr="true">Debug Tools</string>
@@ -48,19 +75,6 @@
</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">
@@ -319,18 +333,27 @@
</layout>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QPushButton" name="btnEditSvg">
- <property name="text">
- <string>Edit SVG Source</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0">
- <widget class="QPushButton" name="btnGlyphPalette">
- <property name="text">
- <string>Glyph Palette</string>
+ <item row="4" column="0">
+ <widget class="QGroupBox" name="groupBoxConvert">
+ <property name="title">
+ <string>Convert...</string>
</property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QPushButton" name="convertPreFormatBtn">
+ <property name="text">
+ <string>Convert to Preformatted</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="convertInlineBtn">
+ <property name="text">
+ <string>Convert to Inline Wrapped</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
</layout>