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++
Type setting: add tests for setting character transforms.
Wolthera van Hövell tot Westerflier7c7071521dbf
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 17ac7765a6..d0954d914a 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -1128,6 +1128,12 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intQPointF anchorAbsolute;QPointF anchorCssPos;+ const KoSvgText::Direction dir = KoSvgText::Direction(this->textProperties().propertyOrDefault(KoSvgTextProperties::DirectionId).toInt());+ const KoSvgText::TextAnchor anchor = KoSvgText::TextAnchor(this->textProperties().propertyOrDefault(KoSvgTextProperties::TextAnchorId).toInt());++ const CharacterResult startRes = d->result.value(startIndex);+ const QPointF startAdvance = startRes.cursorInfo.rtl? startRes.advance: QPointF();+if (deltaPosition) {for (int i = 0; i< startIndex; i++) {KoSvgText::CharTransformation tf = resolvedTransforms.value(i);@@ -1140,10 +1146,19 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intanchorAbsolute.setY(*tf.yPos);}if (tf.startsNewChunk()) {- anchorCssPos = d->result.value(i).cssPosition;+ const CharacterResult res = d->result.value(i);+ anchorCssPos = res.cssPosition;}totalStartDelta += tf.relativeOffset();}+ } else {+ bool rtl = (dir == KoSvgText::DirectionRightToLeft);+ QPointF positionAtVisualEnd = (rtl? d->result.first(): d->result.last()).finalPosition;+ if (anchor == KoSvgText::AnchorEnd) {+ anchorAbsolute = positionAtVisualEnd;+ } else if (anchor == KoSvgText::AnchorMiddle) {+ anchorAbsolute = positionAtVisualEnd/2;+ }}int currentIndex = 0;@@ -1167,11 +1182,25 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intcontinue;}- int transformIndex = (i - startIndex) - addressableOffset;+ const int transformIndex = (i - startIndex) - addressableOffset;KoSvgText::CharTransformation tf = resolvedTransforms.value(i, KoSvgText::CharTransformation());++ // Function to get the delta position.+ auto getDelta = [res, totalStartDelta, accumulatedOffset, anchorAbsolute, anchorCssPos, startAdvance] (QPointF pos) -> QPointF {+ QPointF delta = pos - (res.textPathAndAnchoringOffset + anchorAbsolute + res.textLengthOffset);+ delta -= (totalStartDelta + accumulatedOffset + (res.cssPosition-anchorCssPos) + startAdvance);+ return delta;+ };+ // Function to get absolute position.+ auto getAbsolute = [res, tf, anchorAbsolute] (QPointF pos) -> QPointF {+ QPointF p = pos - (res.textPathAndAnchoringOffset - anchorAbsolute) - tf.relativeOffset();+ return p;+ };+if (i < startIndex) {if (!deltaPosition) {- const QPointF p = res.finalPosition - res.textPathAndAnchoringOffset;+ // Because we don't split the text content element, we need to set the absolute pos for every preceding transform.+ const QPointF p = getAbsolute(res.finalPosition);if (!tf.xPos) {tf.xPos = p.x();}@@ -1182,16 +1211,16 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const inttransforms << tf;continue;}+if (i >= endIndex) {if (i == endIndex) {// Counter transform to keep unselected characters at the same pos.if (deltaPosition && !tf.startsNewChunk()) {- QPointF delta = res.finalPosition - (res.textPathAndAnchoringOffset + anchorAbsolute + res.textLengthOffset);- delta -= (totalStartDelta + accumulatedOffset + (res.cssPosition-anchorCssPos));+ QPointF delta = getDelta(res.finalPosition);tf.dxPos = delta.x();tf.dyPos = delta.y();} else {- const QPointF p = res.finalPosition - res.textPathAndAnchoringOffset;+ const QPointF p = getAbsolute(res.finalPosition) - anchorAbsolute;tf.xPos = p.x();tf.yPos = p.y();}@@ -1206,7 +1235,6 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intif (positions.size()+startIndex > i) {const QPointF pos = positions.value(transformIndex, QPointF());-if (deltaPosition) {if (tf.startsNewChunk()) {anchorAbsolute = tf.absolutePos();@@ -1214,10 +1242,10 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intanchorCssPos = res.cssPosition;}- QPointF delta = pos - (res.textPathAndAnchoringOffset + anchorAbsolute + res.textLengthOffset);- delta -= (totalStartDelta + accumulatedOffset + (res.cssPosition-anchorCssPos));+ QPointF delta = getDelta(pos);tf.dxPos = delta.x();tf.dyPos = delta.y();+if (tf.startsNewChunk()) {accumulatedOffset = QPointF();totalStartDelta = tf.relativeOffset();@@ -1225,10 +1253,12 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intaccumulatedOffset += tf.relativeOffset();}} else {- const QPointF delta = pos - res.textPathAndAnchoringOffset;+ const QPointF delta = getAbsolute(pos);tf.xPos = delta.x();tf.yPos = delta.y();+ accumulatedOffset = pos - res.finalPosition;}+}transforms << tf;@@ -1241,6 +1271,7 @@ bool KoSvgTextShape::setCharacterTransformsOnRange(const int startPos, const intbreak;}}+ const CharacterResult res = d->result.last();if (changed) {KoSvgTextShape::Private::cleanUp(d->textData);diff --git a/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.cpp b/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.cppindex c150625b2e..33a7cb4886 100644--- a/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.cpp+++ b/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.cpp@@ -35,49 +35,18 @@ SvgTextChangeTransformsOnRange::SvgTextChangeTransformsOnRange(KoSvgTextShape *sQList<KoSvgTextCharacterInfo> originalTf = shape->getPositionsAndRotationsForRange(startPos, endPos);if (type == OffsetAll) {+while (!originalTf.isEmpty()) {KoSvgTextCharacterInfo tf = originalTf.takeFirst();positions.append(tf.finalPos + delta);+rotations.append(tf.rotateDeg);}} else {- const int lineEnd = qMin(shape->lineEnd(qMin(startPos, endPos)), qMax(startPos, endPos));- QList<KoSvgTextCharacterInfo> infos =- shape->getPositionsAndRotationsForRange(qMin(startPos, endPos), lineEnd);- if (infos.size() < 1) return;- const bool rtl = infos.first().rtl;- KoSvgTextCharacterInfo first = infos.first();- KoSvgTextCharacterInfo last = infos.last();- if (infos.size() > 1) {- std::sort(infos.begin(), infos.end(), KoSvgTextCharacterInfo::visualLessThan);- for (auto it = infos.begin(); it != infos.end(); it++) {- if (it->visualIndex >= 0) {- first = *it;- break;- }- }- for (auto it = infos.rbegin(); it != infos.rend(); it++) {- if (it->visualIndex >= 0) {- last = *it;- break;- }- }- }- QTransform t = QTransform::fromTranslate(last.finalPos.x(), last.finalPos.y());- t.rotate(last.rotateDeg);- last.finalPos = t.map(last.advance);-- const QLineF originalLine(rtl? last.finalPos: first.finalPos, rtl? first.finalPos: last.finalPos);- QLineF newLine(originalLine.p1(), originalLine.p2() + delta);-- const qreal scale = newLine.length()/originalLine.length();- QTransform origin = QTransform::fromTranslate(originalLine.p1().x(), originalLine.p1().y());- qreal angle = originalLine.angle() - newLine.angle();-- QTransform deltaTf = origin.inverted();- deltaTf *= QTransform::fromScale(scale, scale);- deltaTf *= QTransform().rotate(angle);- deltaTf *= origin;+ QTransform deltaTf = getTransformForOffset(shape, startPos, endPos, delta, type);+ QLineF l(0, 0, 10, 0);+ l.setAngle(0);+ l = deltaTf.map(l);while (!originalTf.isEmpty()) {KoSvgTextCharacterInfo tf = originalTf.takeFirst();@@ -87,7 +56,7 @@ SvgTextChangeTransformsOnRange::SvgTextChangeTransformsOnRange(KoSvgTextShape *spositions.append(tf.finalPos);}if (type != ScaleOnly) {- rotations.append(tf.rotateDeg + (angle));+ rotations.append(tf.rotateDeg - (l.angle()));} else {rotations.append(tf.rotateDeg);}@@ -114,10 +83,13 @@ void SvgTextChangeTransformsOnRange::redo(){QRectF updateRect = m_textShape->boundingRect();+ const int posIndex = m_textShape->indexForPos(m_startPos);+ const int posAnchor = m_textShape->indexForPos(m_endPos);+m_textShape->setCharacterTransformsOnRange(m_startPos, m_endPos, m_positions, m_rotations, m_calculateDeltaPositions);updateRect |= m_textShape->boundingRect();- m_textShape->notifyCursorPosChanged(m_startPos, m_endPos);+ m_textShape->notifyCursorPosChanged(m_textShape->posForIndex(posIndex), m_textShape->posForIndex(posAnchor));m_textShape->updateAbsolute(updateRect);}@@ -137,3 +109,51 @@ bool SvgTextChangeTransformsOnRange::mergeWith(const KUndo2Command *otherCommandm_rotations = other->m_rotations;return true;}++QTransform SvgTextChangeTransformsOnRange::getTransformForOffset(KoSvgTextShape *shape, int startPos, int endPos, QPointF delta, OffsetType type)+{+ QTransform deltaTf;+ if (type == OffsetAll) {+ return QTransform::fromTranslate(delta.x(), delta.y());+ } else {+ const int lineEnd = qMin(shape->lineEnd(qMin(startPos, endPos)), qMax(startPos, endPos));+ QList<KoSvgTextCharacterInfo> infos =+ shape->getPositionsAndRotationsForRange(qMin(startPos, endPos), lineEnd);+ if (infos.size() < 1) return deltaTf;+ const bool rtl = infos.first().rtl;+ KoSvgTextCharacterInfo first = infos.first();+ KoSvgTextCharacterInfo last = infos.last();+ if (infos.size() > 1) {+ std::sort(infos.begin(), infos.end(), KoSvgTextCharacterInfo::visualLessThan);+ for (auto it = infos.begin(); it != infos.end(); it++) {+ if (it->visualIndex >= 0) {+ first = *it;+ break;+ }+ }+ for (auto it = infos.rbegin(); it != infos.rend(); it++) {+ if (it->visualIndex >= 0) {+ last = *it;+ break;+ }+ }+ }+ QTransform t = QTransform::fromTranslate(last.finalPos.x(), last.finalPos.y());+ t.rotate(last.rotateDeg);+ last.finalPos = t.map(last.advance);++ QLineF originalLine(rtl? last.finalPos: first.finalPos, rtl? first.finalPos: last.finalPos);+ QLineF newLine(originalLine.p1(), originalLine.p2() + delta);++ const qreal scale = newLine.length()/originalLine.length();++ QTransform origin = QTransform::fromTranslate(originalLine.p1().x(), originalLine.p1().y());+ qreal angle = originalLine.angle() - newLine.angle();++ deltaTf = origin.inverted();+ deltaTf *= QTransform::fromScale(scale, scale);+ deltaTf *= QTransform().rotate(angle);+ deltaTf *= origin;+ }+ return deltaTf;+}diff --git a/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.h b/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.hindex 0a2fa22674..42eb46bcb2 100644--- a/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.h+++ b/plugins/tools/svgtexttool/SvgTextChangeTransformsOnRange.h@@ -8,9 +8,10 @@#include <kundo2command.h>#include <KoSvgTextShape.h>+#include "kritatoolsvgtext_export.h"-class SvgTextChangeTransformsOnRange : public KUndo2Command+class KRITATOOLSVGTEXT_EXPORT SvgTextChangeTransformsOnRange : public KUndo2Command{public:SvgTextChangeTransformsOnRange(KoSvgTextShape *shape, int startPos, int endPos, QVector<QPointF> positions, QVector<qreal> rotations, bool calculateDeltaPositions, KUndo2Command *parentCommand = nullptr);@@ -28,6 +29,12 @@ public:void redo() override;int id() const override;bool mergeWith(const KUndo2Command *other) override;++ /**+ * @brief getTransformForOffset+ * Function to get the expected transform, so we can test this command better.+ */+ static QTransform getTransformForOffset(KoSvgTextShape *shape, int startPos, int endPos, QPointF delta, OffsetType type);private:KoSvgTextShape *m_textShape = nullptr;int m_startPos = -1;diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cppindex 899f27a004..7c1255fdc2 100644--- a/plugins/tools/svgtexttool/SvgTextTool.cpp+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp@@ -741,7 +741,7 @@ void SvgTextTool::mousePressEvent(KoPointerEvent *event)SvgTextCursor::TypeSettingModeHandle handle = m_textCursor.typeSettingHandleAtPos(handleGrabRect(event->point));if (handle != SvgTextCursor::NoHandle) {if (!m_textCursor.setDominantBaselineFromHandle(handle)) {- m_interactionStrategy.reset(new SvgTextTypeSettingStrategy(this, selectedShape, &m_textCursor, handleGrabRect(event->point)));+ m_interactionStrategy.reset(new SvgTextTypeSettingStrategy(this, selectedShape, &m_textCursor, handleGrabRect(event->point), event->modifiers()));m_textCursor.setDrawTypeSettingHandle(false);}event->accept();diff --git a/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.cpp b/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.cppindex 9caee75c83..71a926f81d 100644--- a/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.cpp+++ b/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.cpp@@ -18,10 +18,12 @@#include <QDebug>#include <KoViewConverter.h>-SvgTextTypeSettingStrategy::SvgTextTypeSettingStrategy(KoToolBase *tool, KoSvgTextShape *textShape, SvgTextCursor *textCursor, const QRectF ®ionOfInterest)+SvgTextTypeSettingStrategy::SvgTextTypeSettingStrategy(KoToolBase *tool, KoSvgTextShape *textShape, SvgTextCursor *textCursor, const QRectF ®ionOfInterest, Qt::KeyboardModifiers modifiers): KoInteractionStrategy(tool), m_shape(textShape), m_dragStart(regionOfInterest.center())+ , m_deltaCalc(true)+ , m_modifiers(modifiers), m_textData(textShape->getMemento()){m_cursorPos = textCursor->getPos();@@ -33,8 +35,9 @@ SvgTextTypeSettingStrategy::SvgTextTypeSettingStrategy(KoToolBase *tool, KoSvgTevoid SvgTextTypeSettingStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers){QPointF delta = mouseLocation - m_dragStart;+ m_modifiers = modifiers;- if (modifiers & Qt::ShiftModifier) {+ if (m_modifiers & Qt::ShiftModifier) {delta = snapToClosestAxis(delta);m_dragCurrent = m_dragStart + delta;m_currentDelta = delta;@@ -44,6 +47,7 @@ void SvgTextTypeSettingStrategy::handleMouseMove(const QPointF &mouseLocation, Qm_currentDelta = m_dragCurrent - m_dragStart;}+if (m_editingType != int(SvgTextCursor::NoHandle)) {SvgTextShapeManagerBlocker blocker(tool()->canvas()->shapeManager());QRectF updateRect = m_shape->boundingRect();@@ -73,7 +77,7 @@ KUndo2Command *SvgTextTypeSettingStrategy::createCommand()if (m_shape->textType() != KoSvgTextShape::PreformattedText && m_shape->textType() != KoSvgTextShape::PrePositionedText) return nullptr;SvgTextChangeTransformsOnRange::OffsetType type = m_editingType == int(SvgTextCursor::StartPos)? SvgTextChangeTransformsOnRange::OffsetAll: SvgTextChangeTransformsOnRange::ScaleAndRotate;- cmd = new SvgTextChangeTransformsOnRange(m_shape, m_cursorPos, m_cursorAnchor, delta, type, true, nullptr);+ cmd = new SvgTextChangeTransformsOnRange(m_shape, m_cursorPos, m_cursorAnchor, delta, type, m_deltaCalc, nullptr);} else {const QPointF dragStart = m_shape->documentToShape(m_dragStart);const QPointF dragCurrent = m_shape->documentToShape(m_dragCurrent);@@ -141,6 +145,6 @@ void SvgTextTypeSettingStrategy::cancelInteraction()void SvgTextTypeSettingStrategy::finishInteraction(Qt::KeyboardModifiers modifiers){- Q_UNUSED(modifiers)+ m_modifiers = modifiers;cancelInteraction();}diff --git a/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.h b/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.hindex 02ec57535f..f36cb5ee38 100644--- a/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.h+++ b/plugins/tools/svgtexttool/SvgTextTypeSettingStrategy.h@@ -23,7 +23,7 @@ class QPointF;class SvgTextTypeSettingStrategy: public KoInteractionStrategy{public:- SvgTextTypeSettingStrategy(KoToolBase *tool, KoSvgTextShape *textShape, SvgTextCursor *textCursor, const QRectF ®ionOfInterest);+ SvgTextTypeSettingStrategy(KoToolBase *tool, KoSvgTextShape *textShape, SvgTextCursor *textCursor, const QRectF ®ionOfInterest, Qt::KeyboardModifiers modifiers = Qt::NoModifier);// KoInteractionStrategy interfacepublic:@@ -44,6 +44,9 @@ private:int m_editingType;int m_referenceCursorPos;+ bool m_deltaCalc;+ Qt::KeyboardModifiers m_modifiers;+QScopedPointer<KUndo2Command> m_previousCmd;KoSvgTextShapeMementoSP m_textData;};diff --git a/plugins/tools/svgtexttool/tests/SvgTextCursorTest.cpp b/plugins/tools/svgtexttool/tests/SvgTextCursorTest.cppindex 0a274b7792..adeae2d5a0 100644--- a/plugins/tools/svgtexttool/tests/SvgTextCursorTest.cpp+++ b/plugins/tools/svgtexttool/tests/SvgTextCursorTest.cpp@@ -8,6 +8,7 @@#include <SvgTextCursor.h>#include <SvgTextInsertCommand.h>#include <SvgTextRemoveCommand.h>+#include <SvgTextChangeTransformsOnRange.h>#include <KoSvgTextShape.h>#include <KoSvgTextShapeMarkupConverter.h>@@ -313,4 +314,133 @@ void SvgTextCursorTest::test_text_remove_dedicated()}+void SvgTextCursorTest::test_set_transforms_on_text_command_data()+{+ QTest::addColumn<QString>("svg");+ QTest::addColumn<int>("pos");+ QTest::addColumn<int>("length");+ QTest::addColumn<int>("type");+ QTest::addColumn<bool>("delta");++ QMap<int, QString> mapType = {+ {int(SvgTextChangeTransformsOnRange::OffsetAll), "-offset-all"},+ {int(SvgTextChangeTransformsOnRange::ScaleAndRotate), "-scale-and-rotate"},+ {int(SvgTextChangeTransformsOnRange::ScaleOnly), "-scale-only"},+ {int(SvgTextChangeTransformsOnRange::RotateOnly), "-rotate-only"}+ };+ QMap<int, QString> mapDelta = {+ {true, "-delta-pos"},+ {false, "-absolute-pos"},+ };++ Q_FOREACH(int type, mapType.keys()) {+ Q_FOREACH(int delta, mapDelta.keys()) {+ QTest::addRow("ltr%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;font-family:Deja Vu Sans\">Digital Painting, Creative Freedom</text>" << 3 << 3 << type << bool(delta);+ QTest::addRow("ttb%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;writing-mode: vertical-rl;font-family:Deja Vu Sans\">KRITA</text>" << 1 << 3 << type << bool(delta);+ QTest::addRow("ltr-absolute-pos%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;font-family:Deja Vu Sans\">Digital Painting, <tspan x=\"0\" y=\"0\">Creative</tspan> Freedom</text>" << 15 << 4 << type << bool(delta);+ QTest::addRow("ltr-mixed-pos%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;font-family:Deja Vu Sans\">Digital Painting, <tspan x=\"0\" dy=\"10\">Creative</tspan> Freedom</text>" << 15 << 4 << type << bool(delta);++ // These tests are very sensitive to the location of the anchor, so the following tests have been massaged a little so the text isn't moved in such a manner that the anchor location changes.++ QTest::addRow("ltr-relative-pos%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;text-anchor:start;font-family:Deja Vu Sans\">Digital Painting, <tspan dx=\"-50\" dy=\"10\">Creative</tspan> Freedom</text>" << 15 << 4 << type << bool(delta);+ QTest::addRow("rtl%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;direction: rtl;text-anchor:end;font-family:Deja Vu Sans\">رسم رقميّ، حريّة إبداعيّة</text>" << 2 << 5 << type << bool(delta);+ QTest::addRow("rtl-unicode-bidi%s%s",+ mapType.value(type).toLatin1().data(),+ mapDelta.value(delta).toLatin1().data()) << "<text style=\"font-size:10.0;direction: rtl;text-anchor:end;font-family:Deja Vu Sans\"><tspan>رسم رقميّ،</tspan><tspan direction=\"ltr\" unicode-bidi=\"isolate\">- Krita - </tspan><tspan> حريّة إبداعيّة</tspan></text></text>" << 14 << 7 << type << bool(delta);+ }+ }+}++void SvgTextCursorTest::test_set_transforms_on_text_command()+{+ QFETCH(QString, svg);+ QFETCH(int, pos);+ QFETCH(int, length);+ QFETCH(int, type);+ QFETCH(bool, delta);+ const QPointF offset(50, 20);+ const SvgTextChangeTransformsOnRange::OffsetType offsetType = SvgTextChangeTransformsOnRange::OffsetType(type);++ KoSvgTextShape *textShape = new KoSvgTextShape();++ KoSvgTextShapeMarkupConverter converter(textShape);+ converter.convertFromSvg(svg, QString(), QRectF(0, 0, 300, 300), 72.0);++ // Normalize the pos and anchor, so we're sure the index corresponds to the given pos.+ const int indexPos = textShape->indexForPos(pos);+ const int indexAnchor = textShape->indexForPos(pos+length);+ const int posNormalized = textShape->posForIndex(indexPos);+ const int anchor = textShape->posForIndex(indexAnchor);++ QString currentString = textShape->plainText().mid(indexPos, indexAnchor - indexPos);++ QList<KoSvgTextCharacterInfo> infos = textShape->getPositionsAndRotationsForRange(posNormalized, anchor);+ QTransform deltaTf = SvgTextChangeTransformsOnRange::getTransformForOffset(textShape, posNormalized, anchor, offset, offsetType);++ QVector<QPointF> positions;+ QVector<qreal> rotations;+ if (offsetType == SvgTextChangeTransformsOnRange::OffsetAll) {+ while (!infos.isEmpty()) {+ KoSvgTextCharacterInfo tf = infos.takeFirst();+ positions.append(deltaTf.map(tf.finalPos));+ rotations.append(tf.rotateDeg);+ }+ } else {+ QLineF l(0, 0, 10, 0);+ l.setAngle(0);+ l = deltaTf.map(l);+ while (!infos.isEmpty()) {+ KoSvgTextCharacterInfo tf = infos.takeFirst();+ if (offsetType != SvgTextChangeTransformsOnRange::RotateOnly) {+ positions.append(deltaTf.map(tf.finalPos));+ } else {+ positions.append(tf.finalPos);+ }+ if (offsetType != SvgTextChangeTransformsOnRange::ScaleOnly) {+ rotations.append(tf.rotateDeg - (l.angle()));+ } else {+ rotations.append(tf.rotateDeg);+ }+ }+ }++ KUndo2Command *cmd = new SvgTextChangeTransformsOnRange(textShape, posNormalized, anchor, offset, offsetType, delta);++ cmd->redo();++ int newPos = textShape->posForIndex(indexPos);+ int newAnchor = textShape->posForIndex(indexAnchor);+ QList<KoSvgTextCharacterInfo> newInfos = textShape->getPositionsAndRotationsForRange(newPos, newAnchor);++ for (int i = 0; i < positions.size(); i++) {+ KoSvgTextCharacterInfo info = newInfos.value(i);+ if (i > 0 && !delta && info.rtl) {+ /// Absolute positioning is supossed to affect the shaping, which in turn affects advance and positioning+ /// This means we cannot be expected to test rtl beyond the first offset.+ break;+ }+ const QPointF position = positions.value(i);+ const qreal rotate = rotations.value(i);++ if (offsetType != SvgTextChangeTransformsOnRange::RotateOnly) {+ QCOMPARE(position, info.finalPos);+ }+ if (offsetType != SvgTextChangeTransformsOnRange::ScaleOnly) {+ QCOMPARE(rotate, info.rotateDeg);+ }+ }+}+SIMPLE_TEST_MAIN(SvgTextCursorTest)diff --git a/plugins/tools/svgtexttool/tests/SvgTextCursorTest.h b/plugins/tools/svgtexttool/tests/SvgTextCursorTest.hindex 343ab518e9..68e7ad5f7a 100644--- a/plugins/tools/svgtexttool/tests/SvgTextCursorTest.h+++ b/plugins/tools/svgtexttool/tests/SvgTextCursorTest.h@@ -31,6 +31,9 @@ private Q_SLOTS:void test_text_remove_dedicated_data();void test_text_remove_dedicated();++ void test_set_transforms_on_text_command_data();+ void test_set_transforms_on_text_command();};#endif // SVGTEXTCURSORTEST_H