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 stripped text mode when we have text with contours.
Wolthera van Hövell tot Westerflier42dd732f6a6e
diff --git a/libs/flake/svg/SvgParser.cpp b/libs/flake/svg/SvgParser.cppindex 1ff114fd3b..d1dd036a85 100644--- a/libs/flake/svg/SvgParser.cpp+++ b/libs/flake/svg/SvgParser.cpp@@ -1791,7 +1791,7 @@ QDomText SvgParser::getTheOnlyTextChild(const QDomElement &e)firstChild.toText() : QDomText();}-KoShape* SvgParser::getTextPath(const QDomElement &e) {+KoShape* SvgParser::getTextPath(const QDomElement &e, bool hideShapesFromDefs) {if (e.hasAttribute("path")) {QDomElement p = e.ownerDocument().createElement("path");p.setAttribute("d", e.attribute("path"));@@ -1810,7 +1810,7 @@ KoShape* SvgParser::getTextPath(const QDomElement &e) {KoShape *cloned = s->cloneShape();const QTransform absTf = s->absoluteTransformation();cloned->setTransformation(absTf * m_shapeParentTransform.value(s).inverted());- if(cloned && s->parent()) cloned->setVisible(false);+ if(cloned && m_defsShapes.contains(s) && hideShapesFromDefs) cloned->setVisible(false);return cloned;}}@@ -1818,7 +1818,7 @@ KoShape* SvgParser::getTextPath(const QDomElement &e) {return nullptr;}-void SvgParser::parseTextChildren(const QDomElement &e, KoSvgTextLoader &textLoader) {+void SvgParser::parseTextChildren(const QDomElement &e, KoSvgTextLoader &textLoader, bool hideShapesFromDefs) {QDomText t = getTheOnlyTextChild(e);if (!t.isNull()) {textLoader.loadSvgText(t, m_context);@@ -1838,9 +1838,9 @@ void SvgParser::parseTextChildren(const QDomElement &e, KoSvgTextLoader &textLoauploadStyleToContext(b);textLoader.loadSvg(b, m_context);if (b.hasChildNodes()) {- parseTextChildren(b, textLoader);+ parseTextChildren(b, textLoader, hideShapesFromDefs);}- textLoader.setTextPathOnCurrentNode(getTextPath(b));+ textLoader.setTextPathOnCurrentNode(getTextPath(b, hideShapesFromDefs));m_context.popGraphicsContext();}}@@ -1859,8 +1859,10 @@ KoShape *SvgParser::parseTextElement(const QDomElement &e, KoSvgTextShape *mergeKoSvgTextShape *rootTextShape = 0;+ bool hideShapesFromDefs = false;if (mergeIntoShape) {rootTextShape = mergeIntoShape;+ hideShapesFromDefs = true;} else {KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value("KoSvgTextShapeID");rootTextShape = dynamic_cast<KoSvgTextShape*>(factory->createDefaultShape(m_documentResourceManager));@@ -1876,12 +1878,12 @@ KoShape *SvgParser::parseTextElement(const QDomElement &e, KoSvgTextShape *mergeif (rootTextShape) {if (!m_context.currentGC()->shapeInsideValue.isEmpty()) {- QList<KoShape*> shapesInside = createListOfShapesFromCSS(e, m_context.currentGC()->shapeInsideValue, m_context);+ QList<KoShape*> shapesInside = createListOfShapesFromCSS(e, m_context.currentGC()->shapeInsideValue, m_context, hideShapesFromDefs);rootTextShape->setShapesInside(shapesInside);}if (!m_context.currentGC()->shapeSubtractValue.isEmpty()) {- QList<KoShape*> shapesSubtract = createListOfShapesFromCSS(e, m_context.currentGC()->shapeSubtractValue, m_context);+ QList<KoShape*> shapesSubtract = createListOfShapesFromCSS(e, m_context.currentGC()->shapeSubtractValue, m_context, hideShapesFromDefs);rootTextShape->setShapesSubtract(shapesSubtract);}}@@ -1939,7 +1941,7 @@ KoShape *SvgParser::parseTextElement(const QDomElement &e, KoSvgTextShape *mergetextLoader.loadSvgText(onlyTextChild, m_context);} else {- parseTextChildren(e, textLoader);+ parseTextChildren(e, textLoader, hideShapesFromDefs);}@@ -2258,7 +2260,7 @@ KoShape * SvgParser::createShapeFromElement(const QDomElement &element, SvgLoadireturn object;}-KoShape *SvgParser::createShapeFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context)+KoShape *SvgParser::createShapeFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context, bool hideShapesFromDefs){if (value.isEmpty()) {return 0;@@ -2287,7 +2289,8 @@ KoShape *SvgParser::createShapeFromCSS(const QDomElement e, const QString value,cloned->setTransformation(absTf * m_shapeParentTransform.value(s).inverted());// When we have a parent, the shape is inside the defs, but when not,// it's in the group we're in the currently parsing.- if (cloned && s->parent()) cloned->setVisible(false);++ if (cloned && m_defsShapes.contains(s) && hideShapesFromDefs) cloned->setVisible(false);return cloned;}} else if (value.startsWith("circle(")) {@@ -2335,7 +2338,7 @@ KoShape *SvgParser::createShapeFromCSS(const QDomElement e, const QString value,return shape;}-QList<KoShape *> SvgParser::createListOfShapesFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context)+QList<KoShape *> SvgParser::createListOfShapesFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context, bool hideShapesFromDefs){QList<KoShape*> shapeList;if (value == "auto" || value == "none") {@@ -2343,7 +2346,7 @@ QList<KoShape *> SvgParser::createListOfShapesFromCSS(const QDomElement e, const}QStringList params = value.split(")");Q_FOREACH(const QString param, params) {- KoShape *s = createShapeFromCSS(e, param.trimmed()+")", context);+ KoShape *s = createShapeFromCSS(e, param.trimmed()+")", context, hideShapesFromDefs);if (s) {shapeList.append(s);}diff --git a/libs/flake/svg/SvgParser.h b/libs/flake/svg/SvgParser.hindex bffe7afa39..21210c8f7c 100644--- a/libs/flake/svg/SvgParser.h+++ b/libs/flake/svg/SvgParser.h@@ -95,10 +95,10 @@ protected:KoShape* parseGroup(const QDomElement &e, const QDomElement &overrideChildrenFrom = QDomElement(), bool createContext = true);/// Get the path for the gives textPath element.- KoShape* getTextPath(const QDomElement &e);+ KoShape* getTextPath(const QDomElement &e, bool hideShapesFromDefs = true);/// parse children of a <text /> element into the root shape.- void parseTextChildren(const QDomElement &e, KoSvgTextLoader &textLoader);+ void parseTextChildren(const QDomElement &e, KoSvgTextLoader &textLoader, bool hideShapesFromDefs = true);/// Parses a container element, returning a list of child shapesQList<KoShape*> parseContainer(const QDomElement &);@@ -182,10 +182,10 @@ protected:KoShape * createShapeFromElement(const QDomElement &element, SvgLoadingContext &context);/// Creates a shape from a CSS shapes definition.- KoShape * createShapeFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context);+ KoShape * createShapeFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context, bool hideShapesFromDefs = true);/// Create a list of shapes from a CSS shapes definition with potentially multiple shapes.- QList<KoShape*> createListOfShapesFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context);+ QList<KoShape*> createListOfShapesFromCSS(const QDomElement e, const QString value, SvgLoadingContext &context, bool hideShapesFromDefs = true);/// Builds the document from the given shapes listvoid buildDocument(QList<KoShape*> shapes);diff --git a/libs/flake/text/KoSvgTextContentElement.cpp b/libs/flake/text/KoSvgTextContentElement.cppindex 81c7220415..e53ed59e13 100644--- a/libs/flake/text/KoSvgTextContentElement.cpp+++ b/libs/flake/text/KoSvgTextContentElement.cpp@@ -275,7 +275,7 @@ bool KoSvgTextContentElement::saveSvg(SvgSavingContext &context,if (textPath) {// we'll always save as an embedded shape as "path" is an svg 2.0// feature.- QString id = textPath->isVisible(false)? context.getID(textPath): SvgStyleWriter::embedShape(textPath, context);+ QString id = textPath->isVisible(false) && !context.strippedTextMode()? context.getID(textPath): SvgStyleWriter::embedShape(textPath, context);// inkscape can only read 'xlink:href'if (!id.isEmpty()) {context.shapeWriter().addAttribute("xlink:href", "#" + id);diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cppindex e004641b60..c1cbf0b0c4 100644--- a/libs/flake/text/KoSvgTextShape.cpp+++ b/libs/flake/text/KoSvgTextShape.cpp@@ -1650,7 +1650,8 @@ bool KoSvgTextShape::saveSvg(SvgSavingContext &context)visibleShapes.append(shape);}}- if (!visibleShapes.isEmpty()) {+ const bool writeGroup = !(visibleShapes.isEmpty() || context.strippedTextMode());+ if (writeGroup) {context.shapeWriter().startElement("g", false);context.shapeWriter().addAttribute("id", context.createUID("group"));context.shapeWriter().addAttribute(KoSvgTextShape_TEXTCONTOURGROUP, "true");@@ -1716,7 +1717,7 @@ bool KoSvgTextShape::saveSvg(SvgSavingContext &context)context.shapeWriter().endElement();}}- if (!visibleShapes.isEmpty()) {+ if (writeGroup) {context.shapeWriter().endElement();}return success;@@ -2440,7 +2441,7 @@ QMap<QString, QString> KoSvgTextShape::shapeTypeSpecificStyles(SvgSavingContextif (!d->shapesInside.isEmpty()) {QStringList shapesInsideList;Q_FOREACH(KoShape* shape, d->shapesInside) {- QString id = shape->isVisible(false)? context.getID(shape): SvgStyleWriter::embedShape(shape, context);+ QString id = (shape->isVisible(false) && !context.strippedTextMode())? context.getID(shape): SvgStyleWriter::embedShape(shape, context);shapesInsideList.append(QString("url(#%1)").arg(id));}map.insert("shape-inside", shapesInsideList.join(" "));