7#ifndef SVG_INLINE_SIZE_HELPER_H
8#define SVG_INLINE_SIZE_HELPER_H
23 if (!inlineSizeProp.
isAuto) {
60 [[nodiscard]]
static inline std::optional<InlineSizeInfo>
fromShape(
KoSvgTextShape *
const shape, qreal dashesLength = 36.0)
63 if (inlineSize <= 0) {
80 anchor = VisualAnchor::LeftOrTop;
82 anchor = VisualAnchor::RightOrBottom;
86 anchor = VisualAnchor::Mid;
90 anchor = VisualAnchor::RightOrBottom;
92 anchor = VisualAnchor::LeftOrTop;
99 const double baseline = yPos;
105 case VisualAnchor::LeftOrTop:
107 right = xPos + inlineSize;
109 case VisualAnchor::Mid:
110 left = xPos - inlineSize * 0.5;
111 right = xPos + inlineSize * 0.5;
113 case VisualAnchor::RightOrBottom:
114 left = xPos - inlineSize;
125 const QRectF outline = shape->
outlineRect().isEmpty()? QRectF(caret.p2(), caret.p1()): shape->
outlineRect();
126 QTransform editorTransform;
127 switch (writingMode) {
131 bottom = outline.bottom();
134 editorTransform.rotate(90.0);
135 top = -outline.right();
136 bottom = -outline.left();
139 editorTransform.rotate(-90.0);
140 editorTransform.scale(-1.0, 1.0);
141 top = outline.left();
142 bottom = outline.right();
146 QLineF scale = editorTransform.map(QLineF(0, 0, 0, 1.0));
148 scale = editorTransform.inverted().map(scale);
156 dashesLength * scale.length(),
166 return {left, top, left, bottom};
171 return {right, top, right, bottom};
176 return {QPointF(left, top), QPointF(right, bottom + dashesLength)};
179 [[nodiscard]]
inline QLineF
generateDashLine(
const QLineF line,
const qreal dashLength = 4.0)
const
181 QPointF start = line.p2();
183 dash.setLength(line.length() + dashLength);
197 return editorTransform.map(QLineF{left, baseline, right, baseline});
208 return shapeTransform.map(baselineLineLocal());
214 case VisualAnchor::LeftOrTop:
215 case VisualAnchor::Mid:
217 return Side::RightOrBottom;
218 case VisualAnchor::RightOrBottom:
219 return Side::LeftOrTop;
225 switch (endLineSide()) {
226 case Side::LeftOrTop:
227 return editorTransform.map(leftLineRaw());
228 case Side::RightOrBottom:
230 return editorTransform.map(rightLineRaw());
236 switch (endLineSide()) {
237 case Side::LeftOrTop:
238 return generateDashLine(editorTransform.map(leftLineRaw()), dashesLength);
239 case Side::RightOrBottom:
241 return generateDashLine(editorTransform.map(rightLineRaw()), dashesLength);
247 return shapeTransform.map(endLineLocal());
253 case VisualAnchor::LeftOrTop:
254 case VisualAnchor::Mid:
256 return Side::LeftOrTop;
257 case VisualAnchor::RightOrBottom:
258 return Side::RightOrBottom;
264 switch (endLineSide()) {
265 case Side::LeftOrTop:
266 return editorTransform.map(rightLineRaw());
267 case Side::RightOrBottom:
269 return editorTransform.map(leftLineRaw());
275 switch (endLineSide()) {
276 case Side::LeftOrTop:
277 return generateDashLine(editorTransform.map(rightLineRaw()), dashesLength);
278 case Side::RightOrBottom:
280 return generateDashLine(editorTransform.map(leftLineRaw()), dashesLength);
286 return shapeTransform.map(startLineLocal());
292 switch (endLineSide()) {
293 case Side::LeftOrTop:
294 endLine = leftLineRaw();
296 case Side::RightOrBottom:
298 endLine = rightLineRaw();
301 const QRectF
rect{endLine.x1() - grabThreshold,
304 bottom - top + grabThreshold * 2};
305 const QPolygonF poly(
rect);
306 return shapeTransform.map(editorTransform.map(poly));
312 switch (endLineSide()) {
313 case Side::LeftOrTop:
314 startLine = rightLineRaw();
316 case Side::RightOrBottom:
318 startLine = leftLineRaw();
321 const QRectF
rect{startLine.x1() - grabThreshold,
324 bottom - top + grabThreshold * 2};
325 const QPolygonF poly(
rect);
326 return shapeTransform.map(editorTransform.map(poly));
331 return shapeTransform.mapRect(editorTransform.mapRect(boundingRectRaw()));
QTransform absoluteTransformation() const
@ TextAnchorId
KoSvgText::TextAnchor.
@ InlineSizeId
KoSvgText::AutoValue.
@ WritingModeId
KoSvgText::WritingMode.
@ DirectionId
KoSvgText::Direction.
QVariant property(PropertyId id, const QVariant &defaultValue=QVariant()) const
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
KoSvgTextProperties textProperties() const
TextAnchor
Where the text is anchored for SVG 1.1 text and 'inline-size'.
@ AnchorEnd
Anchor right for LTR, left for RTL.
@ AnchorStart
Anchor left for LTR, right for RTL.
@ AnchorMiddle
Anchor to the middle.
Direction
Base direction used by Bidi algorithm.
static double getInlineSizePt(const KoSvgTextShape *const shape)
QTransform editorTransform
Transformation from inline-size editor (writing-mode transformation) to shape.
double dashesLength
Length of the dashes at the end.
Side startLineSide() const
static std::optional< InlineSizeInfo > fromShape(KoSvgTextShape *const shape, qreal dashesLength=36.0)
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.
double baseline
Baseline coord along the block-flow direction.
QLineF endLineLocal() const
QLineF leftLineRaw() const
double bottom
Bottom coord along the block-flow direction (left for h-rl, right for h-lr)
QLineF rightLineRaw() const
double left
Left coord (vertical mode) or top coord (horizontal mode)
double right
Right coord (vertical mode) or bottom coord (horizontal mode)
QPolygonF startLineGrabRect(double grabThreshold) const
QLineF endLineDashes() const
QPolygonF endLineGrabRect(double grabThreshold) const
double top
Top coord along the block-flow direction (right for h-rl, left for h-lr)
QRectF boundingRect() const
QLineF startLineLocal() const
QLineF generateDashLine(const QLineF line, const qreal dashLength=4.0) const
QRectF boundingRectRaw() const
QLineF baselineLine() const
Gets a line representing the first line baseline. This always goes from left to right by the inline-b...
QLineF startLineDashes() const