Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSvgTextShape.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef KOSVGTEXTSHAPE_H
8#define KOSVGTEXTSHAPE_H
9
10#include "kritaflake_export.h"
11#include <KoSvgTextProperties.h>
12
13#include <KoShapeFactoryBase.h>
14#include <SvgShape.h>
15#include <KoShape.h>
16#include <KoSvgText.h>
18#include <QFlags>
19
23
24#define KoSvgTextShape_SHAPEID "KoSvgTextShapeID"
28class KRITAFLAKE_EXPORT KoSvgTextShape : public KoShape, public SvgShape
29{
30public:
33 ~KoSvgTextShape() override;
34
35 static const QString &defaultPlaceholderText();
36
37 KoShape* cloneShape() const override;
38
39 void paint(QPainter &painter) const override;
40 void paintStroke(QPainter &painter) const override;
41
42 QPainterPath outline() const override;
43 QRectF outlineRect() const override;
44 QRectF boundingRect() const override;
45
46 enum class DebugElement {
47 CharBbox = 1 << 0,
48 LineBox = 1 << 1,
49 };
51 void paintDebug(QPainter &painter, DebugElements elements) const;
52
58 void relayout() const;
59
67 KoShape * textOutline() const;
68
69 enum TextType {
70 PrePositionedText = 0,
72 PreformattedText,
75 TextInShape
76 };
87 TextType textType() const;
88
93 void setShapesInside(QList<KoShape*> shapesInside);
94
100
105 void setShapesSubtract(QList<KoShape*> shapesSubtract);
106
112
113 QMap<QString, QString> shapeTypeSpecificStyles(SvgSavingContext &context) const;
114
115 void setResolution(qreal xRes, qreal yRes) override;
116
117
118
121 int posLeft(int pos, bool visual = false);
124 int posRight(int pos, bool visual = false);
126 int posUp(int pos, bool visual = false);
128 int posDown(int pos, bool visual = false);
129
137 int lineStart(int pos);
145 int lineEnd(int pos);
146
154 int wordLeft(int pos, bool visual = false);
162 int wordRight(int pos, bool visual = false);
163
172 int nextIndex(int pos);
173
180 int previousIndex(int pos);
181
188 int nextLine(int pos);
195 int previousLine(int pos);
196
203 int wordEnd(int pos);
210 int wordStart(int pos);
211
219 QPainterPath cursorForPos(int pos, QLineF &caret, QColor &color, double bidiFlagSize = 1.0);
220
229 QPainterPath selectionBoxes(int pos, int anchor);
230
231 QPainterPath underlines(int pos, int anchor,
232 KoSvgText::TextDecorations decor,
234 qreal minimum, bool thick);
235
245 int posForPoint(QPointF point, int start = -1, int end = -1, bool *overlaps = nullptr);
246
261 int posForPointLineSensitive(QPointF point);
270 int posForIndex(int index, bool firstIndex = false, bool skipSynthetic = false) const;
277 int indexForPos(int pos) const;
278
285 QPointF initialTextPosition() const;
286
287 /*--------------- Edit text ---------------*/
295 bool insertText(int pos, QString text);
296
312 bool removeText(int &index, int &length);
313
315 KoSvgTextProperties propertiesForPos(const int pos, bool inherited = false) const;
316
324 QList<KoSvgTextProperties> propertiesForRange(const int startPos, const int endPos, bool inherited = false) const;
325
332 void setPropertiesAtPos(int pos, KoSvgTextProperties properties);
333
349 void mergePropertiesIntoRange(const int startPos,
350 const int endPos,
351 const KoSvgTextProperties properties,
352 const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>());
353
354
362 std::unique_ptr<KoSvgTextShape> copyRange(int index, int length) const;
363
371 bool insertRichText(int pos, const KoSvgTextShape *richText);
372
374 void cleanUp();
375
376/*****************************************************************************
377 * KoSvgTextNodeIndex functions.
378 *
379 * SVG Text is internally a tree of nodes, with each node having text
380 * properties, and the child nodes furthest from the root having text content.
381 * While we can access the latter by using ranges, and we can easily access
382 * the root node by using -1, there's no way to access the nodes that may
383 * be inbetween. KoSvgTextNodeIndex allows accessing these nodes.
384 *
385 ****************************************************************************/
386
392 KoSvgTextNodeIndex findNodeIndexForPropertyId(KoSvgTextProperties::PropertyId propertyId);
393
401 QPair<int, int> findRangeForNodeIndex(const KoSvgTextNodeIndex &node) const;
402
403 /*--------------- Properties ---------------*/
404
405 KoSvgTextProperties textProperties() const;
407 void setBackground(QSharedPointer<KoShapeBackground> background) override;
408 KoShapeStrokeModelSP stroke() const override;
409 void setStroke(KoShapeStrokeModelSP stroke) override;
410 QVector<PaintOrder> paintOrder() const override;
411 void setPaintOrder(PaintOrder first, PaintOrder second) override;
412
413
420 QString plainText();
421
427 KoSvgText::WritingMode writingMode() const;
428
430 struct KRITAFLAKE_EXPORT TextCursorChangeListener : public ShapeChangeListener {
431 void notifyShapeChanged(ChangeType type, KoShape *shape) override;
432 virtual void notifyCursorPosChanged(int pos, int anchor) = 0;
433 virtual void notifyMarkupChanged() = 0;
434 };
436 void notifyCursorPosChanged(int pos, int anchor);
438 void notifyMarkupChanged();
439
440 /*--------------- Converter functions ---------------*/
441
448 void convertCharTransformsToPreformatted(bool makeInlineSize = false);
449
455 void setCharacterTransformsFromLayout();
456
457 /*--------------- Loading / Saving ------------------*/
458
460 bool saveSvg(SvgSavingContext &context) override;
461 // Used by the html writer.
462 bool saveHtml(HtmlSavingContext &context);
463
465 void enterNodeSubtree();
467 void leaveNodeSubtree();
468
470 KoSvgTextShapeMementoSP getMemento();
471
473 void setMemento(const KoSvgTextShapeMementoSP memento);
474
476 void setMemento(const KoSvgTextShapeMementoSP memento, int pos, int anchor);
477
479 void debugParsing();
480
481 /***
482 * This blocks the shape from automatically calling relayout
483 * when the text or properties change. Relayout needs to be called
484 * in this mode.
485 * Used in the SVGTextLabel.
486 */
487 void setRelayoutBlocked(const bool disable);
488
494 bool relayoutIsBlocked() const;
495
504 void setFontMatchingDisabled(const bool disable);
505
510 bool fontMatchingDisabled() const;
511
512protected:
513
514 void shapeChanged(ChangeType type, KoShape *shape) override;
515
516private:
517 friend class TestSvgText;
518 friend class KoSvgTextLoader;
525 int nextPos(int pos, bool visual);
526
533 int previousPos(int pos, bool visual);
534
540 QPainterPath defaultCursorShape();
541
542 void setMementoImpl(const KoSvgTextShapeMementoSP memento);
543
544 class Private;
545 QScopedPointer<Private> d;
546};
547
548Q_DECLARE_OPERATORS_FOR_FLAGS(KoSvgTextShape::DebugElements)
549
550class KRITAFLAKE_EXPORT KoSvgTextShapeMemento {
551public:
554private:
555 friend class KoSvgTextShape;
556};
557
567class KRITAFLAKE_EXPORT KoSvgTextNodeIndex {
568public:
571
577 KoSvgTextProperties *properties();
578
584 KoSvgText::TextOnPathInfo *textPathInfo();
585
590 KoShape *textPath();
591
592private:
593 // for internal factory use only
595
596private:
597 friend class KoSvgTextShape;
598 struct Private;
599 QScopedPointer<Private> d;
600
601};
602
604{
605
606public:
610
611 KoShape *createDefaultShape(KoDocumentResourceManager *documentResources = 0) const override;
612
613 KoShape *createShape(const KoProperties *params, KoDocumentResourceManager *documentResources = 0) const override;
615 bool supports(const QDomElement &e, KoShapeLoadingContext &context) const override;
616};
617
618
619
620#endif // KOSVGTEXTSHAPE_H
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
QSharedPointer< KoSvgTextShapeMemento > KoSvgTextShapeMementoSP
The HtmlSavingContext class provides context for saving a flake-based document to html.
virtual void setPaintOrder(PaintOrder first, PaintOrder second)
setPaintOrder set the paint order. As there's only three entries in any given paintorder,...
Definition KoShape.cpp:749
virtual void paintStroke(QPainter &painter) const
paintStroke paints the shape's stroked outline
Definition KoShape.cpp:223
virtual QRectF outlineRect() const
Definition KoShape.cpp:637
virtual QPainterPath outline() const
Definition KoShape.cpp:630
virtual QVector< PaintOrder > paintOrder() const
paintOrder
Definition KoShape.cpp:773
virtual KoShapeStrokeModelSP stroke() const
Definition KoShape.cpp:1067
virtual void setResolution(qreal xRes, qreal yRes)
Definition KoShape.cpp:1416
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
Definition KoShape.cpp:1253
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
virtual void paint(QPainter &painter) const =0
Paint the shape fill The class extending this one is responsible for painting itself....
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200
virtual QSharedPointer< KoShapeBackground > background() const
Definition KoShape.cpp:926
The KoSvgTextNodeIndex class.
QScopedPointer< Private > d
KoSvgTextShapeFactory()
constructor
bool supports(const QDomElement &e, KoShapeLoadingContext &context) const override
Reimplemented.
KoShape * createDefaultShape(KoDocumentResourceManager *documentResources=0) const override
KoShape * createShape(const KoProperties *params, KoDocumentResourceManager *documentResources=0) const override
QString plainText()
plainText plain text of all text inside this text shape, without the bidi controls or any transforms.
@ InlineWrap
Uses inline size to wrap and preserves spaces.
QPointF initialTextPosition() const
initialTextPosition Returns the initial text position as per SVG algorithm. The eventual result of th...
QScopedPointer< Private > d
Q_DECLARE_FLAGS(DebugElements, DebugElement)
QList< KoShape * > shapesSubtract() const
shapesSubtract
QList< KoShape * > shapesInside() const
shapesInside
Context for saving svg files.
An interface providing svg loading and saving routines.
Definition SvgShape.h:18
virtual bool saveSvg(SvgSavingContext &context)
Saves data utilizing specified svg saving context.
Definition SvgShape.cpp:14
Q_DECLARE_OPERATORS_FOR_FLAGS(KisBaseRectsWalker::SubtreeVisitFlags)
TextDecorationStyle
Style of the text-decoration.
Definition KoSvgText.h:265
ShapeChangeListener so we can inform any text cursors that the cursor needs updating.
virtual void notifyCursorPosChanged(int pos, int anchor)=0
The LineBox struct.