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 number of issues with bidi controls.
Wolthera van Hövell tot Westerflier760edab0db79
diff --git a/libs/flake/text/KoCssTextUtils.cpp b/libs/flake/text/KoCssTextUtils.cppindex 023f3cffee..ad099f1175 100644--- a/libs/flake/text/KoCssTextUtils.cpp+++ b/libs/flake/text/KoCssTextUtils.cpp@@ -460,9 +460,9 @@ QString KoCssTextUtils::getBidiOpening(bool ltr, KoSvgText::UnicodeBidi bidi)if (bidi == BidiEmbed) {result = BIDI_CONTROL_LRE;} else if (bidi == BidiOverride) {- result = BIDI_CONTROL_LRI;- } else if (bidi == BidiIsolate) {result = BIDI_CONTROL_LRO;+ } else if (bidi == BidiIsolate) {+ result = BIDI_CONTROL_LRI;} else if (bidi == BidiIsolateOverride) {result = UNICODE_BIDI_ISOLATE_OVERRIDE_LR_START;} else if (bidi == BidiPlainText) {@@ -472,9 +472,9 @@ QString KoCssTextUtils::getBidiOpening(bool ltr, KoSvgText::UnicodeBidi bidi)if (bidi == BidiEmbed) {result = BIDI_CONTROL_RLE;} else if (bidi == BidiOverride) {- result = BIDI_CONTROL_RLI;- } else if (bidi == BidiIsolate) {result = BIDI_CONTROL_RLO;+ } else if (bidi == BidiIsolate) {+ result = BIDI_CONTROL_RLI;} else if (bidi == BidiIsolateOverride) {result = UNICODE_BIDI_ISOLATE_OVERRIDE_RL_START;} else if (bidi == BidiPlainText) {diff --git a/libs/flake/text/KoSvgTextContentElement.h b/libs/flake/text/KoSvgTextContentElement.hindex 22d4a731af..bdcc3d18c4 100644--- a/libs/flake/text/KoSvgTextContentElement.h+++ b/libs/flake/text/KoSvgTextContentElement.h@@ -36,6 +36,7 @@ public:, lengthAdjust(rhs.lengthAdjust), textDecorations(rhs.textDecorations), text(rhs.text)+ , finalResultIndex(rhs.finalResultIndex), associatedOutline(rhs.associatedOutline){if (rhs.textPath) {@@ -68,6 +69,11 @@ public:/// Plain text of the current node. Use insertText and removeText to manipulate it.QString text;+ /// Set during layout, finalResultIndex determines the size of the iterator+ /// on result after going over this contentElement. Once layout has been set+ /// this is less fiddly than using numChars which requires resolving properties.+ int finalResultIndex = -1;+/// The associated outline. Currently only a bounding box.QPainterPath associatedOutline;diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cppindex 626545a2cb..395a2d75ad 100644--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp@@ -767,7 +767,8 @@ void KoSvgTextShape::Private::relayout()QVector<CursorPos> cursorPos;for (auto chunk = textChunks.begin(); chunk != textChunks.end(); chunk++) {const int j = chunk->text.size();- for (int i = globalIndex; i < globalIndex + j; i++) {+ chunk->associatedLeaf->finalResultIndex = (globalIndex+j);+ for (int i = globalIndex; i < chunk->associatedLeaf->finalResultIndex; i++) {if (result.at(i).addressable && !result.at(i).middle) {if (result.at(i).plaintTextIndex > -1) {@@ -829,6 +830,7 @@ void KoSvgTextShape::Private::relayout()cursorPos.append(pos);if (!textChunks.isEmpty()) {textChunks.last().associatedLeaf->associatedOutline.addRect(result.at(dummyIndex).finalTransform().mapRect(result[dummyIndex].inkBoundingBox));+ textChunks.last().associatedLeaf->finalResultIndex = result.size();}}}@@ -844,6 +846,7 @@ void KoSvgTextShape::Private::clearAssociatedOutlines()for (auto it = textData.depthFirstTailBegin(); it != textData.depthFirstTailEnd(); it++) {it->associatedOutline = QPainterPath();it->textDecorations.clear();+ it->finalResultIndex = -1;}}@@ -851,6 +854,8 @@ void KoSvgTextShape::Private::clearAssociatedOutlines()* @brief KoSvgTextShape::Private::resolveTransforms* This resolves transforms and applies whitespace collapse.*/++const QString bidiControls = "\u202a\u202b\u202c\u202d\u202e\u2066\u2067\u2068\u2069";void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QString text, QVector<CharacterResult> &result, int ¤tIndex, bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps) {QVector<KoSvgText::CharTransformation> local = currentTextElement->localTransformations;@@ -867,8 +872,8 @@ void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElemenif (k >= text.size()) {continue;}- bool bidi = (text.at(k).unicode() >= 8234 && text.at(k).unicode() <= 8238)- || (text.at(k).unicode() >= 8294 && text.at(k).unicode() <= 8297);++ bool bidi = bidiControls.contains(text.at(k));bool softHyphen = text.at(k) == QChar::SoftHyphen;// Apparantly when there's bidi controls in the text, they participate in line-wrapping,diff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex 56b1787e41..a844c846ac 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -174,7 +174,8 @@ void KoSvgTextShape::Private::paintPaths(QPainter &painter,if (it.state() == KisForestDetail::Enter) {if (childCount(siblingCurrent(it)) == 0) {- const int j = currentIndex + it->numChars(true);+ if (it->finalResultIndex < 0) continue;+ const int j = it->finalResultIndex;//currentIndex + it->numChars(true);const QRect shapeGlobalClipRect = painter.transform().mapRect(it->associatedOutline.boundingRect().adjusted(-insets.left, -insets.top, insets.right, insets.bottom)).toAlignedRect();@@ -442,7 +443,8 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characteif (childCount(siblingCurrent(it)) == 0) {QPainterPath chunk;- const int j = currentIndex + it->numChars(true);+ const int j = it->finalResultIndex;+ if (j < 0 || j > result.size()) continue;for (int i = currentIndex; i < j; i++) {if (result.at(i).addressable && !result.at(i).hidden) {const QTransform tf = result.at(i).finalTransform();@@ -587,7 +589,9 @@ void KoSvgTextShape::Private::paintDebug(QPainter &painter,{for (auto it = textData.depthFirstTailBegin(); it != textData.depthFirstTailEnd(); it++) {- const int j = currentIndex + it->numChars(true);+ const int j = it->finalResultIndex;+ if (currentIndex > result.size()) continue;+ if (j < 0 || j > result.size()) continue;const QRect shapeGlobalClipRect = painter.transform().mapRect(it->associatedOutline.boundingRect()).toAlignedRect();