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 font-size always being loaded for character style presets.
Wolthera van Hövell tot Westerflieraa603bea6339
diff --git a/libs/flake/resources/KoCssStylePreset.cpp b/libs/flake/resources/KoCssStylePreset.cppindex 52eb3a9c6d..458b96b2e7 100644--- a/libs/flake/resources/KoCssStylePreset.cpp+++ b/libs/flake/resources/KoCssStylePreset.cpp@@ -160,6 +160,8 @@ void KoCssStylePreset::setSampleText(const QString &sample, const KoSvgTextPropesampleText->setPropertiesAtPos(-1, modifiedProps);if (type == STYLE_TYPE_PARAGRAPH) {+ // For paragraph we'll add a shape, as those will allow wrapping,+ // without being part of the properties like inline-size is.KoPathShape *inlineShape = new KoPathShape();inlineShape->moveTo(QPointF(0, 0));inlineShape->lineTo(QPointF(120, 0));@@ -172,30 +174,27 @@ void KoCssStylePreset::setSampleText(const QString &sample, const KoSvgTextProped->shape.reset(sampleText);} else {+ /// For character the sample always needs to be set to be a child to+ /// ensure that the character property doesn't include the default props.+ KoSvgTextShape *newShape = new KoSvgTextShape();+ KoSvgTextProperties paraProps = KoSvgTextProperties::defaultProperties();+ // Set whitespace rule to pre-wrap.+ paraProps.setProperty(KoSvgTextProperties::TextCollapseId, KoSvgText::Preserve);+ paraProps.setProperty(KoSvgTextProperties::TextWrapId, KoSvgText::Wrap);+ newShape->setPropertiesAtPos(-1, paraProps);+ if (!after.isEmpty()) {+ newShape->insertText(0, after);+ }+ if (!before.isEmpty()) {+ newShape->insertText(0, before);+ }- if (before.isEmpty() && after.isEmpty()) {- d->shape.reset(sampleText);- } else {- KoSvgTextShape *newShape = new KoSvgTextShape();- KoSvgTextProperties paraProps = KoSvgTextProperties::defaultProperties();- // Set whitespace rule to pre-wrap.- paraProps.setProperty(KoSvgTextProperties::TextCollapseId, KoSvgText::Preserve);- paraProps.setProperty(KoSvgTextProperties::TextWrapId, KoSvgText::Wrap);- newShape->setPropertiesAtPos(-1, paraProps);- if (!after.isEmpty()) {- newShape->insertText(0, after);- }- if (!before.isEmpty()) {- newShape->insertText(0, before);- }+ newShape->insertRichText(newShape->posForIndex(before.size()), sampleText);- newShape->insertRichText(newShape->posForIndex(before.size()), sampleText);+ d->shape.reset(newShape);- d->shape.reset(newShape);- }}- // Don't d->shape->cleanup() here, as it *can* lead to the sample getting cleaned up.d->shape->cleanUp();updateThumbnail();setValid(true);@@ -340,6 +339,7 @@ KoResourceSP KoCssStylePreset::clone() constbool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface){+ Q_UNUSED(resourcesInterface)if (!dev->isOpen()) dev->open(QIODevice::ReadOnly);QString errorMsg;int errorLine = 0;@@ -360,6 +360,7 @@ bool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP reKoDocumentResourceManager manager;SvgParser parser(&manager);parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values+ parser.setResolveTextPropertiesForTopLevel(false);QSizeF fragmentSize;QList<KoShape*> shapes = parser.parseSvg(xmlDocument.documentElement(), &fragmentSize);diff --git a/libs/flake/svg/SvgParser.cpp b/libs/flake/svg/SvgParser.cppindex a97f63f6de..ae920e7d24 100644--- a/libs/flake/svg/SvgParser.cpp+++ b/libs/flake/svg/SvgParser.cpp@@ -203,9 +203,14 @@ void SvgParser::setDefaultKraTextVersion(int version)m_context.currentGC()->textProperties.setProperty(KoSvgTextProperties::KraTextVersionId, version);}-void SvgParser::setInheritByDefault(const bool enable)+void SvgParser::setFillStrokeInheritByDefault(const bool enable){- m_inheritByDefault = enable;+ m_inheritStrokeFillByDefault = enable;+}++void SvgParser::setResolveTextPropertiesForTopLevel(const bool enable)+{+ m_resolveTextPropertiesForTopLevel = enable;}QList<KoShape*> SvgParser::shapes() const@@ -945,7 +950,7 @@ void SvgParser::uploadStyleToContext(const QDomElement &e){SvgStyles styles = m_context.styleParser().collectStyles(e);m_context.styleParser().parseFont(styles);- m_context.styleParser().parseStyle(styles, m_inheritByDefault);+ m_context.styleParser().parseStyle(styles, m_inheritStrokeFillByDefault);}void SvgParser::applyCurrentStyle(KoShape *shape, const QPointF &shapeToOriginalUserCoordinates)@@ -1006,7 +1011,7 @@ void SvgParser::applyStyle(KoShape *obj, const SvgStyles &styles, const QPointFif (!gc)return;- m_context.styleParser().parseStyle(styles, m_inheritByDefault);+ m_context.styleParser().parseStyle(styles, m_inheritStrokeFillByDefault);if (!obj)return;@@ -1899,7 +1904,7 @@ KoShape *SvgParser::parseTextElement(const QDomElement &e, KoSvgTextShape *merge}}- textLoader.loadSvg(e, m_context, true);+ textLoader.loadSvg(e, m_context, m_resolveTextPropertiesForTopLevel);// 1) apply transformation only in case we are not overriding the shape!// 2) the transformation should be applied *before* the shape is added to the group!diff --git a/libs/flake/svg/SvgParser.h b/libs/flake/svg/SvgParser.hindex dfa420a736..deafc2754c 100644--- a/libs/flake/svg/SvgParser.h+++ b/libs/flake/svg/SvgParser.h@@ -60,7 +60,13 @@ public:// Set whether to always consider shapes without fill or stroke explicitely set as inherited.// By default, this is off, and the parser retrieves the fill from the graphicsContext.- void setInheritByDefault(const bool enable);+ void setFillStrokeInheritByDefault(const bool enable);++ // Whether to try and resolve the text properties for toplevel shapes.+ // By default this is on, as there might be doc-wide css that needs to+ // be resolved. However, for the style properties resource we turn this+ // off.+ void setResolveTextPropertiesForTopLevel(const bool enable);/// Returns the list of all shapes of the svg documentQList<KoShape*> shapes() const;@@ -235,7 +241,8 @@ private:QString m_documentDescription;QVector<KoID> m_warnings;QMap<KoShape *, QTransform> m_shapeParentTransform;- bool m_inheritByDefault = false;+ bool m_inheritStrokeFillByDefault = false;+ bool m_resolveTextPropertiesForTopLevel = true;};#endifdiff --git a/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp b/plugins/dockers/textproperties/KoShapeQtQuickLabel.cppindex 3921694d8f..15de3172e2 100644--- a/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp+++ b/plugins/dockers/textproperties/KoShapeQtQuickLabel.cpp@@ -129,7 +129,7 @@ void KoShapeQtQuickLabel::setSvgData(const QString &newSvgData)QRectF bb = QRectF( 0, 0, 200, 200);QSizeF sz = bb.size();p.setResolution(bb, 72);- p.setInheritByDefault(true);+ p.setFillStrokeInheritByDefault(true);QList<KoShape*> shapes = p.parseSvg(doc.documentElement(), &sz);