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 text properties inheritance only resolve font and lineheight on loading.

Wolthera van Hövell tot Westerfliere9874e3fc8b0
diff --git a/libs/flake/svg/SvgLoadingContext.cpp b/libs/flake/svg/SvgLoadingContext.cpp
index 235f3bfc2e..b2d7b17244 100644
--- a/libs/flake/svg/SvgLoadingContext.cpp
+++ b/libs/flake/svg/SvgLoadingContext.cpp
@@ -281,14 +281,14 @@ QHash<QString, const KoColorProfile *> SvgLoadingContext::profiles()
return d->profiles;
}
-KoSvgTextProperties SvgLoadingContext::resolvedProperties() const
+KoSvgTextProperties SvgLoadingContext::resolvedProperties(bool onlyFontAndLineHeight) const
{
KoSvgTextProperties props;
for (auto it = d->gcStack.begin(); it != d->gcStack.end(); it++) {
SvgGraphicsContext *gc = *it;
KoSvgTextProperties props2 = gc->textProperties;
props.resetNonInheritableToDefault();
- props2.inheritFrom(props, true);
+ props2.inheritFrom(props, true, onlyFontAndLineHeight);
props = props2;
}
return props;
diff --git a/libs/flake/svg/SvgLoadingContext.h b/libs/flake/svg/SvgLoadingContext.h
index 70194bf308..19271aaa33 100644
--- a/libs/flake/svg/SvgLoadingContext.h
+++ b/libs/flake/svg/SvgLoadingContext.h
@@ -81,8 +81,10 @@ public:
/// Return the profiles in the context.
QHash<QString, const KoColorProfile*> profiles();
- /// These are the text properties, completely resolved, ensuring that everything is inherited and the sizes are converted to pt.
- KoSvgTextProperties resolvedProperties() const;
+ /// These are the text properties, completely resolved,
+ /// ensuring that everything is inherited and the sizes are converted to pt.
+ /// @param onlyFontAndLineHeight -- whether to only resolve font and lineheight.
+ KoSvgTextProperties resolvedProperties(bool onlyFontAndLineHeight = false) const;
bool isRootContext() const;
diff --git a/libs/flake/text/KoSvgTextContentElement.cpp b/libs/flake/text/KoSvgTextContentElement.cpp
index e53ed59e13..741169dae1 100644
--- a/libs/flake/text/KoSvgTextContentElement.cpp
+++ b/libs/flake/text/KoSvgTextContentElement.cpp
@@ -165,7 +165,7 @@ bool KoSvgTextContentElement::loadSvg(const QDomElement &e, SvgLoadingContext &c
SvgGraphicsContext *gc = context.currentGC();
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(gc, false);
- KoSvgTextProperties props = rootNode? context.resolvedProperties(): gc->textProperties;
+ KoSvgTextProperties props = rootNode? context.resolvedProperties(true): gc->textProperties;
QVector<KoSvgTextProperties::PropertyId> generic = {KoSvgTextProperties::FillId,
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index 0bbd117f75..6774495de0 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -111,7 +111,7 @@ void KoSvgTextProperties::resetNonInheritableToDefault()
}
}
-void KoSvgTextProperties::inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve)
+void KoSvgTextProperties::inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve, bool onlyFontAndLineHeight)
{
auto it = parentProperties.m_d->properties.constBegin();
for (; it != parentProperties.m_d->properties.constEnd(); ++it) {
@@ -121,11 +121,11 @@ void KoSvgTextProperties::inheritFrom(const KoSvgTextProperties &parentPropertie
}
if (resolve) {
- resolveRelativeValues(parentProperties.metrics(), parentProperties.fontSize().value);
+ resolveRelativeValues(parentProperties.metrics(), parentProperties.fontSize().value, onlyFontAndLineHeight);
}
}
-void KoSvgTextProperties::resolveRelativeValues(const KoSvgText::FontMetrics metrics, const qreal fontSize)
+void KoSvgTextProperties::resolveRelativeValues(const KoSvgText::FontMetrics metrics, const qreal fontSize, bool onlyFontAndLineHeight)
{
// First resolve 'font-*' properties.
// See https://www.w3.org/TR/css-values-4/#font-relative-lengths
@@ -136,15 +136,18 @@ void KoSvgTextProperties::resolveRelativeValues(const KoSvgText::FontMetrics met
KoSvgText::LineHeightInfo lineHeight = this->propertyOrDefault(LineHeightId).value<KoSvgText::LineHeightInfo>();
if (!lineHeight.isNormal && !lineHeight.isNumber) {
if (lineHeight.length.unit == KoSvgText::CssLengthPercentage::Lh) {
- lineHeight.length.convertToAbsolute(metrics, fontSize);
- } else {
+ lineHeight.length.convertToAbsolute(metrics, fontSize, KoSvgText::CssLengthPercentage::Lh);
+ } else if (!onlyFontAndLineHeight) {
lineHeight.length.convertToAbsolute(this->metrics(false), usedSize);
}
setProperty(LineHeightId, QVariant::fromValue(lineHeight));
}
+ if (onlyFontAndLineHeight) return;
+
const KoSvgText::FontMetrics usedMetrics = this->metrics();
+
for (auto it = this->m_d->properties.begin(); it != this->m_d->properties.end(); it++) {
KoSvgText::CssLengthPercentage::UnitType percentageUnit = KoSvgText::CssLengthPercentage::Em;
diff --git a/libs/flake/text/KoSvgTextProperties.h b/libs/flake/text/KoSvgTextProperties.h
index 80d5b3acca..6d5f8cf2c0 100644
--- a/libs/flake/text/KoSvgTextProperties.h
+++ b/libs/flake/text/KoSvgTextProperties.h
@@ -180,15 +180,17 @@ public:
* property is inheritable according to SVG and this set does not define
* it.
*/
- void inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve = false);
+ void inheritFrom(const KoSvgTextProperties &parentProperties, bool resolve = false, bool onlyFontAndLineHeight = false);
/**
* @brief resolveRelativeValues
* resolve the font-relative values.
* @param fontSize -- fontsize to resolve 'em' to.
- * @param xHeight -- xHeight to resolve 'ex' to.
+ * @param onlyFontAndLineHeight -- only resolve fontsize and line height (if necessary).
+ * It can make sense to only want to resolve font and line-height is line-height is LH, because all other relative
+ * units are derived from these.
*/
- void resolveRelativeValues(const KoSvgText::FontMetrics metrics = KoSvgText::FontMetrics(12.0, true), const qreal fontSize = 12.0);
+ void resolveRelativeValues(const KoSvgText::FontMetrics metrics = KoSvgText::FontMetrics(12.0, true), const qreal fontSize = 12.0, bool onlyFontAndLineHeight = false);
/**
* Return true if the property \p id is inherited from \p parentProperties.