Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Fix preformatted text when text is right to left.

Wolthera van Hövell tot Westerflier1b9bd397d3eb
diff --git a/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp b/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp
index d5d73fdc3d..8b5905979d 100644
--- a/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp
+++ b/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp
@@ -425,8 +425,13 @@ void finalizeLine(QVector<CharacterResult> &result,
}
applyInlineSizeAnchoring(result, *currentChunk, anchor, anchorPoint, ltr, isHorizontal, currentLine.textIndent, resHandler);
} else {
- // this adds a length for preformated text, only useful for debug.
- currentChunk->length.setLength(isHorizontal? currentChunk->boundingBox.width(): currentChunk->boundingBox.height());
+ if (!ltr) {
+ // RTL relies on the start being 0.0, so we need to align it to the startAnchor.
+ applyInlineSizeAnchoring(result, *currentChunk, KoSvgText::AnchorStart, currentChunk->length.p1(), ltr, isHorizontal, currentLine.textIndent, resHandler);
+ } else {
+ // this adds a length for preformated text, only useful for debug.
+ currentChunk->length.setLength(isHorizontal? currentChunk->boundingBox.width(): currentChunk->boundingBox.height());
+ }
}
}
lineOffset += lineHeightOffset(writingMode, result, currentLine, firstLine, resHandler);
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index 6bc51df200..58212c1bc8 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -518,7 +518,7 @@ public:
void applyTextLength(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QVector<CharacterResult> &result, int &currentIndex, int &resolvedDescendentNodes, bool isHorizontal,
const KoSvgTextProperties resolvedProps, const KoSvgText::ResolutionHandler &resHandler);
static void applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal, const KoSvgText::ResolutionHandler resHandler);
- static qreal anchoredChunkShift(const QVector<CharacterResult> &result, const bool isHorizontal, const int start, int &i);
+ static qreal anchoredChunkShift(const QVector<CharacterResult> &result, const bool isHorizontal, const int start, int &end);
static qreal
characterResultOnPath(CharacterResult &cr, qreal length, qreal offset, bool isHorizontal, bool isClosed);
static QPainterPath stretchGlyphOnPath(const QPainterPath &glyph,
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index 64b86d4c52..bced35c1f8 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -1679,27 +1679,28 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &en
// NOLINTNEXTLINE(readability-function-cognitive-complexity)
void KoSvgTextShape::Private::applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal, const KoSvgText::ResolutionHandler resHandler)
{
- int i = 0;
+ int end = 0;
int start = 0;
while (start < result.size()) {
- qreal shift = anchoredChunkShift(result, isHorizontal, start, i);
+ qreal shift = anchoredChunkShift(result, isHorizontal, start, end);
const QPointF shiftP = resHandler.adjust(isHorizontal ? QPointF(shift, 0) : QPointF(0, shift));
- for (int j = start; j < i; j++) {
+ for (int j = start; j < end; j++) {
result[j].finalPosition += shiftP;
}
- start = i;
+ start = end;
}
}
-qreal KoSvgTextShape::Private::anchoredChunkShift(const QVector<CharacterResult> &result, const bool isHorizontal, const int start, int &i)
+qreal KoSvgTextShape::Private::anchoredChunkShift(const QVector<CharacterResult> &result, const bool isHorizontal, const int start, int &end)
{
qreal a = 0;
qreal b = 0;
- for (i = start; i < result.size(); i++) {
+ int i = start;
+ for (; i < result.size(); i++) {
if (!result.at(i).addressable) {
continue;
}
@@ -1718,18 +1719,22 @@ qreal KoSvgTextShape::Private::anchoredChunkShift(const QVector<CharacterResult>
}
}
- const bool rtl = result.at(start).direction == KoSvgText::DirectionRightToLeft;
- qreal shift = isHorizontal ? result.at(start).finalPosition.x() : result.at(start).finalPosition.y();
+ const CharacterResult startRes = result.at(start);
- if ((result.at(start).anchor == KoSvgText::AnchorStart && !rtl) || (result.at(start).anchor == KoSvgText::AnchorEnd && rtl)) {
+ const bool rtl = startRes.direction == KoSvgText::DirectionRightToLeft;
+ qreal shift = isHorizontal ? startRes.finalPosition.x() : startRes.finalPosition.y();
+
+ if ((startRes.anchor == KoSvgText::AnchorStart && !rtl)
+ || (startRes.anchor == KoSvgText::AnchorEnd && rtl)) {
shift = shift - a;
- } else if ((result.at(start).anchor == KoSvgText::AnchorEnd && !rtl) || (result.at(start).anchor == KoSvgText::AnchorStart && rtl)) {
+ } else if ((startRes.anchor == KoSvgText::AnchorEnd && !rtl)
+ || (startRes.anchor == KoSvgText::AnchorStart && rtl)) {
shift = shift - b;
-
} else {
shift = shift - (a + b) * 0.5;
}
+ end = i;
return shift;
}