Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextChangeTransformsOnRange Class Reference

#include <SvgTextChangeTransformsOnRange.h>

+ Inheritance diagram for SvgTextChangeTransformsOnRange:

Public Types

enum  OffsetType { OffsetAll , ScaleAndRotate , ScaleOnly , RotateOnly }
 

Public Member Functions

int id () const override
 
bool mergeWith (const KUndo2Command *other) override
 
void redo () override
 
 SvgTextChangeTransformsOnRange (KoSvgTextShape *shape, int startPos, int endPos, QPointF delta, OffsetType type, bool calculateDeltaPositions, KUndo2Command *parentCommand=nullptr)
 
 SvgTextChangeTransformsOnRange (KoSvgTextShape *shape, int startPos, int endPos, QVector< QPointF > positions, QVector< qreal > rotations, bool calculateDeltaPositions, KUndo2Command *parentCommand=nullptr)
 
void undo () override
 
 ~SvgTextChangeTransformsOnRange ()=default
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Static Public Member Functions

static QTransform getTransformForOffset (KoSvgTextShape *shape, int startPos, int endPos, QPointF delta, OffsetType type)
 getTransformForOffset Function to get the expected transform, so we can test this command better.
 

Private Attributes

bool m_calculateDeltaPositions = false
 
int m_endPos = -1
 
QVector< QPointF > m_positions
 
QVector< qreal > m_rotations
 
int m_startPos = -1
 
KoSvgTextShapeMementoSP m_textData
 
KoSvgTextShapem_textShape = nullptr
 

Detailed Description

Definition at line 14 of file SvgTextChangeTransformsOnRange.h.

Member Enumeration Documentation

◆ OffsetType

Constructor & Destructor Documentation

◆ SvgTextChangeTransformsOnRange() [1/2]

SvgTextChangeTransformsOnRange::SvgTextChangeTransformsOnRange ( KoSvgTextShape * shape,
int startPos,
int endPos,
QVector< QPointF > positions,
QVector< qreal > rotations,
bool calculateDeltaPositions,
KUndo2Command * parentCommand = nullptr )

Definition at line 10 of file SvgTextChangeTransformsOnRange.cpp.

11 : KUndo2Command(parentCommand)
12 , m_textShape(shape)
13 , m_startPos(startPos)
14 , m_endPos(endPos)
15 , m_positions(positions)
16 , m_rotations(rotations)
17 , m_calculateDeltaPositions(calculateDeltaPositions)
18 , m_textData(shape->getMemento())
19{
20 setText(kundo2_i18n("Adjust character transforms on text."));
21}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
KoSvgTextShapeMementoSP getMemento()
Get a memento holding the current textdata and layout info.
KUndo2MagicString kundo2_i18n(const char *text)

References kundo2_i18n(), and KUndo2Command::setText().

◆ SvgTextChangeTransformsOnRange() [2/2]

SvgTextChangeTransformsOnRange::SvgTextChangeTransformsOnRange ( KoSvgTextShape * shape,
int startPos,
int endPos,
QPointF delta,
OffsetType type,
bool calculateDeltaPositions,
KUndo2Command * parentCommand = nullptr )

Definition at line 23 of file SvgTextChangeTransformsOnRange.cpp.

24 : KUndo2Command(parentCommand)
25 , m_textShape(shape)
26 , m_startPos(startPos)
27 , m_endPos(endPos)
28 , m_calculateDeltaPositions(calculateDeltaPositions)
29 , m_textData(shape->getMemento())
30{
31 setText(kundo2_i18n("Adjust character transforms on text."));
32
33 QVector<QPointF> positions;
34 QVector<qreal> rotations;
35
36 QList<KoSvgTextCharacterInfo> originalTf = shape->getPositionsAndRotationsForRange(startPos, endPos);
37
38 if (type == OffsetAll) {
39
40 while (!originalTf.isEmpty()) {
41 KoSvgTextCharacterInfo tf = originalTf.takeFirst();
42 positions.append(tf.finalPos + delta);
43
44 rotations.append(tf.rotateDeg);
45 }
46 } else {
47 QTransform deltaTf = getTransformForOffset(shape, startPos, endPos, delta, type);
48 QLineF l(0, 0, 10, 0);
49 l.setAngle(0);
50 l = deltaTf.map(l);
51
52 while (!originalTf.isEmpty()) {
53 KoSvgTextCharacterInfo tf = originalTf.takeFirst();
54 if (type != RotateOnly) {
55 positions.append(deltaTf.map(tf.finalPos));
56 } else {
57 positions.append(tf.finalPos);
58 }
59 if (type != ScaleOnly) {
60 rotations.append(tf.rotateDeg - (l.angle()));
61 } else {
62 rotations.append(tf.rotateDeg);
63 }
64 }
65 }
66
67 m_positions = positions;
68 m_rotations = rotations;
69
70}
QList< KoSvgTextCharacterInfo > getPositionsAndRotationsForRange(const int startPos, const int endPos) const
getPositionsAndRotationsForRange
static QTransform getTransformForOffset(KoSvgTextShape *shape, int startPos, int endPos, QPointF delta, OffsetType type)
getTransformForOffset Function to get the expected transform, so we can test this command better.
The KoSvgTextCharacterInfo class This is a small struct to convey information about character positio...

References KoSvgTextCharacterInfo::finalPos, KoSvgTextShape::getPositionsAndRotationsForRange(), getTransformForOffset(), kundo2_i18n(), m_positions, m_rotations, OffsetAll, KoSvgTextCharacterInfo::rotateDeg, RotateOnly, ScaleOnly, and KUndo2Command::setText().

◆ ~SvgTextChangeTransformsOnRange()

SvgTextChangeTransformsOnRange::~SvgTextChangeTransformsOnRange ( )
default

Member Function Documentation

◆ getTransformForOffset()

QTransform SvgTextChangeTransformsOnRange::getTransformForOffset ( KoSvgTextShape * shape,
int startPos,
int endPos,
QPointF delta,
OffsetType type )
static

getTransformForOffset Function to get the expected transform, so we can test this command better.

Definition at line 115 of file SvgTextChangeTransformsOnRange.cpp.

116{
117 QTransform deltaTf;
118 if (type == OffsetAll) {
119 return QTransform::fromTranslate(delta.x(), delta.y());
120 } else {
121 const int lineEnd = qMin(shape->lineEnd(qMin(startPos, endPos)), qMax(startPos, endPos));
123 shape->getPositionsAndRotationsForRange(qMin(startPos, endPos), lineEnd);
124 if (infos.size() < 1) return deltaTf;
125 const bool rtl = infos.first().rtl;
126 KoSvgTextCharacterInfo first = infos.first();
127 KoSvgTextCharacterInfo last = infos.last();
128 if (infos.size() > 1) {
129 std::sort(infos.begin(), infos.end(), KoSvgTextCharacterInfo::visualLessThan);
130 for (auto it = infos.begin(); it != infos.end(); it++) {
131 if (it->visualIndex >= 0) {
132 first = *it;
133 break;
134 }
135 }
136 for (auto it = infos.rbegin(); it != infos.rend(); it++) {
137 if (it->visualIndex >= 0) {
138 last = *it;
139 break;
140 }
141 }
142 }
143 QTransform t = QTransform::fromTranslate(last.finalPos.x(), last.finalPos.y());
144 t.rotate(last.rotateDeg);
145 last.finalPos = t.map(last.advance);
146
147 QLineF originalLine(rtl? last.finalPos: first.finalPos, rtl? first.finalPos: last.finalPos);
148 QLineF newLine(originalLine.p1(), originalLine.p2() + delta);
149
150 const qreal scale = newLine.length()/originalLine.length();
151
152 QTransform origin = QTransform::fromTranslate(originalLine.p1().x(), originalLine.p1().y());
153 qreal angle = originalLine.angle() - newLine.angle();
154
155 deltaTf = origin.inverted();
156 deltaTf *= QTransform::fromScale(scale, scale);
157 deltaTf *= QTransform().rotate(angle);
158 deltaTf *= origin;
159 }
160 return deltaTf;
161}
int lineEnd(int pos)
lineEnd return the 'line end' for this pos. This uses anchored chunks, so each absolute x,...
static bool visualLessThan(const KoSvgTextCharacterInfo &a, const KoSvgTextCharacterInfo &b)

References KoSvgTextCharacterInfo::advance, KoSvgTextCharacterInfo::finalPos, KoSvgTextShape::getPositionsAndRotationsForRange(), KoSvgTextShape::lineEnd(), OffsetAll, KoSvgTextCharacterInfo::rotateDeg, and KoSvgTextCharacterInfo::visualLessThan().

◆ id()

int SvgTextChangeTransformsOnRange::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 98 of file SvgTextChangeTransformsOnRange.cpp.

References KisCommandUtils::SvgTextChangeTransformsOnRangeCommandId.

◆ mergeWith()

bool SvgTextChangeTransformsOnRange::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 103 of file SvgTextChangeTransformsOnRange.cpp.

103 {
104 const SvgTextChangeTransformsOnRange *other = dynamic_cast<const SvgTextChangeTransformsOnRange *>(otherCommand);
105
106 if (!other || other->m_textShape != m_textShape || other->m_startPos != m_startPos || other->m_endPos != m_endPos || other->m_calculateDeltaPositions != m_calculateDeltaPositions) {
107 return false;
108 }
109
110 m_positions = other->m_positions;
111 m_rotations = other->m_rotations;
112 return true;
113}

References m_calculateDeltaPositions, m_endPos, m_positions, m_rotations, m_startPos, and m_textShape.

◆ redo()

void SvgTextChangeTransformsOnRange::redo ( )
overridevirtual

Applies a change to the document. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls redo() on all child commands.

See also
undo()

Reimplemented from KUndo2Command.

Definition at line 84 of file SvgTextChangeTransformsOnRange.cpp.

85{
87
88 const int posIndex = m_textShape->indexForPos(m_startPos);
89 const int posAnchor = m_textShape->indexForPos(m_endPos);
90
92
94
96}
static void bulkShapesUpdate(const UpdatesList &updates)
void notifyCursorPosChanged(int pos, int anchor)
Notify that the cursor position has changed.
bool setCharacterTransformsOnRange(const int startPos, const int endPos, const QVector< QPointF > positions, const QVector< qreal > rotateDegrees, const bool deltaPosition=true)
setCharacterTransformsOnRange Set SVG 1.1 style character transforms on the given range....
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.
int posForIndex(int index, bool firstIndex=false, bool skipSynthetic=false) const
posForIndex Get the cursor position for a given index in a string.

References KoShapeBulkActionLock::bulkShapesUpdate(), KoSvgTextShape::indexForPos(), m_calculateDeltaPositions, m_endPos, m_positions, m_rotations, m_startPos, m_textShape, KoSvgTextShape::notifyCursorPosChanged(), KoSvgTextShape::posForIndex(), KoSvgTextShape::setCharacterTransformsOnRange(), and KoShapeBulkActionLock::unlock().

◆ undo()

void SvgTextChangeTransformsOnRange::undo ( )
overridevirtual

Reverts a change to the document. After undo() is called, the state of the document should be the same as before redo() was called. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls undo() on all child commands in reverse order.

See also
redo()

Reimplemented from KUndo2Command.

Definition at line 72 of file SvgTextChangeTransformsOnRange.cpp.

73{
75
77
79
81
82}
void setMemento(const KoSvgTextShapeMementoSP memento)
Set the text data and layout info, reset listening cursors to 0.

References KoShapeBulkActionLock::bulkShapesUpdate(), m_endPos, m_startPos, m_textData, m_textShape, KoSvgTextShape::notifyCursorPosChanged(), KoSvgTextShape::setMemento(), and KoShapeBulkActionLock::unlock().

Member Data Documentation

◆ m_calculateDeltaPositions

bool SvgTextChangeTransformsOnRange::m_calculateDeltaPositions = false
private

Definition at line 44 of file SvgTextChangeTransformsOnRange.h.

◆ m_endPos

int SvgTextChangeTransformsOnRange::m_endPos = -1
private

Definition at line 41 of file SvgTextChangeTransformsOnRange.h.

◆ m_positions

QVector<QPointF> SvgTextChangeTransformsOnRange::m_positions
private

Definition at line 42 of file SvgTextChangeTransformsOnRange.h.

◆ m_rotations

QVector<qreal> SvgTextChangeTransformsOnRange::m_rotations
private

Definition at line 43 of file SvgTextChangeTransformsOnRange.h.

◆ m_startPos

int SvgTextChangeTransformsOnRange::m_startPos = -1
private

Definition at line 40 of file SvgTextChangeTransformsOnRange.h.

◆ m_textData

KoSvgTextShapeMementoSP SvgTextChangeTransformsOnRange::m_textData
private

Definition at line 45 of file SvgTextChangeTransformsOnRange.h.

◆ m_textShape

KoSvgTextShape* SvgTextChangeTransformsOnRange::m_textShape = nullptr
private

Definition at line 39 of file SvgTextChangeTransformsOnRange.h.


The documentation for this class was generated from the following files: