Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgInlineSizeHelper::InlineSizeInfo Struct Reference

#include <SvgInlineSizeHelper.h>

Public Member Functions

QLineF baselineLine () const
 Gets a line representing the first line baseline. This always goes from left to right by the inline-base direction, then mapped by the editor and the shape transformation.
 
QLineF baselineLineLocal () const
 Gets a shape-local line representing the first line baseline. This always goes from left to right by the inline-base direction, then mapped by the editor transformation.
 
QRectF boundingRect () const
 
QLineF endLine () const
 
QLineF endLineDashes () const
 
QPolygonF endLineGrabRect (double grabThreshold) const
 
QLineF endLineLocal () const
 
Side endLineSide () const
 
QLineF startLine () const
 
QLineF startLineDashes () const
 
QPolygonF startLineGrabRect (double grabThreshold) const
 
QLineF startLineLocal () const
 
Side startLineSide () const
 

Static Public Member Functions

static std::optional< InlineSizeInfofromShape (KoSvgTextShape *const shape, qreal dashesLength=36.0)
 

Public Attributes

VisualAnchor anchor
 
double baseline
 Baseline coord along the block-flow direction.
 
double bottom
 Bottom coord along the block-flow direction (left for h-rl, right for h-lr)
 
double dashesLength
 Length of the dashes at the end.
 
QTransform editorTransform
 Transformation from inline-size editor (writing-mode transformation) to shape.
 
double inlineSize
 
double left
 Left coord (vertical mode) or top coord (horizontal mode)
 
double right
 Right coord (vertical mode) or bottom coord (horizontal mode)
 
QTransform shapeTransform
 Transformation from shape local to document.
 
double top
 Top coord along the block-flow direction (right for h-rl, left for h-lr)
 

Private Member Functions

QRectF boundingRectRaw () const
 
QLineF generateDashLine (const QLineF line, const qreal dashLength=4.0) const
 
QLineF leftLineRaw () const
 
QLineF rightLineRaw () const
 

Detailed Description

Definition at line 40 of file SvgInlineSizeHelper.h.

Member Function Documentation

◆ baselineLine()

QLineF SvgInlineSizeHelper::InlineSizeInfo::baselineLine ( ) const
inline

Gets a line representing the first line baseline. This always goes from left to right by the inline-base direction, then mapped by the editor and the shape transformation.

Returns
QLineF

Definition at line 206 of file SvgInlineSizeHelper.h.

207 {
208 return shapeTransform.map(baselineLineLocal());
209 }
QLineF baselineLineLocal() const
Gets a shape-local line representing the first line baseline. This always goes from left to right by ...
QTransform shapeTransform
Transformation from shape local to document.

◆ baselineLineLocal()

QLineF SvgInlineSizeHelper::InlineSizeInfo::baselineLineLocal ( ) const
inline

Gets a shape-local line representing the first line baseline. This always goes from left to right by the inline-base direction, then mapped by the editor transformation.

Returns
QLineF

Definition at line 195 of file SvgInlineSizeHelper.h.

196 {
197 return editorTransform.map(QLineF{left, baseline, right, baseline});
198 }
QTransform editorTransform
Transformation from inline-size editor (writing-mode transformation) to shape.
double baseline
Baseline coord along the block-flow direction.
double left
Left coord (vertical mode) or top coord (horizontal mode)
double right
Right coord (vertical mode) or bottom coord (horizontal mode)

◆ boundingRect()

QRectF SvgInlineSizeHelper::InlineSizeInfo::boundingRect ( ) const
inline

Definition at line 329 of file SvgInlineSizeHelper.h.

330 {
331 return shapeTransform.mapRect(editorTransform.mapRect(boundingRectRaw()));
332 }

◆ boundingRectRaw()

QRectF SvgInlineSizeHelper::InlineSizeInfo::boundingRectRaw ( ) const
inlineprivate

Definition at line 174 of file SvgInlineSizeHelper.h.

175 {
176 return {QPointF(left, top), QPointF(right, bottom + dashesLength)};
177 }
double dashesLength
Length of the dashes at the end.
double bottom
Bottom coord along the block-flow direction (left for h-rl, right for h-lr)
double top
Top coord along the block-flow direction (right for h-rl, left for h-lr)

◆ endLine()

QLineF SvgInlineSizeHelper::InlineSizeInfo::endLine ( ) const
inline

Definition at line 245 of file SvgInlineSizeHelper.h.

246 {
247 return shapeTransform.map(endLineLocal());
248 }

◆ endLineDashes()

QLineF SvgInlineSizeHelper::InlineSizeInfo::endLineDashes ( ) const
inline

Definition at line 234 of file SvgInlineSizeHelper.h.

◆ endLineGrabRect()

QPolygonF SvgInlineSizeHelper::InlineSizeInfo::endLineGrabRect ( double grabThreshold) const
inline

Definition at line 289 of file SvgInlineSizeHelper.h.

290 {
291 QLineF endLine;
292 switch (endLineSide()) {
293 case Side::LeftOrTop:
295 break;
297 default:
299 break;
300 }
301 const QRectF rect{endLine.x1() - grabThreshold,
302 top - grabThreshold,
303 grabThreshold * 2,
304 bottom - top + grabThreshold * 2};
305 const QPolygonF poly(rect);
306 return shapeTransform.map(editorTransform.map(poly));
307 }

◆ endLineLocal()

QLineF SvgInlineSizeHelper::InlineSizeInfo::endLineLocal ( ) const
inline

Definition at line 223 of file SvgInlineSizeHelper.h.

224 {
225 switch (endLineSide()) {
226 case Side::LeftOrTop:
227 return editorTransform.map(leftLineRaw());
229 default:
230 return editorTransform.map(rightLineRaw());
231 }
232 }

◆ endLineSide()

Side SvgInlineSizeHelper::InlineSizeInfo::endLineSide ( ) const
inline

◆ fromShape()

static std::optional< InlineSizeInfo > SvgInlineSizeHelper::InlineSizeInfo::fromShape ( KoSvgTextShape *const shape,
qreal dashesLength = 36.0 )
inlinestatic

Definition at line 60 of file SvgInlineSizeHelper.h.

61 {
62 const double inlineSize = getInlineSizePt(shape);
63 if (inlineSize <= 0) {
64 return {};
65 }
66 KoSvgTextProperties props = shape->propertiesForPos(-1);
67
70 const KoSvgText::Direction direction =
72 const KoSvgText::TextAnchor textAnchor =
74
75 VisualAnchor anchor{};
76 switch (textAnchor) {
78 default:
81 } else {
83 }
84 break;
87 break;
91 } else {
93 }
94 break;
95 }
96 const double xPos = writingMode == KoSvgText::WritingMode::HorizontalTB? shape->initialTextPosition().x(): shape->initialTextPosition().y();
97 const double yPos = writingMode == KoSvgText::WritingMode::HorizontalTB? shape->initialTextPosition().y(): shape->initialTextPosition().x();
98
99 const double baseline = yPos;
100 double left{};
101 double right{};
102 double top{};
103 double bottom{};
104 switch (anchor) {
106 left = xPos;
107 right = xPos + inlineSize;
108 break;
110 left = xPos - inlineSize * 0.5;
111 right = xPos + inlineSize * 0.5;
112 break;
114 left = xPos - inlineSize;
115 right = xPos;
116 break;
117 };
118
119 // We piggyback on the shape transformation that we already need to
120 // deal with to also handle the different orientations of writing-mode.
121 // We default to the "default caret size" when the textShape (and thus outline) is empty.
122 QLineF caret;
123 QColor c;
124 shape->cursorForPos(0, caret, c);
125 const QRectF outline = shape->outlineRect().isEmpty()? QRectF(caret.p2(), caret.p1()): shape->outlineRect();
126 QTransform editorTransform;
127 switch (writingMode) {
129 default:
130 top = outline.top();
131 bottom = outline.bottom();
132 break;
134 editorTransform.rotate(90.0);
135 top = -outline.right();
136 bottom = -outline.left();
137 break;
139 editorTransform.rotate(-90.0);
140 editorTransform.scale(-1.0, 1.0);
141 top = outline.left();
142 bottom = outline.right();
143 break;
144 }
145
146 QLineF scale = editorTransform.map(QLineF(0, 0, 0, 1.0));
147 scale = shape->absoluteTransformation().inverted().map(scale);
148 scale = editorTransform.inverted().map(scale);
149
150 InlineSizeInfo ret{inlineSize,
151 baseline,
152 left,
153 right,
154 top,
155 bottom,
156 dashesLength * scale.length(),
157 anchor,
159 shape->absoluteTransformation()};
160 return {ret};
161 }
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
@ TextAnchorId
KoSvgText::TextAnchor.
@ WritingModeId
KoSvgText::WritingMode.
@ DirectionId
KoSvgText::Direction.
QVariant propertyOrDefault(PropertyId id) const
QPointF initialTextPosition
KoSvgTextProperties propertiesForPos(const int pos, bool inherited=false) const
Return the properties at a given position.
QPainterPath cursorForPos(int pos, QLineF &caret, QColor &color, double bidiFlagSize=1.0)
cursorForPos returns the QPainterPath associated with this cursorPosition.
QRectF outlineRect() const override
TextAnchor
Where the text is anchored for SVG 1.1 text and 'inline-size'.
Definition KoSvgText.h:79
@ AnchorEnd
Anchor right for LTR, left for RTL.
Definition KoSvgText.h:82
@ AnchorStart
Anchor left for LTR, right for RTL.
Definition KoSvgText.h:80
@ AnchorMiddle
Anchor to the middle.
Definition KoSvgText.h:81
Direction
Base direction used by Bidi algorithm.
Definition KoSvgText.h:48
@ DirectionLeftToRight
Definition KoSvgText.h:49
@ HorizontalTB
Definition KoSvgText.h:38
static double getInlineSizePt(const KoSvgTextShape *const shape)

References KoShape::absoluteTransformation(), KoSvgText::AnchorEnd, KoSvgText::AnchorMiddle, KoSvgText::AnchorStart, KoSvgTextShape::cursorForPos(), KoSvgTextProperties::DirectionId, KoSvgText::DirectionLeftToRight, SvgInlineSizeHelper::getInlineSizePt(), KoSvgText::HorizontalTB, KoSvgTextShape::initialTextPosition, KoSvgTextShape::outlineRect(), KoSvgTextShape::propertiesForPos(), KoSvgTextProperties::propertyOrDefault(), KoSvgTextProperties::TextAnchorId, KoSvgText::VerticalLR, KoSvgText::VerticalRL, and KoSvgTextProperties::WritingModeId.

◆ generateDashLine()

QLineF SvgInlineSizeHelper::InlineSizeInfo::generateDashLine ( const QLineF line,
const qreal dashLength = 4.0 ) const
inlineprivate

Definition at line 179 of file SvgInlineSizeHelper.h.

180 {
181 QPointF start = line.p2();
182 QLineF dash = line;
183 dash.setLength(line.length() + dashLength);
184 dash.setP1(start);
185 return dash;
186 }

◆ leftLineRaw()

QLineF SvgInlineSizeHelper::InlineSizeInfo::leftLineRaw ( ) const
inlineprivate

Definition at line 164 of file SvgInlineSizeHelper.h.

165 {
166 return {left, top, left, bottom};
167 }

◆ rightLineRaw()

QLineF SvgInlineSizeHelper::InlineSizeInfo::rightLineRaw ( ) const
inlineprivate

Definition at line 169 of file SvgInlineSizeHelper.h.

170 {
171 return {right, top, right, bottom};
172 }

◆ startLine()

QLineF SvgInlineSizeHelper::InlineSizeInfo::startLine ( ) const
inline

Definition at line 284 of file SvgInlineSizeHelper.h.

285 {
286 return shapeTransform.map(startLineLocal());
287 }

◆ startLineDashes()

QLineF SvgInlineSizeHelper::InlineSizeInfo::startLineDashes ( ) const
inline

Definition at line 273 of file SvgInlineSizeHelper.h.

274 {
275 switch (endLineSide()) {
276 case Side::LeftOrTop:
279 default:
281 }
282 }

◆ startLineGrabRect()

QPolygonF SvgInlineSizeHelper::InlineSizeInfo::startLineGrabRect ( double grabThreshold) const
inline

Definition at line 309 of file SvgInlineSizeHelper.h.

310 {
311 QLineF startLine;
312 switch (endLineSide()) {
313 case Side::LeftOrTop:
315 break;
317 default:
319 break;
320 }
321 const QRectF rect{startLine.x1() - grabThreshold,
322 top - grabThreshold,
323 grabThreshold * 2,
324 bottom - top + grabThreshold * 2};
325 const QPolygonF poly(rect);
326 return shapeTransform.map(editorTransform.map(poly));
327 }

◆ startLineLocal()

QLineF SvgInlineSizeHelper::InlineSizeInfo::startLineLocal ( ) const
inline

Definition at line 262 of file SvgInlineSizeHelper.h.

263 {
264 switch (endLineSide()) {
265 case Side::LeftOrTop:
266 return editorTransform.map(rightLineRaw());
268 default:
269 return editorTransform.map(leftLineRaw());
270 }
271 }

◆ startLineSide()

Side SvgInlineSizeHelper::InlineSizeInfo::startLineSide ( ) const
inline

Definition at line 250 of file SvgInlineSizeHelper.h.

251 {
252 switch (anchor) {
255 default:
256 return Side::LeftOrTop;
258 return Side::RightOrBottom;
259 }
260 }

Member Data Documentation

◆ anchor

VisualAnchor SvgInlineSizeHelper::InlineSizeInfo::anchor

Definition at line 54 of file SvgInlineSizeHelper.h.

◆ baseline

double SvgInlineSizeHelper::InlineSizeInfo::baseline

Baseline coord along the block-flow direction.

Definition at line 43 of file SvgInlineSizeHelper.h.

◆ bottom

double SvgInlineSizeHelper::InlineSizeInfo::bottom

Bottom coord along the block-flow direction (left for h-rl, right for h-lr)

Definition at line 51 of file SvgInlineSizeHelper.h.

◆ dashesLength

double SvgInlineSizeHelper::InlineSizeInfo::dashesLength

Length of the dashes at the end.

Definition at line 53 of file SvgInlineSizeHelper.h.

◆ editorTransform

QTransform SvgInlineSizeHelper::InlineSizeInfo::editorTransform

Transformation from inline-size editor (writing-mode transformation) to shape.

Definition at line 56 of file SvgInlineSizeHelper.h.

◆ inlineSize

double SvgInlineSizeHelper::InlineSizeInfo::inlineSize

Definition at line 41 of file SvgInlineSizeHelper.h.

◆ left

double SvgInlineSizeHelper::InlineSizeInfo::left

Left coord (vertical mode) or top coord (horizontal mode)

Definition at line 45 of file SvgInlineSizeHelper.h.

◆ right

double SvgInlineSizeHelper::InlineSizeInfo::right

Right coord (vertical mode) or bottom coord (horizontal mode)

Definition at line 47 of file SvgInlineSizeHelper.h.

◆ shapeTransform

QTransform SvgInlineSizeHelper::InlineSizeInfo::shapeTransform

Transformation from shape local to document.

Definition at line 58 of file SvgInlineSizeHelper.h.

◆ top

double SvgInlineSizeHelper::InlineSizeInfo::top

Top coord along the block-flow direction (right for h-rl, left for h-lr)

Definition at line 49 of file SvgInlineSizeHelper.h.


The documentation for this struct was generated from the following file: