Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Make paragraph properties only apply to the paragraph.

Wolthera van Hövell tot Westerfliere6c0196e425d
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index eb65843717..45c7973cb6 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -1210,3 +1210,12 @@ const KoSvgTextProperties &KoSvgTextProperties::defaultProperties()
return *s_defaultProperties;
}
+bool KoSvgTextProperties::propertyIsBlockOnly(PropertyId id)
+{
+ return id == WritingModeId ||
+ id == TextAlignAllId ||
+ id == TextAlignLastId ||
+ id == TextIndentId ||
+ id == HangingPunctuationId;
+}
+
diff --git a/libs/flake/text/KoSvgTextProperties.h b/libs/flake/text/KoSvgTextProperties.h
index 875cde6f64..5a9df5b14c 100644
--- a/libs/flake/text/KoSvgTextProperties.h
+++ b/libs/flake/text/KoSvgTextProperties.h
@@ -277,6 +277,14 @@ public:
*/
static const KoSvgTextProperties& defaultProperties();
+ /**
+ * Returns whether the property only applies to paragraphs (what CSS calls blocks).
+ * Within SVG, all paragraphs are blocks and all text inside is inline. There are
+ * some potential caveats to this (text-combine-upright, ruby), but those are also
+ * unique in other ways.
+ */
+ static bool propertyIsBlockOnly(KoSvgTextProperties::PropertyId id);
+
private:
struct Private;
const QScopedPointer<Private> m_d;
diff --git a/libs/flake/text/KoSvgTextShape.cpp b/libs/flake/text/KoSvgTextShape.cpp
index 6207195cae..225d0ec384 100644
--- a/libs/flake/text/KoSvgTextShape.cpp
+++ b/libs/flake/text/KoSvgTextShape.cpp
@@ -939,6 +939,8 @@ void KoSvgTextShape::mergePropertiesIntoRange(const int startPos,
}
bool changed = false;
int currentIndex = 0;
+ KoSvgText::AutoValue inlineSize = d->textData.childBegin()->properties.propertyOrDefault(KoSvgTextProperties::InlineSizeId).value<KoSvgText::AutoValue>();
+ bool isWrapping = !d->shapesInside.isEmpty() || !inlineSize.isAuto;
for (auto it = d->textData.depthFirstTailBegin(); it != d->textData.depthFirstTailEnd(); it++) {
if (KoSvgTextShape::Private::childCount(siblingCurrent(it)) > 0) {
continue;
@@ -946,10 +948,18 @@ void KoSvgTextShape::mergePropertiesIntoRange(const int startPos,
if (currentIndex >= startIndex && currentIndex < endIndex) {
Q_FOREACH(KoSvgTextProperties::PropertyId p, properties.properties()) {
- it->properties.setProperty(p, properties.property(p));
+ if (KoSvgTextProperties::propertyIsBlockOnly(p) || (p == KoSvgTextProperties::TextAnchorId && isWrapping)) {
+ d->textData.childBegin()->properties.setProperty(p, properties.property(p));
+ } else {
+ it->properties.setProperty(p, properties.property(p));
+ }
}
Q_FOREACH(KoSvgTextProperties::PropertyId p, removeProperties) {
- it->properties.removeProperty(p);
+ if (KoSvgTextProperties::propertyIsBlockOnly(p)) {
+ d->textData.childBegin()->properties.removeProperty(p);
+ } else {
+ it->properties.removeProperty(p);
+ }
}
changed = true;