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

Load and use new font relative values in css-values-4

Wolthera van Hövell tot Westerflier4f7447ba3b6f
diff --git a/libs/flake/svg/SvgUtil.cpp b/libs/flake/svg/SvgUtil.cpp
index 05352e22e9..a09a199f52 100644
--- a/libs/flake/svg/SvgUtil.cpp
+++ b/libs/flake/svg/SvgUtil.cpp
@@ -227,7 +227,7 @@ qreal SvgUtil::parseUnit(SvgGraphicsContext *gc, const KoSvgTextProperties &reso
return 0.0;
}
KoSvgText::CssLengthPercentage length = parseUnitStruct(gc, unit, horiz, vert, bbox);
- length.convertToAbsolute(resolved.fontSize().value, resolved.xHeight());
+ length.convertToAbsolute(resolved.metrics(), resolved.fontSize().value);
return length.value;
}
@@ -273,6 +273,14 @@ KoSvgText::CssLengthPercentage SvgUtil::parseUnitStructImpl(SvgGraphicsContext *
length.unit = KoSvgText::CssLengthPercentage::Em;
} else if (unit.right(2) == QLatin1String("ex")) {
length.unit = KoSvgText::CssLengthPercentage::Ex;
+ } else if (unit.right(3) == QLatin1String("cap")) {
+ length.unit = KoSvgText::CssLengthPercentage::Cap;
+ } else if (unit.right(2) == QLatin1String("ch")) {
+ length.unit = KoSvgText::CssLengthPercentage::Ch;
+ } else if (unit.right(2) == QLatin1String("ic")) {
+ length.unit = KoSvgText::CssLengthPercentage::Ic;
+ } else if (unit.right(2) == QLatin1String("lh")) {
+ length.unit = KoSvgText::CssLengthPercentage::Lh;
} else if (unit.right(1) == QLatin1Char('%')) {
if (percentageViewBox) {
diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cpp
index 8ccc8a217f..04552a8226 100644
--- a/libs/flake/text/KoFontRegistry.cpp
+++ b/libs/flake/text/KoFontRegistry.cpp
@@ -768,19 +768,19 @@ KoSvgText::FontMetrics KoFontRegistry::generateFontMetrics(FT_FaceSP face, bool
// Fontsize and advances.
metrics.fontSize = isHorizontal? face.data()->size->metrics.y_ppem*64.0: face.data()->size->metrics.x_ppem*64.0;
- if(!FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), ' '), faceLoadFlags)) {
+ if(FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), ' '), faceLoadFlags)) {
metrics.spaceAdvance = isHorizontal? face.data()->glyph->advance.x: face.data()->glyph->advance.y;
} else {
metrics.spaceAdvance = isHorizontal? metrics.fontSize/2: metrics.fontSize;
}
- if(!FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), '0'), faceLoadFlags)) {
+ if(FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), '0'), faceLoadFlags)) {
metrics.zeroAdvance = isHorizontal? face.data()->glyph->advance.x: face.data()->glyph->advance.y;
} else {
metrics.zeroAdvance = isHorizontal? metrics.fontSize/2: metrics.fontSize;
}
- if(!FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), 0x6C34), faceLoadFlags)) {
+ if(FT_Load_Glyph(face.data(), FT_Get_Char_Index(face.data(), 0x6C34), faceLoadFlags)) {
metrics.ideographicAdvance = isHorizontal? face.data()->glyph->advance.x: face.data()->glyph->advance.y;
} else {
metrics.ideographicAdvance = metrics.fontSize;
diff --git a/libs/flake/text/KoSvgText.cpp b/libs/flake/text/KoSvgText.cpp
index c26dd19828..1a026d2016 100644
--- a/libs/flake/text/KoSvgText.cpp
+++ b/libs/flake/text/KoSvgText.cpp
@@ -888,6 +888,14 @@ QDebug operator<<(QDebug dbg, const CssLengthPercentage &value)
dbg.nospace() << value.value << "em";
} else if (value.unit == CssLengthPercentage::Ex) {
dbg.nospace() << value.value << "ex";
+ } else if (value.unit == CssLengthPercentage::Cap) {
+ dbg.nospace() << value.value << "cap";
+ } else if (value.unit == CssLengthPercentage::Ch) {
+ dbg.nospace() << value.value << "ch";
+ } else if (value.unit == CssLengthPercentage::Ic) {
+ dbg.nospace() << value.value << "ic";
+ } else if (value.unit == CssLengthPercentage::Lh) {
+ dbg.nospace() << value.value << "lh";
} else {
dbg.nospace() << value.value << "(pt)";
}
@@ -907,20 +915,40 @@ QString writeLengthPercentage(const CssLengthPercentage &length, bool percentage
val += "em";
} else if (length.unit == CssLengthPercentage::Ex) {
val += "ex";
+ } else if (length.unit == CssLengthPercentage::Cap) {
+ val += "cap";
+ } else if (length.unit == CssLengthPercentage::Ch) {
+ val += "ch";
+ } else if (length.unit == CssLengthPercentage::Ic) {
+ val += "ic";
+ } else if (length.unit == CssLengthPercentage::Lh) {
+ val += "lh";
}
}
return val;
}
-void CssLengthPercentage::convertToAbsolute(const qreal fontSizeInPt, const qreal fontXHeightInPt, const CssLengthPercentage::UnitType percentageUnit) {
+void CssLengthPercentage::convertToAbsolute(const KoSvgText::FontMetrics metrics, const qreal fontSize, const CssLengthPercentage::UnitType percentageUnit) {
UnitType u = unit;
if (u == Percentage) {
u = percentageUnit;
}
+ // FontMetrics is in freetype pixels, but we also don't know the resolution, which we need to calculate pt.
+ // So the first multiplier handles the potential resolution difference, the second multiplier the freetype pixel.
+ const qreal fontSizeMultiplier = 1/((metrics.fontSize/64.0)/fontSize);
+ const qreal ftMultiplier = fontSizeMultiplier/64.0;
if (u == Em) {
- value = value * fontSizeInPt;
+ value = value * fontSize;
} else if (u == Ex) {
- value = value * fontXHeightInPt;
+ value = value * metrics.xHeight * ftMultiplier;
+ } else if (u == Cap) {
+ value = value * metrics.capHeight * ftMultiplier;
+ } else if (u == Ch) {
+ value = value * metrics.zeroAdvance * ftMultiplier;
+ } else if (u == Ic) {
+ value = value * metrics.ideographicAdvance * ftMultiplier;
+ } else if (u == Lh) {
+ value = value * (metrics.ascender - metrics.descender + metrics.lineGap) * ftMultiplier;
}
unit = Absolute;
}
@@ -1399,6 +1427,52 @@ FontMetrics::FontMetrics(qreal fontSizeInPt, bool isHorizontal)
ideographicFaceOverBaseline = ascender;
}
+bool FontMetrics::operator==(const FontMetrics &other) const {
+ return isVertical == other.isVertical
+ && fontSize == other.fontSize
+ && zeroAdvance == other.zeroAdvance
+ && spaceAdvance == other.spaceAdvance
+ && ideographicAdvance == other.ideographicAdvance
+ && xHeight == other.xHeight
+ && capHeight == other.capHeight
+ && subScriptOffset == other.subScriptOffset
+ && superScriptOffset == other.superScriptOffset
+ && ascender == other.ascender
+ && descender == other.descender
+ && lineGap == other.lineGap
+ && alphabeticBaseline == other.alphabeticBaseline
+ && ideographicUnderBaseline == other.ideographicUnderBaseline
+ && ideographicCenterBaseline == other.ideographicCenterBaseline
+ && ideographicOverBaseline == other.ideographicOverBaseline
+ && ideographicFaceUnderBaseline == other.ideographicFaceUnderBaseline
+ && ideographicFaceOverBaseline == other.ideographicFaceOverBaseline
+ && hangingBaseline == other.hangingBaseline;
+}
+
+int FontMetrics::valueForBaselineValue(Baseline baseline) const {
+ switch(baseline) {
+ case BaselineIdeographic:
+ return ideographicUnderBaseline;
+ case BaselineAlphabetic:
+ return alphabeticBaseline;
+ case BaselineHanging:
+ return hangingBaseline;
+ case BaselineMathematical:
+ return mathematicalBaseline;
+ case BaselineCentral:
+ return ideographicCenterBaseline;
+ case BaselineMiddle:
+ return xHeight/2;
+ case BaselineTextBottom:
+ return descender;
+ case BaselineTextTop:
+ return ascender;
+ default:
+ break;
+ }
+ return 0;
+}
+
void FontMetrics::setBaselineValueByTag(const QLatin1String &tag, int32_t value) {
if (tag == "romn") {
alphabeticBaseline = value;
diff --git a/libs/flake/text/KoSvgText.h b/libs/flake/text/KoSvgText.h
index d07a878903..434ee5557b 100644
--- a/libs/flake/text/KoSvgText.h
+++ b/libs/flake/text/KoSvgText.h
@@ -307,6 +307,59 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(TextSpaceTrims)
Q_DECLARE_FLAGS(HangingPunctuations, HangingPunctuation)
Q_DECLARE_OPERATORS_FOR_FLAGS(HangingPunctuations)
+/**
+ * @brief The FontMetrics class
+ * A class to keep track of a variety of font metrics.
+ * Note that values are in Freetype pixels and coordinates! (that is 64 times bigger than a regular pixel, and Y is swapped.)
+ */
+struct FontMetrics : public boost::equality_comparable<FontMetrics> {
+ bool isVertical = false; ///< Different fontMetrics count between vertical and horizontal.
+ qint32 fontSize; ///< Currently set size, CSS unit 'em'
+ qint32 zeroAdvance; ///< Advance of the character '0', CSS Unit 'ch', defaults to 0.5 em in horizontal and 1.0 em in vertical.
+ qint32 spaceAdvance;///< Advance of the character ' ', used by tabs.
+ qint32 ideographicAdvance; ///< Advance of the character '水' (U+6C34), CSS Unit ic, defaults to 1 em.
+
+ qint32 xHeight; ///< height of X, defaults to 0.5 fontsize.
+ qint32 capHeight; ///< Height of capital letters, defaults to ascender.
+ QPair<qint32, qint32> subScriptOffset; ///< subscript baseline height, defaults to 1/5th em below alphabetic.
+ QPair<qint32, qint32> superScriptOffset; ///< superscript baseline height, defaults to 2/3rd above alphabetic.
+
+ qint32 ascender; ///< distance from origin to top.
+ qint32 descender; ///< distance for origin to bottom.
+ qint32 lineGap; ///< additional linegap between consequetive lines.
+
+ qint32 alphabeticBaseline; ///< location of alphabetic baseline from origin.
+ qint32 mathematicalBaseline; ///< location of mathematical baseline from origin.
+
+ qint32 ideographicUnderBaseline; ///< location of ideographic under baseline from origin, may fall back to descender.
+ qint32 ideographicCenterBaseline; ///< location of ideographic center baseline from origin,
+ ///< default baseline for vertical, centered between over and under.
+ qint32 ideographicOverBaseline; ///< location of ideographic over baseline from origin.
+
+ qint32 ideographicFaceUnderBaseline; ///< location of ideographic face under baseline, that is, the bottom of the glyphs.
+ qint32 ideographicFaceOverBaseline; ///< location of ideographic face over baseline, that is, the top of the glyphs.
+
+ qint32 hangingBaseline; ///< location of the hanging baseline used in north brahmic scripts.
+
+ FontMetrics () {
+
+ }
+
+ // Generate fallback font metrics from a fontSize.
+ FontMetrics (qreal fontSizeInPt, bool isHorizontal);
+
+ bool operator==(const FontMetrics & other) const;
+
+ int valueForBaselineValue(Baseline baseline) const;
+
+ void setBaselineValueByTag(const QLatin1String &tag, int32_t value);
+
+ void setMetricsValueByTag(const QLatin1String &tag, int32_t value);
+
+ void scaleBaselines(const qreal multiplier);
+};
+QDebug KRITAFLAKE_EXPORT operator<<(QDebug dbg, const KoSvgText::FontMetrics &metrics);
+
/**
* CssLengthPercentage is a struct that represents the CSS length-percentage,
* which is Css' way of saying that an attribute can be either a length (which
@@ -332,6 +385,10 @@ struct CssLengthPercentage : public boost::equality_comparable<CssLengthPercenta
Percentage, /// 0 to 1.0
Em, /// multiply by Font-size
Ex, /// multiply by font-x-height.
+ Cap,/// multiply by font cap height
+ Ch, /// multiply by width of "0", represents avarage proportional script advance.
+ Ic, /// multiply by width of "U+6C34", represents avarage full width script advance.
+ Lh, /// multiply by lineheight.
};
CssLengthPercentage() {}
@@ -340,7 +397,7 @@ struct CssLengthPercentage : public boost::equality_comparable<CssLengthPercenta
qreal value = 0.0;
UnitType unit = Absolute;
- void convertToAbsolute(const qreal fontSizeInPt, const qreal fontXHeightInPt, const UnitType percentageUnit = Em);
+ void convertToAbsolute(const KoSvgText::FontMetrics metrics, const qreal fontSize, const UnitType percentageUnit = Em);
bool operator==(const CssLengthPercentage & other) const {
return qFuzzyCompare(value, other.value) && unit == other.unit;
@@ -980,100 +1037,7 @@ FontFeatureEastAsian parseFontFeatureEastAsian(const QString &value, FontFeature
QString writeFontFeatureEastAsian(const FontFeatureEastAsian &feature);
QDebug KRITAFLAKE_EXPORT operator<<(QDebug dbg, const KoSvgText::FontFeatureEastAsian &feature);
-/**
- * @brief The FontMetrics class
- * A class to keep track of a variety of font metrics.
- * Note that values are in Freetype pixels and coordinates! (that is 64 times bigger than a regular pixel, and Y is swapped.)
- */
-struct FontMetrics : public boost::equality_comparable<FontMetrics> {
- bool isVertical = false; ///< Different fontMetrics count between vertical and horizontal.
- qint32 fontSize; ///< Currently set size, CSS unit 'em'
- qint32 zeroAdvance; ///< Advance of the character '0', CSS Unit 'ch', defaults to 0.5 em in horizontal and 1.0 em in vertical.
- qint32 spaceAdvance;///< Advance of the character ' ', used by tabs.
- qint32 ideographicAdvance; ///< Advance of the character '水' (U+6C34), CSS Unit ic, defaults to 1 em.
-
- qint32 xHeight; ///< height of X, defaults to 0.5 fontsize.
- qint32 capHeight; ///< Height of capital letters, defaults to ascender.
- QPair<qint32, qint32> subScriptOffset; ///< subscript baseline height, defaults to 1/5th em below alphabetic.
- QPair<qint32, qint32> superScriptOffset; ///< superscript baseline height, defaults to 2/3rd above alphabetic.
-
- qint32 ascender; ///< distance from origin to top.
- qint32 descender; ///< distance for origin to bottom.
- qint32 lineGap; ///< additional linegap between consequetive lines.
-
- qint32 alphabeticBaseline; ///< location of alphabetic baseline from origin.
- qint32 mathematicalBaseline; ///< location of mathematical baseline from origin.
-
- qint32 ideographicUnderBaseline; ///< location of ideographic under baseline from origin, may fall back to descender.
- qint32 ideographicCenterBaseline; ///< location of ideographic center baseline from origin,
- ///< default baseline for vertical, centered between over and under.
- qint32 ideographicOverBaseline; ///< location of ideographic over baseline from origin.
- qint32 ideographicFaceUnderBaseline; ///< location of ideographic face under baseline, that is, the bottom of the glyphs.
- qint32 ideographicFaceOverBaseline; ///< location of ideographic face over baseline, that is, the top of the glyphs.
-
- qint32 hangingBaseline; ///< location of the hanging baseline used in north brahmic scripts.
-
- FontMetrics () {
-
- }
-
- // Generate fallback font metrics from a fontSize.
- FontMetrics (qreal fontSizeInPt, bool isHorizontal);
-
- bool operator==(const FontMetrics & other) const {
- return isVertical == other.isVertical
- && fontSize == other.fontSize
- && zeroAdvance == other.zeroAdvance
- && spaceAdvance == other.spaceAdvance
- && ideographicAdvance == other.ideographicAdvance
- && xHeight == other.xHeight
- && capHeight == other.capHeight
- && subScriptOffset == other.subScriptOffset
- && superScriptOffset == other.superScriptOffset
- && ascender == other.ascender
- && descender == other.descender
- && lineGap == other.lineGap
- && alphabeticBaseline == other.alphabeticBaseline
- && ideographicUnderBaseline == other.ideographicUnderBaseline
- && ideographicCenterBaseline == other.ideographicCenterBaseline
- && ideographicOverBaseline == other.ideographicOverBaseline
- && ideographicFaceUnderBaseline == other.ideographicFaceUnderBaseline
- && ideographicFaceOverBaseline == other.ideographicFaceOverBaseline
- && hangingBaseline == other.hangingBaseline;
- }
-
- int valueForBaselineValue(Baseline baseline) const {
- switch(baseline) {
- case BaselineIdeographic:
- return ideographicUnderBaseline;
- case BaselineAlphabetic:
- return alphabeticBaseline;
- case BaselineHanging:
- return hangingBaseline;
- case BaselineMathematical:
- return mathematicalBaseline;
- case BaselineCentral:
- return ideographicCenterBaseline;
- case BaselineMiddle:
- return xHeight/2;
- case BaselineTextBottom:
- return descender;
- case BaselineTextTop:
- return ascender;
- default:
- break;
- }
- return 0;
- }
-
- void setBaselineValueByTag(const QLatin1String &tag, int32_t value);
-
- void setMetricsValueByTag(const QLatin1String &tag, int32_t value);
-
- void scaleBaselines(const qreal multiplier);
-};
-QDebug KRITAFLAKE_EXPORT operator<<(QDebug dbg, const KoSvgText::FontMetrics &metrics);
} // namespace KoSvgText
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index c7c60d06b7..64589b24cc 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -121,48 +121,52 @@ void KoSvgTextProperties::inheritFrom(const KoSvgTextProperties &parentPropertie
}
if (resolve) {
- resolveRelativeValues(parentProperties.fontSize().value, parentProperties.xHeight());
+ resolveRelativeValues(parentProperties.metrics(), parentProperties.fontSize().value);
}
}
-void KoSvgTextProperties::resolveRelativeValues(const qreal fontSize, const qreal xHeight)
+void KoSvgTextProperties::resolveRelativeValues(const KoSvgText::FontMetrics metrics, const qreal fontSize)
{
// First resolve 'font-*' properties.
// See https://www.w3.org/TR/css-values-4/#font-relative-lengths
- // Note: if we ever support lh (lineheight unit) that needs to be resolved here first too.
KoSvgText::CssLengthPercentage size = this->fontSize();
- size.convertToAbsolute(fontSize, xHeight);
+ size.convertToAbsolute(metrics, fontSize);
this->setFontSize(size);
- qreal usedSize = size.value;
- qreal usedXHeight = this->xHeight();
+ const qreal usedSize = size.value;
+ 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(this->metrics(false), usedSize);
+ }
+ setProperty(LineHeightId, QVariant::fromValue(lineHeight));
+ }
+
+ const KoSvgText::FontMetrics usedMetrics = this->metrics();
for (auto it = this->m_d->properties.begin(); it != this->m_d->properties.end(); it++) {
+ if (it.key() == LineHeightId) continue;
if (it.value().canConvert<KoSvgText::CssLengthPercentage>() && it.key() != KoSvgTextProperties::FontSizeId) {
KoSvgText::CssLengthPercentage length = it.value().value<KoSvgText::CssLengthPercentage>();
- length.convertToAbsolute(usedSize, usedXHeight);
+ length.convertToAbsolute(usedMetrics, usedSize);
it.value() = QVariant::fromValue(length);
} else if (it.value().canConvert<KoSvgText::AutoLengthPercentage>()) {
KoSvgText::AutoLengthPercentage val = it.value().value<KoSvgText::AutoLengthPercentage>();
if (!val.isAuto) {
- val.length.convertToAbsolute(usedSize, usedXHeight);
+ val.length.convertToAbsolute(usedMetrics, usedSize);
it.value() = QVariant::fromValue(val);
}
- } else if (it.key() == KoSvgTextProperties::LineHeightId) {
- KoSvgText::LineHeightInfo lineHeight = it.value().value<KoSvgText::LineHeightInfo>();
- if (!lineHeight.isNormal && !lineHeight.isNumber) {
- lineHeight.length.convertToAbsolute(usedSize, usedXHeight);
- it.value() = QVariant::fromValue(lineHeight);
- }
} else if (it.key() == KoSvgTextProperties::TabSizeId) {
KoSvgText::TabSizeInfo tabSize = it.value().value<KoSvgText::TabSizeInfo>();
if (!tabSize.isNumber) {
- tabSize.length.convertToAbsolute(usedSize, usedXHeight);
+ tabSize.length.convertToAbsolute(usedMetrics, usedSize);
it.value() = QVariant::fromValue(tabSize);
}
} else if (it.key() == KoSvgTextProperties::TextIndentId) {
KoSvgText::TextIndentInfo indent = it.value().value<KoSvgText::TextIndentInfo>();
if (indent.length.unit != KoSvgText::CssLengthPercentage::Percentage) {
- indent.length.convertToAbsolute(usedSize, usedXHeight);
+ indent.length.convertToAbsolute(usedMetrics, usedSize);
}
it.value() = QVariant::fromValue(indent);
}
@@ -1030,16 +1034,41 @@ QFont KoSvgTextProperties::generateFont() const
qreal KoSvgTextProperties::xHeight() const
{
- const KoCSSFontInfo info = cssFontInfo();
+ const KoSvgText::FontMetrics metrics = this->metrics(false);
+
const qreal fontSizeVal = fontSize().value;
- const bool isHorizontal = propertyOrDefault(WritingModeId).toInt() == KoSvgText::HorizontalTB;
- const KoSvgText::FontMetrics metrics = KoFontRegistry::instance()->fontMetricsForCSSValues(info, isHorizontal);
if (metrics.xHeight > 0 && metrics.fontSize > 0) {
return metrics.xHeight * fontSizeVal / metrics.fontSize;
}
return fontSizeVal * 0.5;
}
+KoSvgText::FontMetrics KoSvgTextProperties::metrics(const bool withResolvedLineHeight) const
+{
+ const KoCSSFontInfo info = cssFontInfo();
+
+ const bool isHorizontal = propertyOrDefault(WritingModeId).toInt() == KoSvgText::HorizontalTB;
+ KoSvgText::FontMetrics metrics = KoFontRegistry::instance()->fontMetricsForCSSValues(info, isHorizontal);
+
+ return withResolvedLineHeight? applyLineHeight(metrics): metrics;
+}
+
+KoSvgText::FontMetrics KoSvgTextProperties::applyLineHeight(KoSvgText::FontMetrics metrics) const
+{
+ const qreal res = metrics.fontSize / this->fontSize().value;
+
+ KoSvgText::LineHeightInfo lineHeight = this->propertyOrDefault(LineHeightId).value<KoSvgText::LineHeightInfo>();
+ if (!lineHeight.isNormal) {
+ if (lineHeight.isNumber) {
+ metrics.lineGap = (metrics.fontSize)*lineHeight.value;
+ } else {
+ metrics.lineGap = lineHeight.length.value * res;
+ }
+ metrics.lineGap -= (metrics.ascender-metrics.descender);
+ }
+ return metrics;
+}
+
QStringList KoSvgTextProperties::fontFeaturesForText(int start, int length) const
{
using namespace KoSvgText;
diff --git a/libs/flake/text/KoSvgTextProperties.h b/libs/flake/text/KoSvgTextProperties.h
index d517542795..ae59543abc 100644
--- a/libs/flake/text/KoSvgTextProperties.h
+++ b/libs/flake/text/KoSvgTextProperties.h
@@ -183,7 +183,7 @@ public:
* @param fontSize -- fontsize to resolve 'em' to.
* @param xHeight -- xHeight to resolve 'ex' to.
*/
- void resolveRelativeValues(const qreal fontSize = 12.0, const qreal xHeight = 6.0);
+ void resolveRelativeValues(const KoSvgText::FontMetrics metrics = KoSvgText::FontMetrics(12.0, true), const qreal fontSize = 12.0);
/**
* Return true if the property \p id is inherited from \p parentProperties.
@@ -237,6 +237,22 @@ public:
qreal xHeight() const;
+ /**
+ * @brief metrics
+ * Return the metrics of the first available font.
+ * @param withResolvedLineHeight -- apply the lineheight into the linegap property.
+ * @return metrics for the current font.
+ */
+ KoSvgText::FontMetrics metrics(const bool withResolvedLineHeight = true) const;
+
+ /**
+ * @brief applyLineHeight
+ * Calculate the linegap for the current linegap property.
+ * @param metrics the metrics to apply this to.
+ * @return metrics with the linegap adjusted for the lineheight.
+ */
+ KoSvgText::FontMetrics applyLineHeight(KoSvgText::FontMetrics metrics) const;
+
/**
* @brief fontFeaturesForText
* Returns a harfbuzz friendly list of opentype font-feature settings using
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index 64c975a664..918b996c26 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -272,7 +272,6 @@ void KoSvgTextShape::Private::relayout()
KoSvgText::TabSizeInfo tabInfo = properties.propertyOrDefault(KoSvgTextProperties::TabSizeId).value<KoSvgText::TabSizeInfo>();
KoSvgText::AutoLengthPercentage letterSpacing = properties.propertyOrDefault(KoSvgTextProperties::LetterSpacingId).value<KoSvgText::AutoLengthPercentage>();
KoSvgText::AutoLengthPercentage wordSpacing = properties.propertyOrDefault(KoSvgTextProperties::WordSpacingId).value<KoSvgText::AutoLengthPercentage>();
- KoSvgText::LineHeightInfo lineHeight = properties.propertyOrDefault(KoSvgTextProperties::LineHeightId).value<KoSvgText::LineHeightInfo>();
bool overflowWrap = KoSvgText::OverflowWrap(properties.propertyOrDefault(KoSvgTextProperties::OverflowWrapId).toInt()) != KoSvgText::OverflowWrapNormal;
KoColorBackground *b = dynamic_cast<KoColorBackground *>(chunk.bg.data());
@@ -377,7 +376,6 @@ void KoSvgTextShape::Private::relayout()
QVector<int> lengths;
QStringList fontFeatures = properties.fontFeaturesForText(start, length);
- qreal fontSize = properties.fontSize().value;
const KoSvgText::CssFontStyleData style = properties.propertyOrDefault(KoSvgTextProperties::FontStyleId).value<KoSvgText::CssFontStyleData>();
bool synthesizeWeight = properties.propertyOrDefault(KoSvgTextProperties::FontSynthesisBoldId).toBool();
bool synthesizeStyle = properties.propertyOrDefault(KoSvgTextProperties::FontSynthesisItalicId).toBool();
@@ -442,19 +440,9 @@ void KoSvgTextShape::Private::relayout()
}
result[j].metrics = metricsList.value(currentScript);
- qreal leading = result[j].metrics.lineGap;
+ const KoSvgText::FontMetrics currentMetrics = properties.applyLineHeight(result[j].metrics);
- if (!lineHeight.isNormal) {
- if (lineHeight.isNumber) {
- leading = (fontSize*scaleToPixel*ftFontUnit)*lineHeight.value;
- leading -= (result[j].metrics.ascender-result[j].metrics.descender);
- } else {
- QPointF val = ftTF.inverted().map(QPointF(lineHeight.length.value, lineHeight.length.value));
- leading = isHorizontal? val.x(): val.y();
- leading -= (result[j].metrics.ascender-result[j].metrics.descender);
- }
- }
- result[j].fontHalfLeading = leading * 0.5;
+ result[j].fontHalfLeading = currentMetrics.lineGap / 2;
result[j].fontStyle = synthesizeStyle? style.style: QFont::StyleNormal;
result[j].fontWeight = synthesizeWeight? properties.propertyOrDefault(KoSvgTextProperties::FontWeightId).toInt(): 400;
}
diff --git a/libs/flake/text/lager/LineHeightModel.cpp b/libs/flake/text/lager/LineHeightModel.cpp
index 892d0b367c..3c9b281e00 100644
--- a/libs/flake/text/lager/LineHeightModel.cpp
+++ b/libs/flake/text/lager/LineHeightModel.cpp
@@ -43,6 +43,14 @@ auto getUnit = lager::lenses::getset (
return LineHeightModel::LineHeightType::Em;
case KoSvgText::CssLengthPercentage::Ex:
return LineHeightModel::LineHeightType::Ex;
+ case KoSvgText::CssLengthPercentage::Cap:
+ return LineHeightModel::LineHeightType::Cap;
+ case KoSvgText::CssLengthPercentage::Ch:
+ return LineHeightModel::LineHeightType::Ch;
+ case KoSvgText::CssLengthPercentage::Ic:
+ return LineHeightModel::LineHeightType::Ic;
+ case KoSvgText::CssLengthPercentage::Lh:
+ return LineHeightModel::LineHeightType::Lh;
case KoSvgText::CssLengthPercentage::Percentage:
return LineHeightModel::LineHeightType::Percentage;
}
@@ -63,6 +71,18 @@ auto getUnit = lager::lenses::getset (
case LineHeightModel::LineHeightType::Ex:
data.length.unit = KoSvgText::CssLengthPercentage::Ex;
break;
+ case LineHeightModel::LineHeightType::Cap:
+ data.length.unit = KoSvgText::CssLengthPercentage::Cap;
+ break;
+ case LineHeightModel::LineHeightType::Ch:
+ data.length.unit = KoSvgText::CssLengthPercentage::Ch;
+ break;
+ case LineHeightModel::LineHeightType::Ic:
+ data.length.unit = KoSvgText::CssLengthPercentage::Ic;
+ break;
+ case LineHeightModel::LineHeightType::Lh:
+ data.length.unit = KoSvgText::CssLengthPercentage::Lh;
+ break;
case LineHeightModel::LineHeightType::Percentage:
data.length.unit = KoSvgText::CssLengthPercentage::Percentage;
break;
diff --git a/libs/flake/text/lager/LineHeightModel.h b/libs/flake/text/lager/LineHeightModel.h
index e20dbd2279..77efe52412 100644
--- a/libs/flake/text/lager/LineHeightModel.h
+++ b/libs/flake/text/lager/LineHeightModel.h
@@ -24,6 +24,10 @@ public:
Absolute,
Em,
Ex,
+ Cap,
+ Ch,
+ Ic,
+ Lh,
Percentage,
Lines
};
diff --git a/libs/flake/text/lager/TabSizeModel.cpp b/libs/flake/text/lager/TabSizeModel.cpp
index 27adf8c26b..e19218f77e 100644
--- a/libs/flake/text/lager/TabSizeModel.cpp
+++ b/libs/flake/text/lager/TabSizeModel.cpp
@@ -35,6 +35,14 @@ auto getUnit = lager::lenses::getset (
return TabSizeModel::TabSizeType::Em;
case KoSvgText::CssLengthPercentage::Ex:
return TabSizeModel::TabSizeType::Ex;
+ case KoSvgText::CssLengthPercentage::Cap:
+ return TabSizeModel::TabSizeType::Cap;
+ case KoSvgText::CssLengthPercentage::Ch:
+ return TabSizeModel::TabSizeType::Ch;
+ case KoSvgText::CssLengthPercentage::Ic:
+ return TabSizeModel::TabSizeType::Ic;
+ case KoSvgText::CssLengthPercentage::Lh:
+ return TabSizeModel::TabSizeType::Lh;
default:
break;
}
@@ -55,6 +63,18 @@ auto getUnit = lager::lenses::getset (
case TabSizeModel::TabSizeType::Ex:
data.length.unit = KoSvgText::CssLengthPercentage::Ex;
break;
+ case TabSizeModel::TabSizeType::Cap:
+ data.length.unit = KoSvgText::CssLengthPercentage::Cap;
+ break;
+ case TabSizeModel::TabSizeType::Ch:
+ data.length.unit = KoSvgText::CssLengthPercentage::Ch;
+ break;
+ case TabSizeModel::TabSizeType::Ic:
+ data.length.unit = KoSvgText::CssLengthPercentage::Ic;
+ break;
+ case TabSizeModel::TabSizeType::Lh:
+ data.length.unit = KoSvgText::CssLengthPercentage::Lh;
+ break;
default:
break;
}
diff --git a/libs/flake/text/lager/TabSizeModel.h b/libs/flake/text/lager/TabSizeModel.h
index a761bd5189..ecfc05c69f 100644
--- a/libs/flake/text/lager/TabSizeModel.h
+++ b/libs/flake/text/lager/TabSizeModel.h
@@ -24,6 +24,10 @@ public:
Absolute,
Em,
Ex,
+ Cap,
+ Ch,
+ Ic,
+ Lh,
Spaces
};
Q_ENUM(TabSizeType)
diff --git a/plugins/dockers/textproperties/qml/LineHeight.qml b/plugins/dockers/textproperties/qml/LineHeight.qml
index d2de247bd9..d3f2d29662 100644
--- a/plugins/dockers/textproperties/qml/LineHeight.qml
+++ b/plugins/dockers/textproperties/qml/LineHeight.qml
@@ -104,6 +104,10 @@ TextPropertyBase {
{ text: i18nc("@label:inlistbox", "Pt"), value: LineHeightModel.Absolute},
{ text: i18nc("@label:inlistbox", "Em"), value: LineHeightModel.Em},
{ text: i18nc("@label:inlistbox", "Ex"), value: LineHeightModel.Ex},
+ { text: i18nc("@label:inlistbox", "Cap"), value: LineHeightModel.Cap},
+ { text: i18nc("@label:inlistbox", "Ch"), value: LineHeightModel.Ch},
+ { text: i18nc("@label:inlistbox", "Ic"), value: LineHeightModel.Ic},
+ { text: i18nc("@label:inlistbox", "Lh"), value: LineHeightModel.Lh},
{ text: i18nc("@label:inlistbox", "%"), value: LineHeightModel.Percentage},
{ text: i18nc("@label:inlistbox", "Lines"), value: LineHeightModel.Lines},
]
diff --git a/plugins/dockers/textproperties/qml/TabSize.qml b/plugins/dockers/textproperties/qml/TabSize.qml
index d5dd203db8..e6453d96f5 100644
--- a/plugins/dockers/textproperties/qml/TabSize.qml
+++ b/plugins/dockers/textproperties/qml/TabSize.qml
@@ -77,7 +77,11 @@ TextPropertyBase {
{text: i18nc("@label:inlistbox", "Spaces"), value: TabSizeModel.Spaces},
{text: i18nc("@label:inlistbox", "Pt"), value: TabSizeModel.Absolute},
{text: i18nc("@label:inlistbox", "Em"), value: TabSizeModel.Em},
- {text: i18nc("@label:inlistbox", "Ex"), value: TabSizeModel.Ex}
+ {text: i18nc("@label:inlistbox", "Ex"), value: TabSizeModel.Ex},
+ {text: i18nc("@label:inlistbox", "Cap"), value: TabSizeModel.Cap},
+ {text: i18nc("@label:inlistbox", "Ch"), value: TabSizeModel.Ch},
+ {text: i18nc("@label:inlistbox", "Ic"), value: TabSizeModel.Ic},
+ {text: i18nc("@label:inlistbox", "Lh"), value: TabSizeModel.Lh}
]
textRole: "text";
valueRole: "value";
diff --git a/plugins/dockers/textproperties/qml/UnitComboBox.qml b/plugins/dockers/textproperties/qml/UnitComboBox.qml
index b0fb1277f3..84cc7ca940 100644
--- a/plugins/dockers/textproperties/qml/UnitComboBox.qml
+++ b/plugins/dockers/textproperties/qml/UnitComboBox.qml
@@ -19,6 +19,10 @@ SqueezedComboBox {
property string ptString: i18nc("@label:inlistbox", "Pt");
property string emString: i18nc("@label:inlistbox", "Em");
property string exString: i18nc("@label:inlistbox", "Ex");
+ property string chString: i18nc("@label:inlistbox", "Ch");
+ property string capString: i18nc("@label:inlistbox", "Cap");
+ property string icString: i18nc("@label:inlistbox", "Ic");
+ property string lhString: i18nc("@label:inlistbox", "Lh");
property string prcString: i18nc("@label:inlistbox", "%");
Component.onCompleted: {
@@ -27,7 +31,11 @@ SqueezedComboBox {
model = [
{text: ptString, value: 0},
{text: emString, value: 2},
- {text: exString, value: 3}
+ {text: exString, value: 3},
+ {text: capString, value: 4},
+ {text: chString, value: 5},
+ {text: icString, value: 6},
+ {text: lhString, value: 7}
];
}
}
@@ -36,6 +44,10 @@ SqueezedComboBox {
{text: ptString, value: 0},
{text: emString, value: 2},
{text: exString, value: 3},
+ {text: capString, value: 4},
+ {text: chString, value: 5},
+ {text: icString, value: 6},
+ {text: lhString, value: 7},
{text: prcString, value: 1}
]
textRole: "text";