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 gradients on text when text-in-shape.
Wolthera van Hövell tot Westerfliera575d8341e11
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex 6235e641c0..16344eb5f9 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -2051,7 +2051,7 @@ void KoSvgTextShape::paint(QPainter &painter) constint currentIndex = 0;if (!d->result.isEmpty()) {QPainterPath rootBounds;- rootBounds.addRect(this->outline().boundingRect());+ rootBounds.addRect(Private::boundingBoxFromTree(d->textData, this, false));d->paintTextDecoration(painter, rootBounds, this, KoSvgText::DecorationUnderline, textRendering);d->paintTextDecoration(painter, rootBounds, this, KoSvgText::DecorationOverline, textRendering);d->paintPaths(painter, rootBounds, this, d->result, textRendering, chunk, currentIndex);@@ -2100,36 +2100,7 @@ QRectF KoSvgTextShape::boundingRect() constreturn shapesRect;}}- QRectF result;-- QList<KoShapeStrokeModelSP> parentStrokes;- for (auto it = d->textData.compositionBegin(); it != d->textData.compositionEnd(); it++) {- if (it.state() == KisForestDetail::Enter) {- if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {- parentStrokes.append(it->properties.property(KoSvgTextProperties::StrokeId).value<KoSvgText::StrokeProperty>().property);- }- } else {- KoShapeStrokeModelSP stroke = parentStrokes.size() > 0? parentStrokes.last(): nullptr;- QRectF bb = it->associatedOutline.boundingRect();- QMap<KoSvgText::TextDecoration, QPainterPath> decorations = it->textDecorations;- for (int i = 0; i < decorations.values().size(); ++i) {- bb |= decorations.values().at(i).boundingRect();- }- if (!bb.isEmpty()) {- if (stroke) {- KoInsets insets;- stroke->strokeInsets(this, insets);- result |= bb.adjusted(-insets.left, -insets.top, insets.right, insets.bottom);- } else {- result |= bb;- }- }- if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {- // reset stroke to use parent stroke.- parentStrokes.pop_back();- }- }- }+ QRectF result = Private::boundingBoxFromTree(d->textData, this, true);return (this->absoluteTransformation().mapRect(result) | shapesRect);}diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.hindex 4974059d94..0dc40e6a87 100644--- a/libs/flake/text/KoSvgTextShape_p.h+++ b/libs/flake/text/KoSvgTextShape_p.h@@ -14,6 +14,7 @@#include "KoSvgTextContentElement.h"#include <KoShapePainter.h>#include <KoShapeManager.h>+#include <KoInsets.h>#include "KoCssTextUtils.h"#include <KoShapeGroup.h>@@ -687,7 +688,7 @@ public:const KoSvgText::TextRendering rendering,QPainterPath &chunk,int ¤tIndex);- KoShape* collectPaths(const KoShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex);+ KoShape* collectPaths(const KoSvgTextShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex);void paintDebug(QPainter &painter,const QVector<CharacterResult> &result,int ¤tIndex);@@ -1414,6 +1415,48 @@ public:newTextPathName = QString("textPath"+QString::number(textPathNumber));}}++ /**+ * @brief boundingBoxFromTree+ * get the bounding box of the current textdata tree.+ * We need the bounding box for a variety of things, primarily KoShape::boundingRect(),+ * but also the calculation of the gradient painting rect.+ * @param tree -- tree to perform this on.+ * @param includeStrokeInset -- whether to include stroke insets.+ * @return a bounding rect.+ */+ static QRectF boundingBoxFromTree(KisForest<KoSvgTextContentElement> tree, const KoSvgTextShape *rootShape, bool includeStrokeInset) {+ QRectF result;+ QList<KoShapeStrokeModelSP> parentStrokes;+ for (auto it = tree.compositionBegin(); it != tree.compositionEnd(); it++) {+ if (it.state() == KisForestDetail::Enter) {+ if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {+ parentStrokes.append(it->properties.property(KoSvgTextProperties::StrokeId).value<KoSvgText::StrokeProperty>().property);+ }+ } else {+ KoShapeStrokeModelSP stroke = parentStrokes.size() > 0? parentStrokes.last(): nullptr;+ QRectF bb = it->associatedOutline.boundingRect();+ QMap<KoSvgText::TextDecoration, QPainterPath> decorations = it->textDecorations;+ for (int i = 0; i < decorations.values().size(); ++i) {+ bb |= decorations.values().at(i).boundingRect();+ }+ if (!bb.isEmpty()) {+ if (stroke && includeStrokeInset) {+ KoInsets insets;+ stroke->strokeInsets(rootShape, insets);+ result |= bb.adjusted(-insets.left, -insets.top, insets.right, insets.bottom);+ } else {+ result |= bb;+ }+ }+ if (it->properties.hasProperty(KoSvgTextProperties::StrokeId)) {+ // reset stroke to use parent stroke.+ parentStrokes.pop_back();+ }+ }+ }+ return result;+ }};#endif // KO_SVG_TEXT_SHAPE_P_Hdiff --git a/libs/flake/text/KoSvgTextShape_p_output.cpp b/libs/flake/text/KoSvgTextShape_p_output.cppindex e985f000d4..e08185d4ac 100644--- a/libs/flake/text/KoSvgTextShape_p_output.cpp+++ b/libs/flake/text/KoSvgTextShape_p_output.cpp@@ -343,13 +343,15 @@ KoShapeStrokeModelSP transformStrokeBgToNewBounds(KoShapeStrokeModelSP stroke, cQBrush b = s->lineBrush();if (b.gradient()) {QRectF nb = newBounds;+ QRectF ob = oldBounds;if (calcInsets) {KoInsets insets;s->strokeInsets(nullptr, insets);nb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);+ ob.adjust(-insets.left, -insets.top, insets.right, insets.bottom);}- QRectF relative = KisAlgebra2D::absoluteToRelative(oldBounds, nb);+ QRectF relative = KisAlgebra2D::absoluteToRelative(ob, nb);KoShapeStrokeSP newStroke(new KoShapeStroke(*s.data()));QTransform newTf = QTransform::fromTranslate(relative.x(), relative.y());newTf.scale(relative.width(), relative.height());@@ -363,7 +365,7 @@ KoShapeStrokeModelSP transformStrokeBgToNewBounds(KoShapeStrokeModelSP stroke, c// NOLINTNEXTLINE(readability-function-cognitive-complexity)KoShape *-KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex)+KoSvgTextShape::Private::collectPaths(const KoSvgTextShape *rootShape, QVector<CharacterResult> &result, int ¤tIndex){QList<KoShape *> shapes;@@ -390,6 +392,8 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<CharacteQSharedPointer<KoShapeBackground> background = rootShape->background();QVector<KoShape::PaintOrder> paintOrder = rootShape->paintOrder();+ const QRectF rootOutline = Private::boundingBoxFromTree(textData, rootShape, false);+bool currentNodeInheritsBg = false;bool currentNodeInheritsStroke = false;@@ -421,7 +425,7 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characteif (textDecorations.contains(KoSvgText::DecorationUnderline)) {KoPathShape *shape = KoPathShape::createShapeFromPainterPath(textDecorations.value(KoSvgText::DecorationUnderline));shape->setBackground(transformBackgroundToBounds(decorationColor,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setStroke(stroke);shape->setZIndex(shapes.size());@@ -437,10 +441,10 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characteif (textDecorations.contains(KoSvgText::DecorationOverline)) {KoPathShape *shape = KoPathShape::createShapeFromPainterPath(textDecorations.value(KoSvgText::DecorationOverline));shape->setBackground(transformBackgroundToBounds(decorationColor,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setStroke(transformStrokeBgToNewBounds(stroke,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setZIndex(shapes.size());shape->setFillRule(Qt::WindingFill);@@ -526,11 +530,11 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characte}KoPathShape *shape = KoPathShape::createShapeFromPainterPath(chunk);shape->setBackground(transformBackgroundToBounds(background,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setStroke(transformStrokeBgToNewBounds(stroke,- rootShape->outlineRect().adjusted(-insets.left, -insets.top, insets.right, insets.bottom),+ rootOutline,shape->outlineRect()));shape->setZIndex(shapes.size());shape->setFillRule(Qt::WindingFill);@@ -555,10 +559,10 @@ KoSvgTextShape::Private::collectPaths(const KoShape *rootShape, QVector<Characteif (textDecorations.contains(KoSvgText::DecorationLineThrough)) {KoPathShape *shape = KoPathShape::createShapeFromPainterPath(textDecorations.value(KoSvgText::DecorationLineThrough));shape->setBackground(transformBackgroundToBounds(decorationColor,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setStroke(transformStrokeBgToNewBounds(stroke,- rootShape->outlineRect(),+ rootOutline,shape->outlineRect()));shape->setZIndex(shapes.size());shape->setFillRule(Qt::WindingFill);