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

The SvgTextTypeSettingStrategy class This class encompasses the typesetting mode. More...

#include <SvgTextTypeSettingStrategy.h>

+ Inheritance diagram for SvgTextTypeSettingStrategy:

Public Member Functions

void cancelInteraction () override
 
KUndo2CommandcreateCommand () override
 
void finishInteraction (Qt::KeyboardModifiers modifiers) override
 
void handleMouseMove (const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override
 
 SvgTextTypeSettingStrategy (KoToolBase *tool, KoSvgTextShape *textShape, SvgTextCursor *textCursor, const QRectF &regionOfInterest, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
 
- Public Member Functions inherited from KoInteractionStrategy
 KoInteractionStrategy (KoToolBase *parent)
 constructor
 
virtual void paint (QPainter &painter, const KoViewConverter &converter)
 
KoToolBasetool () const
 
virtual ~KoInteractionStrategy ()
 Destructor.
 

Private Attributes

QPointF m_currentDelta
 
int m_cursorAnchor
 
int m_cursorPos
 
bool m_deltaCalc
 
QPointF m_dragCurrent
 
QPointF m_dragStart
 
int m_editingType
 
Qt::KeyboardModifiers m_modifiers
 
QScopedPointer< KUndo2Commandm_previousCmd
 
int m_referenceCursorPos
 
KoSvgTextShapem_shape
 
KoSvgTextShapeMementoSP m_textData
 

Additional Inherited Members

- Protected Member Functions inherited from KoInteractionStrategy
uint decorationThickness () const
 
uint grabSensitivity () const
 Convenience function to get the global grab sensitivity.
 
uint handleRadius () const
 Convenience function to get the global handle radius.
 
 KoInteractionStrategy (KoInteractionStrategyPrivate &)
 constructor
 
- Protected Attributes inherited from KoInteractionStrategy
KoInteractionStrategyPrivated_ptr
 

Detailed Description

The SvgTextTypeSettingStrategy class This class encompasses the typesetting mode.

Definition at line 23 of file SvgTextTypeSettingStrategy.h.

Constructor & Destructor Documentation

◆ SvgTextTypeSettingStrategy()

SvgTextTypeSettingStrategy::SvgTextTypeSettingStrategy ( KoToolBase * tool,
KoSvgTextShape * textShape,
SvgTextCursor * textCursor,
const QRectF & regionOfInterest,
Qt::KeyboardModifiers modifiers = Qt::NoModifier )

Definition at line 21 of file SvgTextTypeSettingStrategy.cpp.

23 , m_shape(textShape)
24 , m_dragStart(regionOfInterest.center())
25 , m_deltaCalc(true)
26 , m_modifiers(modifiers)
27 , m_textData(textShape->getMemento())
28{
29 m_cursorPos = textCursor->getPos();
30 m_cursorAnchor = textCursor->getAnchor();
31 m_editingType = textCursor->typeSettingHandleAtPos(regionOfInterest);
33}
KoInteractionStrategy(KoToolBase *parent)
constructor
KoSvgTextShapeMementoSP getMemento()
Get a memento holding the current textdata and layout info.
int getAnchor()
Get the current selection anchor. This is the same as position, unless there's a selection.
TypeSettingModeHandle
Handles used by type setting mode.
int getPos()
Get the current position.
int posForTypeSettingHandleAndRect(const TypeSettingModeHandle handle, const QRectF regionOfInterest)
posForHandleAndRect Returns the closest cursor position for a given region and typesetting handle....
TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest)
Get typeSettingMode handle for text;.

References SvgTextCursor::getAnchor(), SvgTextCursor::getPos(), m_cursorAnchor, m_cursorPos, m_editingType, m_referenceCursorPos, SvgTextCursor::posForTypeSettingHandleAndRect(), and SvgTextCursor::typeSettingHandleAtPos().

Member Function Documentation

◆ cancelInteraction()

void SvgTextTypeSettingStrategy::cancelInteraction ( )
overridevirtual

This method will undo frames based interactions by calling createCommand() and unexecuting that.

Reimplemented from KoInteractionStrategy.

Definition at line 160 of file SvgTextTypeSettingStrategy.cpp.

161{
162 tool()->canvas()->snapGuide()->reset();
163 QRectF updateRect = m_shape->boundingRect();
164 if (m_previousCmd) {
165 m_previousCmd->undo();
166 }
167 updateRect |= m_shape->boundingRect();
171}
KoSnapGuide * snapGuide
virtual void updateAbsolute(const QRectF &rect) const
Definition KoShape.cpp:545
void reset()
Resets the snap guide.
void setMemento(const KoSvgTextShapeMementoSP memento)
Set the text data and layout info, reset listening cursors to 0.
QRectF boundingRect() const override
Get the bounding box of the shape.
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
virtual void repaintDecorations()
QScopedPointer< KUndo2Command > m_previousCmd

References KoSvgTextShape::boundingRect(), KoToolBase::canvas(), m_cursorAnchor, m_cursorPos, m_previousCmd, m_shape, m_textData, KoToolBase::repaintDecorations(), KoSnapGuide::reset(), KoSvgTextShape::setMemento(), KoCanvasBase::snapGuide, KoInteractionStrategy::tool(), and KoShape::updateAbsolute().

◆ createCommand()

KUndo2Command * SvgTextTypeSettingStrategy::createCommand ( )
overridevirtual

For interactions that are undo-able this method should be implemented to return such a command. Implementations should return 0 otherwise.

Returns
a command, or 0.

Used to synchronise the offsets when changing fontsize...

Implements KoInteractionStrategy.

Definition at line 68 of file SvgTextTypeSettingStrategy.cpp.

69{
70 if (m_editingType == int(SvgTextCursor::NoHandle)) return nullptr;
71 QPointF delta = m_currentDelta;
72
74 if (originalTf.isEmpty()) return nullptr;
75
76 KUndo2Command *cmd = nullptr;
80
82 } else {
83 const QPointF dragStart = m_shape->documentToShape(m_dragStart);
84 const QPointF dragCurrent = m_shape->documentToShape(m_dragCurrent);
85 const int closestPos = m_referenceCursorPos;
86 const QList<KoSvgTextCharacterInfo> infos = m_shape->getPositionsAndRotationsForRange(closestPos, closestPos);
87
88 if (infos.empty()) return cmd;
89
90 const KoSvgTextCharacterInfo info = infos.first();
91 const QTransform tf = QTransform::fromTranslate(info.finalPos.x(), info.finalPos.y()) * QTransform().rotate(info.rotateDeg);
92 const QLineF line = tf.map(QLineF(QPointF(), info.advance));
93 const qreal distNew = kisDistanceToLine(dragCurrent, line);
94
96 KoSvgTextProperties oldProps = m_shape->propertiesForPos(closestPos, true);
97
99 QVector<QPointF> newPositions;
100 QVector<qreal> newRotations;
101
103 const qreal distOld = kisDistanceToLine(dragStart, line);
104 const qreal scale = qMax(0.000001, distNew/distOld);
106 length.value *= scale;
107 props.setFontSize(length);
108
110 // When we change font size, we need to correct the offset for the scaled advances.
111 // Technically, we need to test against the laid out text to get the correct advance, but that's really complicated...
112 QPointF diff = QPointF();
113
114 Q_FOREACH(const KoSvgTextCharacterInfo originalInfo, originalTf) {
115 const QTransform rotate = QTransform().rotate(originalInfo.rotateDeg);
116 const QPointF newPos = originalInfo.finalPos + diff;
117 const QTransform oTf = QTransform::fromTranslate(originalInfo.finalPos.x(), originalInfo.finalPos.y()) * rotate;
118 diff += (oTf.map(originalInfo.advance*scale) - oTf.map(originalInfo.advance));
119 newPositions.append(newPos);
120 newRotations.append(originalInfo.rotateDeg);
121 }
122 }
123 } else if (m_editingType == int(SvgTextCursor::BaselineShift)) {
125
126 const QLineF normal = line.normalVector();
127 qreal dot = QVector2D::dotProduct(QVector2D(normal.p2() - normal.p1()), QVector2D(dragCurrent-line.p1()));
128 length.value = dot < 0? -distNew: distNew;
133 const qreal metricsMultiplier = oldProps.fontSize().value/qreal(info.metrics.fontSize);
134
135 const qreal ascender = metricsMultiplier*info.metrics.ascender;
136 const qreal descender = metricsMultiplier*info.metrics.descender;
137 qreal lineGap = distNew - fabs(m_editingType == int(SvgTextCursor::LineHeightTop)? ascender: descender);
138 lineHeight.length.value = (ascender-descender)+lineGap+lineGap;
139 lineHeight.isNormal = false;
140 lineHeight.isNumber = false;
141
142 props.setProperty(KoSvgTextProperties::LineHeightId, QVariant::fromValue(lineHeight));
143 }
144 if (!props.isEmpty()) {
145 int pos = m_cursorPos == m_cursorAnchor? -1: m_cursorPos;
146 int anchor = m_cursorPos == m_cursorAnchor? -1: m_cursorAnchor;
147 if (!newPositions.isEmpty()) {
148 cmd = new KUndo2Command();
149 KUndo2Command *cmd2 = new SvgTextMergePropertiesRangeCommand(m_shape, props, pos, anchor, QSet<KoSvgTextProperties::PropertyId>(), cmd);
150 new SvgTextChangeTransformsOnRange(m_shape, m_cursorPos, m_cursorAnchor, newPositions, newRotations, m_deltaCalc, cmd);
151 cmd->setText(cmd2->text());
152 } else {
153 cmd = new SvgTextMergePropertiesRangeCommand(m_shape, props, pos, anchor);
154 }
155 }
156 }
157 return cmd;
158}
qreal metricsMultiplier(const CssQmlUnitConverter::UserUnits type, const KoSvgText::FontMetrics metrics, const qreal fontSize, const qreal percentageReference)
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
void setText(const KUndo2MagicString &text)
KUndo2MagicString text() const
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1016
@ LineHeightId
KoSvgText::AutoValue.
@ BaselineShiftModeId
KoSvgText::BaselineShiftMode.
void setFontSize(const KoSvgText::CssLengthPercentage length)
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const
KoSvgText::CssLengthPercentage fontSize() const
@ PreformattedText
Text-on-Path falls under this or PrePositionedText depending on collapse of lines.
KoSvgTextProperties propertiesForPos(const int pos, bool inherited=false) const
Return the properties at a given position.
TextType textType() const
textType This enum gives an indication of what kind of text this shape is. The different text types a...
QList< KoSvgTextCharacterInfo > getPositionsAndRotationsForRange(const int startPos, const int endPos) const
getPositionsAndRotationsForRange
The SvgTextMergePropertiesRangeCommand class This sets properties on a specific range in a single tex...
qreal kisDistanceToLine(const QPointF &m, const QLineF &line)
Definition kis_global.h:234
@ ShiftLengthPercentage
Css Length Percentage, percentage is lh.
Definition KoSvgText.h:244
The KoSvgTextCharacterInfo class This is a small struct to convey information about character positio...
KoSvgText::FontMetrics metrics
<Whether the character is in the middle of a cluster.
qint32 fontSize
Currently set size, CSS unit 'em'.
Definition KoSvgText.h:329
qint32 descender
distance for origin to bottom.
Definition KoSvgText.h:340
qint32 ascender
distance from origin to top.
Definition KoSvgText.h:339
bool isNumber
Length or number.
Definition KoSvgText.h:695
CssLengthPercentage length
Definition KoSvgText.h:693
bool isNormal
It's a number indicating the lineHeight;.
Definition KoSvgText.h:696
@ BaselineShift
The text properties handles.

References KoSvgTextCharacterInfo::advance, KoSvgText::FontMetrics::ascender, SvgTextCursor::Ascender, SvgTextCursor::BaselineShift, KoSvgTextProperties::BaselineShiftModeId, KoSvgTextProperties::BaselineShiftValueId, KoSvgText::FontMetrics::descender, SvgTextCursor::Descender, KoShape::documentToShape(), SvgTextCursor::EndPos, KoSvgTextCharacterInfo::finalPos, KoSvgText::FontMetrics::fontSize, KoSvgTextProperties::fontSize(), KoSvgTextShape::getPositionsAndRotationsForRange(), KoSvgTextProperties::isEmpty(), KoSvgText::LineHeightInfo::isNormal, KoSvgText::LineHeightInfo::isNumber, kisDistanceToLine(), KoSvgText::LineHeightInfo::length, length(), SvgTextCursor::LineHeightBottom, KoSvgTextProperties::LineHeightId, SvgTextCursor::LineHeightTop, m_currentDelta, m_cursorAnchor, m_cursorPos, m_deltaCalc, m_dragCurrent, m_dragStart, m_editingType, m_referenceCursorPos, m_shape, KoSvgTextCharacterInfo::metrics, metricsMultiplier(), SvgTextCursor::NoHandle, SvgTextChangeTransformsOnRange::OffsetAll, KoSvgTextShape::PreformattedText, KoSvgTextShape::PrePositionedText, KoSvgTextShape::propertiesForPos(), KoSvgTextProperties::propertyOrDefault(), KoSvgTextCharacterInfo::rotateDeg, SvgTextChangeTransformsOnRange::ScaleAndRotate, KoSvgTextProperties::setFontSize(), KoSvgTextProperties::setProperty(), KUndo2Command::setText(), KoSvgText::ShiftLengthPercentage, SvgTextCursor::StartPos, KUndo2Command::text(), KoSvgTextShape::textType(), and KoSvgText::CssLengthPercentage::value.

◆ finishInteraction()

void SvgTextTypeSettingStrategy::finishInteraction ( Qt::KeyboardModifiers modifiers)
overridevirtual

Override to make final changes to the data on the end of an interaction.

Implements KoInteractionStrategy.

Definition at line 173 of file SvgTextTypeSettingStrategy.cpp.

174{
175 m_modifiers = modifiers;
177}

References cancelInteraction(), and m_modifiers.

◆ handleMouseMove()

void SvgTextTypeSettingStrategy::handleMouseMove ( const QPointF & mouseLocation,
Qt::KeyboardModifiers modifiers )
overridevirtual

Extending classes should implement this method to update the selectedShapes based on the new mouse position.

Parameters
mouseLocationthe new location in pt
modifiersOR-ed set of keys pressed.

Implements KoInteractionStrategy.

Definition at line 35 of file SvgTextTypeSettingStrategy.cpp.

36{
37 QPointF delta = mouseLocation - m_dragStart;
38 m_modifiers = modifiers;
39
40 if (m_modifiers & Qt::ShiftModifier) {
41 delta = snapToClosestAxis(delta);
42 m_dragCurrent = m_dragStart + delta;
43 m_currentDelta = delta;
44 } else {
46 tool()->canvas()->snapGuide()->snap(mouseLocation, modifiers);
48 }
49
50
52 SvgTextShapeManagerBlocker blocker(tool()->canvas()->shapeManager());
53 // TODO: replace with KoShapeBulkActionLock (recursive locking is not supported right now)
54 QRectF updateRect = m_shape->boundingRect();
55 if (m_previousCmd) {
56 m_previousCmd->undo();
57 }
59 if (m_previousCmd) {
60 m_previousCmd->redo();
61 }
62 updateRect |= m_shape->boundingRect();
63 blocker.unlock();
64 m_shape->updateAbsolute(updateRect);
65 }
66}
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
KUndo2Command * createCommand() override
PointType snapToClosestAxis(PointType P)
Definition kis_global.h:199

References KoSvgTextShape::boundingRect(), KoToolBase::canvas(), createCommand(), m_currentDelta, m_dragCurrent, m_dragStart, m_editingType, m_modifiers, m_previousCmd, m_shape, SvgTextCursor::NoHandle, KoSnapGuide::snap(), KoCanvasBase::snapGuide, snapToClosestAxis(), KoInteractionStrategy::tool(), and KoShape::updateAbsolute().

Member Data Documentation

◆ m_currentDelta

QPointF SvgTextTypeSettingStrategy::m_currentDelta
private

Definition at line 40 of file SvgTextTypeSettingStrategy.h.

◆ m_cursorAnchor

int SvgTextTypeSettingStrategy::m_cursorAnchor
private

Definition at line 43 of file SvgTextTypeSettingStrategy.h.

◆ m_cursorPos

int SvgTextTypeSettingStrategy::m_cursorPos
private

Definition at line 42 of file SvgTextTypeSettingStrategy.h.

◆ m_deltaCalc

bool SvgTextTypeSettingStrategy::m_deltaCalc
private

Definition at line 47 of file SvgTextTypeSettingStrategy.h.

◆ m_dragCurrent

QPointF SvgTextTypeSettingStrategy::m_dragCurrent
private

Definition at line 39 of file SvgTextTypeSettingStrategy.h.

◆ m_dragStart

QPointF SvgTextTypeSettingStrategy::m_dragStart
private

Definition at line 38 of file SvgTextTypeSettingStrategy.h.

◆ m_editingType

int SvgTextTypeSettingStrategy::m_editingType
private

Definition at line 44 of file SvgTextTypeSettingStrategy.h.

◆ m_modifiers

Qt::KeyboardModifiers SvgTextTypeSettingStrategy::m_modifiers
private

Definition at line 48 of file SvgTextTypeSettingStrategy.h.

◆ m_previousCmd

QScopedPointer<KUndo2Command> SvgTextTypeSettingStrategy::m_previousCmd
private

Definition at line 50 of file SvgTextTypeSettingStrategy.h.

◆ m_referenceCursorPos

int SvgTextTypeSettingStrategy::m_referenceCursorPos
private

Definition at line 45 of file SvgTextTypeSettingStrategy.h.

◆ m_shape

KoSvgTextShape* SvgTextTypeSettingStrategy::m_shape
private

Definition at line 37 of file SvgTextTypeSettingStrategy.h.

◆ m_textData

KoSvgTextShapeMementoSP SvgTextTypeSettingStrategy::m_textData
private

Definition at line 51 of file SvgTextTypeSettingStrategy.h.


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