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 up snapping to nearest pixel for alignment, tabsize, line-height, text length and text-decor.
Wolthera van Hövell tot Westerflier1452002c3295
diff --git a/libs/flake/text/KoSvgText.cpp b/libs/flake/text/KoSvgText.cppindex 5fd0519130..c91da426fe 100644--- a/libs/flake/text/KoSvgText.cpp+++ b/libs/flake/text/KoSvgText.cpp@@ -1713,6 +1713,38 @@ QPointF ResolutionHandler::adjust(const QPointF point) const {return pixelToPoint().map(pix);}+QPointF ResolutionHandler::adjustFloor(const QPointF point) const+{+ if (!roundToPixelHorizontal && !roundToPixelVertical) return point;+ QPointF pix = pointToPixel().map(point);+ if (roundToPixelHorizontal) {+ pix.setX(floor(pix.x()));+ }+ if (roundToPixelVertical) {+ pix.setY(floor(pix.y()));+ }+ return pixelToPoint().map(pix);+}++QPointF ResolutionHandler::adjustCeil(const QPointF point) const+{+ if (!roundToPixelHorizontal && !roundToPixelVertical) return point;+ QPointF pix = pointToPixel().map(point);+ if (roundToPixelHorizontal) {+ pix.setX(ceil(pix.x()));+ }+ if (roundToPixelVertical) {+ pix.setY(ceil(pix.y()));+ }+ return pixelToPoint().map(pix);+}++QPointF ResolutionHandler::adjustWithOffset(const QPointF point, const QPointF offset) const+{+ if (!roundToPixelHorizontal && !roundToPixelVertical) return point;+ return adjust(point+offset)-offset;+}+QRectF ResolutionHandler::adjust(const QRectF rect) const {return QRectF(adjust(rect.topLeft()), adjust(rect.bottomRight()));}diff --git a/libs/flake/text/KoSvgText.h b/libs/flake/text/KoSvgText.hindex b2118ef673..ffc2789ba8 100644--- a/libs/flake/text/KoSvgText.h+++ b/libs/flake/text/KoSvgText.h@@ -1083,7 +1083,6 @@ struct TextUnderlinePosition : public boost::equality_comparable<TextUnderlinePo*/struct ResolutionHandler {- ResolutionHandler() {}ResolutionHandler(qreal _xRes = 72.0, qreal _yRes = 72.0, bool _roundToPixelHorizontal = false, bool _roundToPixelVertical = false): xRes(_xRes), yRes(_yRes), roundToPixelHorizontal(_roundToPixelHorizontal), roundToPixelVertical(_roundToPixelVertical) {}@@ -1110,6 +1109,15 @@ struct ResolutionHandler {/// Adjusts the point to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.QPointF adjust(const QPointF point) const;+ /// Adjusts the point to floored pixel values. @see adjust(QPointF);+ QPointF adjustFloor(const QPointF point) const;+ /// Adjusts the point to ceiled pixel values. @see adjust(QPointF);+ QPointF adjustCeil(const QPointF point) const;++ /// For text decoration, we need to ensure that the whole thing, including width and height is aligned to the pixel.+ /// So this adds the offset (half the total width) and uses that to round to.+ QPointF adjustWithOffset(const QPointF point, const QPointF offset) const;+/// Adjusts the rect to rounded pixel values, based on whether roundToPixelHorizontal or roundToPixelVertical are true.QRectF adjust(const QRectF rect) const;};diff --git a/libs/flake/text/KoSvgTextShapeLayoutFunc.h b/libs/flake/text/KoSvgTextShapeLayoutFunc.hindex 69103d71d6..2c68f13b1e 100644--- a/libs/flake/text/KoSvgTextShapeLayoutFunc.h+++ b/libs/flake/text/KoSvgTextShapeLayoutFunc.h@@ -26,16 +26,17 @@ void finalizeLine(QVector<CharacterResult> &result,QPointF ¤tPos,LineBox ¤tLine,QPointF &lineOffset,- KoSvgText::TextAnchor anchor,- KoSvgText::WritingMode writingMode,- bool ltr,- bool inlineSize,- bool textInShape);+ const KoSvgText::TextAnchor anchor,+ const KoSvgText::WritingMode writingMode,+ const bool ltr,+ const bool inlineSize,+ const bool textInShape,+ const KoSvgText::ResolutionHandler &resHandler);QVector<LineBox> breakLines(const KoSvgTextProperties &properties,const QMap<int, int> &logicalToVisual,QVector<CharacterResult> &result,- QPointF startPos);+ QPointF startPos, const KoSvgText::ResolutionHandler &resHandler);QList<QPainterPath>getShapes(QList<KoShape *> shapesInside, QList<KoShape *> shapesSubtract, const KoSvgTextProperties &properties);@@ -43,7 +44,7 @@ getShapes(QList<KoShape *> shapesInside, QList<KoShape *> shapesSubtract, constQVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,const QMap<int, int> &logicalToVisual,QVector<CharacterResult> &result,- QList<QPainterPath> shapes, QPointF &startPos);+ QList<QPainterPath> shapes, QPointF &startPos, const KoSvgText::ResolutionHandler &resHandler);} // namespace KoSvgTextShapeLayoutFuncdiff --git a/libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp b/libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cppindex a71913cdcc..416abbd8e8 100644--- a/libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp+++ b/libs/flake/text/KoSvgTextShapeLayoutFunc_inShape.cpp@@ -442,7 +442,8 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,const QMap<int, int> &logicalToVisual,QVector<CharacterResult> &result,QList<QPainterPath> shapes,- QPointF &startPos)+ QPointF &startPos,+ const KoSvgText::ResolutionHandler &resHandler){QVector<LineBox> lineBoxes;KoSvgText::WritingMode writingMode = KoSvgText::WritingMode(properties.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());@@ -484,7 +485,7 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,QPainterPath currentShape;while (it.hasNext()) {int index = it.next();- result[index].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal);+ result[index].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal, resHandler);CharacterResult charResult = result.at(index);if (!charResult.addressable) {continue;@@ -545,7 +546,7 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,if (softBreak) {if (!currentLine.isEmpty()) {- finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true);+ finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true, resHandler);lineBoxes.append(currentLine);firstLine = false;indentLine = false;@@ -564,7 +565,7 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,getEstimatedHeight(result, index, wordBox, currentShape.boundingRect(), writingMode);currentPos -= writingMode == KoSvgText::VerticalRL? wordBox.topRight(): wordBox.topLeft();- currentLine = LineBox(findLineBoxesForFirstPos(currentShape, currentPos, wordBox, writingMode), ltr, indent);+ currentLine = LineBox(findLineBoxesForFirstPos(currentShape, currentPos, wordBox, writingMode), ltr, indent, resHandler);qreal length = isHorizontal? wordBox.width(): wordBox.height();for (int i = 0; i < currentLine.chunks.size(); i++) {if (currentLine.chunks.at(i).length.length() > length) {@@ -593,14 +594,14 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,qreal textIdentValue = textIndentInfo.length.value;if (isHorizontal) {if (indentPercent) {- textIndent *= currentShape.boundingRect().width();+ textIdentValue *= currentShape.boundingRect().width();}- textIndent = QPointF(textIdentValue, 0);+ textIndent = resHandler.adjust(QPointF(textIdentValue, 0));} else {if (indentPercent) {- textIndent *= currentShape.boundingRect().height();+ textIdentValue *= currentShape.boundingRect().height();}- textIndent = QPointF(0, textIdentValue);+ textIndent = resHandler.adjust(QPointF(0, textIdentValue));}bool ind = textIndentInfo.hanging? !indentLine: indentLine;indent = ind? textIndent: QPointF();@@ -620,7 +621,7 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,if (foundFirst) {if (needNewLine) {- currentLine = LineBox(findLineBoxesForFirstPos(currentShape, currentPos, wordBox, writingMode), ltr, indent);+ currentLine = LineBox(findLineBoxesForFirstPos(currentShape, currentPos, wordBox, writingMode), ltr, indent, resHandler);// We could set this to find the first fitting width, but it's better to try and improve the precision of the firstpos algorithm,// as this gives more stable results.currentLine.setCurrentChunkForPos(currentPos, isHorizontal);@@ -661,13 +662,13 @@ QVector<LineBox> flowTextInShapes(const KoSvgTextProperties &properties,}if (charResult.breakType == BreakType::HardBreak) {- finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true);+ finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true, resHandler);lineBoxes.append(currentLine);currentLine = LineBox();indentLine = textIndentInfo.hanging? false: textIndentInfo.eachLine;}}- finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true);+ finalizeLine(result, currentPos, currentLine, lineOffset, anchor, writingMode, ltr, true, true, resHandler);lineBoxes.append(currentLine);return lineBoxes;}diff --git a/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp b/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cppindex 76cb83e47a..d5d73fdc3d 100644--- a/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp+++ b/libs/flake/text/KoSvgTextShapeLayoutFunc_lines.cpp@@ -83,7 +83,7 @@ void addWordToLine(QVector<CharacterResult> &result,calculateLineHeight(cr, currentLine.actualLineTop, currentLine.actualLineBottom, isHorizontal, !cr.anchored_chunk);cr.cssPosition = currentPos;- cr.calculateAndApplyTabsize(currentPos, isHorizontal);+ cr.calculateAndApplyTabsize(currentPos, isHorizontal, KoSvgText::ResolutionHandler());currentPos += cr.advance;lineAdvance = currentPos;@@ -103,7 +103,8 @@ void addWordToLine(QVector<CharacterResult> &result,static QPointF lineHeightOffset(KoSvgText::WritingMode writingMode,QVector<CharacterResult> &result,LineBox ¤tLine,- bool firstLine)+ const bool firstLine,+ const KoSvgText::ResolutionHandler resHandler){QPointF lineTop;QPointF lineBottom;@@ -157,7 +158,11 @@ static QPointF lineHeightOffset(KoSvgText::WritingMode writingMode,lineBottom = currentLine.baselineBottom;}bool returnDescent = firstLine;- QPointF offset = lineTop + lineBottom;+ QPointF offset = resHandler.adjust(lineTop + lineBottom);+ if (resHandler.roundToPixelHorizontal || resHandler.roundToPixelVertical) {+ lineTop = offset - resHandler.adjust(lineBottom);+ correctionOffset = resHandler.adjust(correctionOffset);+ }if (!returnDescent) {for (auto chunk = currentLine.chunks.begin(); chunk != currentLine.chunks.end(); chunk++) {@@ -174,14 +179,14 @@ static QPointF lineHeightOffset(KoSvgText::WritingMode writingMode,for (auto chunk = currentLine.chunks.begin(); chunk != currentLine.chunks.end(); chunk++) {Q_FOREACH (int j, chunk->chunkIndices) {result[j].cssPosition -= correctionOffset;- result[j].cssPosition += result[j].totalBaselineOffset();+ result[j].cssPosition = result[j].cssPosition + result[j].totalBaselineOffset();result[j].finalPosition = result.at(j).cssPosition;}chunk->length.translate(-correctionOffset);chunk->boundingBox.translate(-correctionOffset);}}- return offset;+ return resHandler.adjust(offset);}// NOLINTNEXTLINE(readability-function-cognitive-complexity)@@ -242,15 +247,15 @@ handleCollapseAndHang(QVector<CharacterResult> &result, LineChunk &chunk, bool l// NOLINTNEXTLINE(readability-function-cognitive-complexity)static void applyInlineSizeAnchoring(QVector<CharacterResult> &result,LineChunk &chunk,- KoSvgText::TextAnchor anchor,- QPointF anchorPoint,- bool ltr,- bool isHorizontal,- QPointF textIndent)+ const KoSvgText::TextAnchor anchor,+ const QPointF anchorPoint,+ const bool ltr,+ const bool isHorizontal,+ const QPointF textIndent,+ const KoSvgText::ResolutionHandler &resHandler){- QVector<int> lineIndices = chunk.chunkIndices;- QPointF startPos = anchorPoint;- qreal shift = isHorizontal ? startPos.x() : startPos.y();+ const QVector<int> lineIndices = chunk.chunkIndices;+ qreal shift = isHorizontal ? anchorPoint.x() : anchorPoint.y();qreal a = 0;qreal b = 0;@@ -302,9 +307,9 @@ static void applyInlineSizeAnchoring(QVector<CharacterResult> &result,shift -= ((a + b) * 0.5);}- QPointF shiftP = isHorizontal ? QPointF(shift, 0) : QPointF(0, shift);+ QPointF shiftP = resHandler.adjust(isHorizontal ? QPointF(shift, 0) : QPointF(0, shift));Q_FOREACH (int j, lineIndices) {- result[j].cssPosition += shiftP;+ result[j].cssPosition = result[j].cssPosition+shiftP;result[j].finalPosition = result.at(j).cssPosition;}chunk.boundingBox.translate(shiftP);@@ -317,11 +322,12 @@ void finalizeLine(QVector<CharacterResult> &result,QPointF ¤tPos,LineBox ¤tLine,QPointF &lineOffset,- KoSvgText::TextAnchor anchor,- KoSvgText::WritingMode writingMode,- bool ltr,- bool inlineSize,- bool textInShape)+ const KoSvgText::TextAnchor anchor,+ const KoSvgText::WritingMode writingMode,+ const bool ltr,+ const bool inlineSize,+ const bool textInShape,+ const KoSvgText::ResolutionHandler &resHandler){bool isHorizontal = writingMode == KoSvgText::HorizontalTB;@@ -417,13 +423,13 @@ void finalizeLine(QVector<CharacterResult> &result,anchorPoint = currentChunk->length.p2();}}- applyInlineSizeAnchoring(result, *currentChunk, anchor, anchorPoint, ltr, isHorizontal, currentLine.textIndent);+ 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());}}- lineOffset += lineHeightOffset(writingMode, result, currentLine, firstLine);+ lineOffset += lineHeightOffset(writingMode, result, currentLine, firstLine, resHandler);currentPos = lineOffset;}@@ -431,7 +437,8 @@ void finalizeLine(QVector<CharacterResult> &result,QVector<LineBox> breakLines(const KoSvgTextProperties &properties,const QMap<int, int> &logicalToVisual,QVector<CharacterResult> &result,- QPointF startPos)+ QPointF startPos,+ const KoSvgText::ResolutionHandler &resHandler){KoSvgText::WritingMode writingMode = KoSvgText::WritingMode(properties.propertyOrDefault(KoSvgTextProperties::WritingModeId).toInt());KoSvgText::Direction direction = KoSvgText::Direction(properties.propertyOrDefault(KoSvgTextProperties::DirectionId).toInt());@@ -452,14 +459,14 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,qreal textIdentValue = textIndentInfo.length.unit == KoSvgText::CssLengthPercentage::Percentage?textIndentInfo.length.value * inlineSize.customValue: textIndentInfo.length.value;if (isHorizontal) {- textIndent = QPointF(textIdentValue, 0);+ textIndent = resHandler.adjust(QPointF(textIdentValue, 0));endPos = ltr ? QPointF(startPos.x() + inlineSize.customValue, 0) : QPointF(startPos.x() - inlineSize.customValue, 0);} else {- textIndent = QPointF(0, textIdentValue);+ textIndent = resHandler.adjust(QPointF(0, textIdentValue));endPos = ltr ? QPointF(0, startPos.y() + inlineSize.customValue) : QPointF(0, startPos.y() - inlineSize.customValue);}}- LineBox currentLine(startPos, endPos);+ LineBox currentLine(startPos, endPos, resHandler);currentLine.firstLine = true;QVector<int> wordIndices; ///< 'word' in this case meaning characters@@ -478,7 +485,7 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,QListIterator<int> it(logicalToVisual.keys());while (it.hasNext()) {int index = it.next();- result[index].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal);+ result[index].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal, resHandler);CharacterResult charResult = result.at(index);if (!charResult.addressable) {continue;@@ -525,7 +532,8 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,writingMode,ltr,!inlineSize.isAuto,- false);+ false,+ resHandler);lineBoxes.append(currentLine);currentLine.clearAndAdjust(isHorizontal, lineOffset, textIndentInfo.hanging? textIndent: QPointF());if (!inlineSize.isAuto) {@@ -543,7 +551,7 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,QVector<int> partialWord;currentLine.firstLine = firstLine;Q_FOREACH (const int i, wordIndices) {- result[i].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal);+ result[i].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal, resHandler);wordAdvance += result.at(i).advance;wordLength = isHorizontal ? wordAdvance.x() : wordAdvance.y();if (wordLength <= inlineSize.customValue) {@@ -559,13 +567,14 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,writingMode,ltr,!inlineSize.isAuto,- false);+ false,+ resHandler);lineBoxes.append(currentLine);currentLine.clearAndAdjust(isHorizontal, lineOffset, textIndentInfo.hanging? textIndent: QPointF());if (!inlineSize.isAuto) {currentPos += currentLine.textIndent;}- result[i].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal);+ result[i].calculateAndApplyTabsize(wordAdvance + currentPos, isHorizontal, resHandler);wordAdvance = result.at(i).advance;partialWord.append(i);}@@ -585,7 +594,8 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,writingMode,ltr,!inlineSize.isAuto,- false);+ false,+ resHandler);lineBoxes.append(currentLine);bool indentLine = textIndentInfo.hanging? false: textIndentInfo.eachLine;currentLine.clearAndAdjust(isHorizontal, lineOffset, indentLine? textIndent: QPointF());@@ -606,7 +616,8 @@ QVector<LineBox> breakLines(const KoSvgTextProperties &properties,writingMode,ltr,!inlineSize.isAuto,- false);+ false,+ resHandler);lineBoxes.append(currentLine);}}diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex 652438bd8e..2586f2fbd4 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -128,15 +128,13 @@ struct CharacterResult {std::optional<qreal> tabSize; ///< If present, this is a tab and it should align to multiples of this tabSize value.- void calculateAndApplyTabsize(QPointF currentPos, bool isHorizontal) {+ void calculateAndApplyTabsize(QPointF currentPos, bool isHorizontal, const KoSvgText::ResolutionHandler &resHandler) {if (!tabSize) return;if (*tabSize == qInf() || qIsNaN(*tabSize)) return;if (*tabSize > 0) {qreal remainder = *tabSize - (isHorizontal? fmod(currentPos.x(), *tabSize): fmod(currentPos.y(), *tabSize));- advance = isHorizontal? QPointF(remainder, advance.y()): QPointF(advance.x(), remainder);- } else {- advance = isHorizontal? QPointF(0, advance.y()): QPointF(advance.x(), 0);+ advance = resHandler.adjust(isHorizontal? QPointF(remainder, advance.y()): QPointF(advance.x(), remainder));}}@@ -300,26 +298,26 @@ struct LineBox {LineBox() {}- LineBox(QPointF start, QPointF end) {+ LineBox(QPointF start, QPointF end, const KoSvgText::ResolutionHandler &resHandler) {LineChunk chunk;- chunk.length = QLineF(start, end);+ chunk.length = QLineF(resHandler.adjustCeil(start), resHandler.adjustFloor(end));chunks.append(chunk);currentChunk = 0;}- LineBox(QVector<QLineF> lineWidths, bool ltr, QPointF indent) {+ LineBox(QVector<QLineF> lineWidths, bool ltr, QPointF indent, const KoSvgText::ResolutionHandler &resHandler) {textIndent = indent;if (ltr) {Q_FOREACH(QLineF line, lineWidths) {LineChunk chunk;- chunk.length = line;+ chunk.length = QLineF(resHandler.adjustCeil(line.p1()), resHandler.adjustFloor(line.p2()));chunks.append(chunk);currentChunk = 0;}} else {Q_FOREACH(QLineF line, lineWidths) {LineChunk chunk;- chunk.length = QLineF(line.p2(), line.p1());+ chunk.length = QLineF(resHandler.adjustFloor(line.p2()), resHandler.adjustCeil(line.p1()));chunks.insert(0, chunk);currentChunk = 0;}@@ -511,8 +509,8 @@ public:QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps);void applyTextLength(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QVector<CharacterResult> &result, int ¤tIndex, int &resolvedDescendentNodes, bool isHorizontal,- const KoSvgTextProperties resolvedProps);- static void applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal);+ const KoSvgTextProperties resolvedProps, const KoSvgText::ResolutionHandler &resHandler);+ static void applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal, const KoSvgText::ResolutionHandler resHandler);static qrealcharacterResultOnPath(CharacterResult &cr, qreal length, qreal offset, bool isHorizontal, bool isClosed);static QPainterPath stretchGlyphOnPath(const QPainterPath &glyph,diff --git a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp b/libs/flake/text/KoSvgTextShape_p_glyphs.cppindex 00400ddfaf..2b6b743e05 100644--- a/libs/flake/text/KoSvgTextShape_p_glyphs.cpp+++ b/libs/flake/text/KoSvgTextShape_p_glyphs.cpp@@ -579,6 +579,7 @@ bool KoSvgTextShape::Private::loadGlyph(const KoSvgText::ResolutionHandler &resHQRect bboxPixel(left, top, width, height);if (!isHorizontal) {bboxPixel.moveLeft(-(bboxPixel.width() / 2));+ bboxPixel.moveTop(-bboxPixel.height());}QRectF drawRect = ftTF.mapRect(QRectF(bboxPixel.topLeft() * resHandler.freeTypePixel, bboxPixel.size() * resHandler.freeTypePixel));drawRect.translate(charResult.advance - ftTF.map(advance));diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cppindex 7e9aa32f22..626545a2cb 100644--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp@@ -152,8 +152,8 @@ void KoSvgTextShape::Private::relayout()};// Setup the resolution handler.- const bool horzSnapping = textRendering != KoSvgText::RenderingGeometricPrecision || textRendering != KoSvgText::RenderingAuto;- const bool vertSnapping = (textRendering == KoSvgText::RenderingOptimizeLegibility && isHorizontal) || textRendering == KoSvgText::RenderingOptimizeSpeed;+ const bool horzSnapping = textRendering == KoSvgText::RenderingOptimizeSpeed || (textRendering == KoSvgText::RenderingOptimizeLegibility && !isHorizontal);+ const bool vertSnapping = textRendering != KoSvgText::RenderingGeometricPrecision && textRendering != KoSvgText::RenderingAuto;const KoSvgText::ResolutionHandler resHandler(this->xRes, this->yRes, horzSnapping, vertSnapping);// First, get text. We use the subChunks because that handles bidi-insertion for us.@@ -646,9 +646,9 @@ void KoSvgTextShape::Private::relayout()QPointF startPos = resolvedTransforms.value(0).absolutePos() - result.value(0).dominantBaselineOffset;if (!this->shapesInside.isEmpty()) {QList<QPainterPath> shapes = getShapes(this->shapesInside, this->shapesSubtract, rootProperties);- this->lineBoxes = flowTextInShapes(rootProperties, logicalToVisual, result, shapes, startPos);+ this->lineBoxes = flowTextInShapes(rootProperties, logicalToVisual, result, shapes, startPos, resHandler);} else {- this->lineBoxes = breakLines(rootProperties, logicalToVisual, result, startPos);+ this->lineBoxes = breakLines(rootProperties, logicalToVisual, result, startPos, resHandler);}// Handle baseline alignment.@@ -693,7 +693,7 @@ void KoSvgTextShape::Private::relayout()debugFlake << "5. Apply ‘textLength’ attribute";globalIndex = 0;int resolved = 0;- this->applyTextLength(textData.childBegin(), result, globalIndex, resolved, isHorizontal, KoSvgTextProperties::defaultProperties());+ this->applyTextLength(textData.childBegin(), result, globalIndex, resolved, isHorizontal, KoSvgTextProperties::defaultProperties(), resHandler);// 6. Adjust positions: x, ydebugFlake << "6. Adjust positions: x, y";@@ -722,7 +722,7 @@ void KoSvgTextShape::Private::relayout()// 7. Apply anchoringdebugFlake << "7. Apply anchoring";- applyAnchoring(result, isHorizontal);+ applyAnchoring(result, isHorizontal, resHandler);// Computing the textDecorations needs to happen before applying the// textPath to the results, as we need the unapplied result vector for@@ -942,7 +942,7 @@ void KoSvgTextShape::Private::applyTextLength(KisForest<KoSvgTextContentElement>int ¤tIndex,int &resolvedDescendentNodes,bool isHorizontal,- const KoSvgTextProperties resolvedProps)+ const KoSvgTextProperties resolvedProps, const KoSvgText::ResolutionHandler &resHandler){int i = currentIndex;@@ -952,7 +952,7 @@ void KoSvgTextShape::Private::applyTextLength(KisForest<KoSvgTextContentElement>KoSvgTextProperties props;props.inheritFrom(resolvedProps, true);for (auto child = KisForestDetail::childBegin(currentTextElement); child != KisForestDetail::childEnd(currentTextElement); child++) {- applyTextLength(child, result, currentIndex, resolvedChildren, isHorizontal, props);+ applyTextLength(child, result, currentIndex, resolvedChildren, isHorizontal, props, resHandler);}// Raqm handles bidi reordering for us, but this algorithm does not// anticipate that, so we need to keep track of which typographic item@@ -1009,7 +1009,7 @@ void KoSvgTextShape::Private::applyTextLength(KisForest<KoSvgTextContentElement>bool last = spacingAndGlyphs ? false : k == visualToLogical.keys().last();if (!(cr.textLengthApplied && secondTextLengthApplied) && !last) {- shift += d;+ shift = resHandler.adjust(shift+d);}secondTextLengthApplied = cr.textLengthApplied;cr.textLengthApplied = true;@@ -1585,6 +1585,11 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &enDecorationBox box = decorationBoxes.at(i);if (box.underlineOffsets.size() > 0) {stroker.setWidth(qMax(minimumDecorationThickness, (box.thickness/(box.underlineOffsets.size()))*freetypePixelsToPt));+ if (isHorizontal) {+ stroker.setWidth(resHandler.adjust(QPointF(0, stroker.width())).y());+ } else {+ stroker.setWidth(resHandler.adjust(QPointF(stroker.width(), 0)).x());+ }} else {stroker.setWidth(minimumDecorationThickness);}@@ -1604,26 +1609,24 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &enQMap<TextDecoration, QPointF> decorationOffsets;if (isHorizontal) {const qreal startX = rect.left();- decorationOffsets[DecorationOverline] = QPointF(startX, box.decorationRect.top()) + pathWidth;- decorationOffsets[DecorationUnderline] = QPointF(startX, box.decorationRect.bottom());+ decorationOffsets[DecorationOverline] = resHandler.adjustWithOffset(QPointF(startX, box.decorationRect.top()) + pathWidth, pathWidth*0.5);+ decorationOffsets[DecorationUnderline] = resHandler.adjustWithOffset(QPointF(startX, box.decorationRect.bottom()), pathWidth*0.5);if (underlinePosH == UnderlineAuto) {qreal average = 0;for (int j = 0; j < box.underlineOffsets.size(); j++) {average += box.underlineOffsets.at(j);}average = average > 0? (average/box.underlineOffsets.size()): 0;- decorationOffsets[DecorationUnderline] += QPointF(0, average);+ decorationOffsets[DecorationUnderline] += resHandler.adjustWithOffset(QPointF(0, average), pathWidth*0.5);}} else {const qreal startY = rect.top();if (underlinePosV == UnderlineRight) {- decorationOffsets[DecorationOverline] = QPointF(box.decorationRect.left(), startY);- decorationOffsets[DecorationUnderline] = QPointF(box.decorationRect.right(), startY);- decorationOffsets[DecorationUnderline] += pathWidth;+ decorationOffsets[DecorationOverline] = resHandler.adjustWithOffset(QPointF(box.decorationRect.left(), startY), pathWidth*0.5);+ decorationOffsets[DecorationUnderline] = resHandler.adjustWithOffset(QPointF(box.decorationRect.right(), startY) +pathWidth, pathWidth*0.5);} else {- decorationOffsets[DecorationOverline] = QPointF(box.decorationRect.right(), startY);- decorationOffsets[DecorationUnderline] = QPointF(box.decorationRect.left(), startY);- decorationOffsets[DecorationOverline] += pathWidth;+ decorationOffsets[DecorationOverline] = resHandler.adjustWithOffset(QPointF(box.decorationRect.right(), startY) +pathWidth, pathWidth*0.5);+ decorationOffsets[DecorationUnderline] = resHandler.adjustWithOffset(QPointF(box.decorationRect.left(), startY), pathWidth*0.5);}}@@ -1640,6 +1643,14 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &enQPolygonF poly = l.line;if (poly.isEmpty()) continue;stroker.setWidth(qMax(minimumDecorationThickness, (l.thickness/(poly.size()))*freetypePixelsToPt));+ QPointF pathWidth;+ if (isHorizontal) {+ pathWidth = resHandler.adjust(QPointF(0, stroker.width()));+ stroker.setWidth(pathWidth.y());+ } else {+ pathWidth = resHandler.adjust(QPointF(stroker.width(), 0));+ stroker.setWidth(pathWidth.x());+ }qreal average = 0.0;for (int j = 0; j < poly.size(); j++) {average += isHorizontal? poly.at(j).y(): poly.at(j).x();@@ -1647,6 +1658,8 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &enaverage /= poly.size();QLineF line = isHorizontal? QLineF(poly.first().x(), average, poly.last().x(), average): QLineF(average, poly.first().y(), average, poly.last().y());+ line.setP1(resHandler.adjustWithOffset(line.p1(), pathWidth*0.5));+ line.setP2(resHandler.adjustWithOffset(line.p2(), pathWidth*0.5));QPair<QPainterPath, QPointF> generatedPath = generateDecorationPath(line, stroker.width(), style, isHorizontal, textOnPath, minimumDecorationThickness);QPainterPath p = generatedPath.first;finalizeDecoration(p, line.p1() + (generatedPath.second * 0.5), stroker, DecorationLineThrough, decorationPaths, currentTextPath, isHorizontal, currentTextPathOffset, textPathSide);@@ -1657,7 +1670,7 @@ KoSvgTextShape::Private::generateDecorationPaths(const int &start, const int &en}// NOLINTNEXTLINE(readability-function-cognitive-complexity)-void KoSvgTextShape::Private::applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal)+void KoSvgTextShape::Private::applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal, const KoSvgText::ResolutionHandler resHandler){int i = 0;int start = 0;@@ -1697,7 +1710,7 @@ void KoSvgTextShape::Private::applyAnchoring(QVector<CharacterResult> &result, bshift = shift - (a + b) * 0.5;}- const QPointF shiftP = isHorizontal ? QPointF(shift, 0) : QPointF(0, shift);+ const QPointF shiftP = resHandler.adjust(isHorizontal ? QPointF(shift, 0) : QPointF(0, shift));for (int j = start; j < i; j++) {result[j].finalPosition += shiftP;