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

Fix text-transform not inheriting properly.

Wolthera van Hövell tot Westerfliere27d69d6a00c
diff --git a/libs/flake/text/KoSvgTextContentElement.cpp b/libs/flake/text/KoSvgTextContentElement.cpp
index d114789817..ead3adae17 100644
--- a/libs/flake/text/KoSvgTextContentElement.cpp
+++ b/libs/flake/text/KoSvgTextContentElement.cpp
@@ -381,15 +381,15 @@ static QString transformText(QString text, KoSvgText::TextTransformInfo textTran
return text;
}
-int KoSvgTextContentElement::numChars(bool withControls) const
+int KoSvgTextContentElement::numChars(bool withControls, KoSvgTextProperties resolvedProps) const
{
int result = 0;
if (withControls) {
- KoSvgText::UnicodeBidi bidi = KoSvgText::UnicodeBidi(properties.propertyOrDefault(KoSvgTextProperties::UnicodeBidiId).toInt());
- KoSvgText::Direction direction = KoSvgText::Direction(properties.propertyOrDefault(KoSvgTextProperties::DirectionId).toInt());
+ KoSvgText::UnicodeBidi bidi = KoSvgText::UnicodeBidi(resolvedProps.propertyOrDefault(KoSvgTextProperties::UnicodeBidiId).toInt());
+ KoSvgText::Direction direction = KoSvgText::Direction(resolvedProps.propertyOrDefault(KoSvgTextProperties::DirectionId).toInt());
KoSvgText::TextTransformInfo textTransformInfo =
- properties.propertyOrDefault(KoSvgTextProperties::TextTransformId).value<KoSvgText::TextTransformInfo>();
- QString lang = properties.property(KoSvgTextProperties::TextLanguage).toString().toUtf8();
+ resolvedProps.propertyOrDefault(KoSvgTextProperties::TextTransformId).value<KoSvgText::TextTransformInfo>();
+ QString lang = resolvedProps.property(KoSvgTextProperties::TextLanguage).toString().toUtf8();
QVector<QPair<int, int>> positions;
result = KoCssTextUtils::getBidiOpening(direction == KoSvgText::DirectionLeftToRight, bidi).size();
@@ -411,11 +411,11 @@ void KoSvgTextContentElement::insertText(int start, QString insertText)
}
-QString KoSvgTextContentElement::getTransformedString(QVector<QPair<int, int> > &positions) const
+QString KoSvgTextContentElement::getTransformedString(QVector<QPair<int, int> > &positions, KoSvgTextProperties resolvedProps) const
{
KoSvgText::TextTransformInfo textTransformInfo =
- properties.propertyOrDefault(KoSvgTextProperties::TextTransformId).value<KoSvgText::TextTransformInfo>();
- QString lang = properties.property(KoSvgTextProperties::TextLanguage).toString().toUtf8();
+ resolvedProps.propertyOrDefault(KoSvgTextProperties::TextTransformId).value<KoSvgText::TextTransformInfo>();
+ QString lang = resolvedProps.property(KoSvgTextProperties::TextLanguage).toString().toUtf8();
return transformText(text, textTransformInfo, lang, positions);
}
diff --git a/libs/flake/text/KoSvgTextContentElement.h b/libs/flake/text/KoSvgTextContentElement.h
index cbe9025c4b..22d4a731af 100644
--- a/libs/flake/text/KoSvgTextContentElement.h
+++ b/libs/flake/text/KoSvgTextContentElement.h
@@ -93,13 +93,13 @@ public:
* @param withControls this will enable the bidi controls to be
* counted as well.
*/
- int numChars(bool withControls = false) const;
+ int numChars(bool withControls = false, KoSvgTextProperties resolvedProps = KoSvgTextProperties()) const;
/**
* Get the text with transformations applied.
* @param positions the text positions which may have changed due the uppercase transform.
*/
- QString getTransformedString(QVector<QPair<int, int>> &positions) const;
+ QString getTransformedString(QVector<QPair<int, int>> &positions, KoSvgTextProperties resolvedProps = KoSvgTextProperties()) const;
/**
* @brief insertText
diff --git a/libs/flake/text/KoSvgTextShape_p.h b/libs/flake/text/KoSvgTextShape_p.h
index f964b745c2..8a936e1ae0 100644
--- a/libs/flake/text/KoSvgTextShape_p.h
+++ b/libs/flake/text/KoSvgTextShape_p.h
@@ -427,9 +427,13 @@ public:
CharacterResult &charResult) const;
void clearAssociatedOutlines();
- void resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QString text, QVector<CharacterResult> &result, int &currentIndex, bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars);
+ void resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement,
+ QString text, QVector<CharacterResult> &result, int &currentIndex,
+ bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved,
+ QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps);
- void applyTextLength(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QVector<CharacterResult> &result, int &currentIndex, int &resolvedDescendentNodes, bool isHorizontal);
+ void applyTextLength(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QVector<CharacterResult> &result, int &currentIndex, int &resolvedDescendentNodes, bool isHorizontal,
+ const KoSvgTextProperties resolvedProps);
static void applyAnchoring(QVector<CharacterResult> &result, bool isHorizontal);
static qreal
characterResultOnPath(CharacterResult &cr, qreal length, qreal offset, bool isHorizontal, bool isClosed);
@@ -438,7 +442,7 @@ public:
bool isHorizontal,
qreal offset,
bool isClosed);
- static void applyTextPath(KisForest<KoSvgTextContentElement>::child_iterator parent, QVector<CharacterResult> &result, bool isHorizontal, QPointF &startPos);
+ static void applyTextPath(KisForest<KoSvgTextContentElement>::child_iterator parent, QVector<CharacterResult> &result, bool isHorizontal, QPointF &startPos, const KoSvgTextProperties resolvedProps);
static void computeFontMetrics(KisForest<KoSvgTextContentElement>::child_iterator parent, const KoSvgTextProperties &parentProps,
const KoSvgText::FontMetrics &parentBaselineTable, const KoSvgText::Baseline parentBaseline,
const QPointF superScript,
@@ -451,7 +455,7 @@ public:
static void handleLineBoxAlignment(KisForest<KoSvgTextContentElement>::child_iterator parent,
QVector<CharacterResult> &result, const QVector<LineBox> lineBoxes,
int &currentIndex,
- const bool isHorizontal);
+ const bool isHorizontal, const KoSvgTextProperties resolvedProps);
void computeTextDecorations(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement,
const QVector<CharacterResult>& result,
const QMap<int, int>& logicalToVisual,
@@ -464,8 +468,7 @@ public:
bool ltr,
bool wrapping,
const qreal res,
- const KoSvgText::TextDecorationUnderlinePosition underlinePosH = KoSvgText::TextDecorationUnderlinePosition::UnderlineAuto,
- const KoSvgText::TextDecorationUnderlinePosition underlinePosV = KoSvgText::TextDecorationUnderlinePosition::UnderlineAuto);
+ const KoSvgTextProperties resolvedProps);
QMap<KoSvgText::TextDecoration, QPainterPath> generateDecorationPaths(const int &start, const int &end,
const qreal res,
const QVector<CharacterResult> &result,
@@ -508,10 +511,12 @@ public:
int &currentIndex);
/// Get the number of characters for the whole subtree of this node.
- static int numChars(KisForest<KoSvgTextContentElement>::child_iterator parent, bool withControls = false) {
- int count = parent->numChars(withControls);
+ static int numChars(KisForest<KoSvgTextContentElement>::child_iterator parent, bool withControls = false, KoSvgTextProperties resolvedProps = KoSvgTextProperties::defaultProperties()) {
+ KoSvgTextProperties props = parent->properties;
+ props.inheritFrom(resolvedProps, true);
+ int count = parent->numChars(withControls, props);
for (auto it = KisForestDetail::childBegin(parent); it != KisForestDetail::childEnd(parent); it++) {
- count += numChars(it, withControls);
+ count += numChars(it, withControls, props);
}
return count;
}
diff --git a/libs/flake/text/KoSvgTextShape_p_layout.cpp b/libs/flake/text/KoSvgTextShape_p_layout.cpp
index 96ca62fc2a..fdcbc449a6 100644
--- a/libs/flake/text/KoSvgTextShape_p_layout.cpp
+++ b/libs/flake/text/KoSvgTextShape_p_layout.cpp
@@ -258,7 +258,7 @@ void KoSvgTextShape::Private::relayout()
resolvedTransforms[0].xPos = 0;
resolvedTransforms[0].yPos = 0;
}
- this->resolveTransforms(textData.childBegin(), text, result, globalIndex, isHorizontal, wrapped, false, resolvedTransforms, collapseChars);
+ this->resolveTransforms(textData.childBegin(), text, result, globalIndex, isHorizontal, wrapped, false, resolvedTransforms, collapseChars, KoSvgTextProperties::defaultProperties());
QMap<int, KoSvgText::TabSizeInfo> tabSizeInfo;
@@ -625,7 +625,7 @@ void KoSvgTextShape::Private::relayout()
// Handle baseline alignment.
globalIndex = 0;
- this->handleLineBoxAlignment(textData.childBegin(), result, this->lineBoxes, globalIndex, isHorizontal);
+ this->handleLineBoxAlignment(textData.childBegin(), result, this->lineBoxes, globalIndex, isHorizontal, KoSvgTextProperties::defaultProperties());
if (inlineSize.isAuto && this->shapesInside.isEmpty()) {
debugFlake << "Starting with SVG 1.1 specific portion";
@@ -665,7 +665,7 @@ void KoSvgTextShape::Private::relayout()
debugFlake << "5. Apply ‘textLength’ attribute";
globalIndex = 0;
int resolved = 0;
- this->applyTextLength(textData.childBegin(), result, globalIndex, resolved, isHorizontal);
+ this->applyTextLength(textData.childBegin(), result, globalIndex, resolved, isHorizontal, KoSvgTextProperties::defaultProperties());
// 6. Adjust positions: x, y
debugFlake << "6. Adjust positions: x, y";
@@ -712,12 +712,12 @@ void KoSvgTextShape::Private::relayout()
isHorizontal,
direction == KoSvgText::DirectionLeftToRight,
false,
- finalRes);
+ finalRes, KoSvgTextProperties::defaultProperties());
// 8. Position on path
debugFlake << "8. Position on path";
- this->applyTextPath(textData.childBegin(), result, isHorizontal, startPos);
+ this->applyTextPath(textData.childBegin(), result, isHorizontal, startPos, KoSvgTextProperties::defaultProperties());
} else {
globalIndex = 0;
debugFlake << "Computing text-decorationsfor inline-size";
@@ -732,7 +732,7 @@ void KoSvgTextShape::Private::relayout()
isHorizontal,
direction == KoSvgText::DirectionLeftToRight,
true,
- finalRes);
+ finalRes, KoSvgTextProperties::defaultProperties());
}
// 9. return result.
@@ -825,14 +825,14 @@ void KoSvgTextShape::Private::clearAssociatedOutlines()
* @brief KoSvgTextShape::Private::resolveTransforms
* This resolves transforms and applies whitespace collapse.
*/
-void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QString text, QVector<CharacterResult> &result, int &currentIndex, bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars) {
+void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElement>::child_iterator currentTextElement, QString text, QVector<CharacterResult> &result, int &currentIndex, bool isHorizontal, bool wrapped, bool textInPath, QVector<KoSvgText::CharTransformation> &resolved, QVector<bool> collapsedChars, const KoSvgTextProperties resolvedProps) {
QVector<KoSvgText::CharTransformation> local = currentTextElement->localTransformations;
int i = 0;
int index = currentIndex;
- int j = index + numChars(currentTextElement, true);
+ int j = index + numChars(currentTextElement, true, resolvedProps);
if (currentTextElement->textPath) {
textInPath = true;
@@ -865,8 +865,10 @@ void KoSvgTextShape::Private::resolveTransforms(KisForest<KoSvgTextContentElemen
}
}
+ KoSvgTextProperties props = currentTextElement->properties;
+ props.inheritFrom(resolvedProps, true);
for (auto child = KisForestDetail::childBegin(currentTextElement); child != KisForestDetail::childEnd(currentTextElement); child++) {
- resolveTransforms(child, text, result, currentIndex, isHorizontal, false, textInPath, resolved, collapsedChars);
+ resolveTransforms(child, text, result, currentIndex, isHorizontal, false, textInPath, resolved, collapsedChars, props);
}
@@ -907,15 +909,18 @@ void KoSvgTextShape::Private::applyTextLength(KisForest<KoSvgTextContentElement>
QVector<CharacterResult> &result,
int &currentIndex,
int &resolvedDescendentNodes,
- bool isHorizontal)
+ bool isHorizontal,
+ const KoSvgTextProperties resolvedProps)
{
int i = currentIndex;
- int j = i + numChars(currentTextElement, true);
+ int j = i + numChars(currentTextElement, true, resolvedProps);
int resolvedChildren = 0;
+ KoSvgTextProperties props;
+ props.inheritFrom(resolvedProps, true);
for (auto child = KisForestDetail::childBegin(currentTextElement); child != KisForestDetail::childEnd(currentTextElement); child++) {
- applyTextLength(child, result, currentIndex, resolvedChildren, isHorizontal);
+ applyTextLength(child, result, currentIndex, resolvedChildren, isHorizontal, props);
}
// Raqm handles bidi reordering for us, but this algorithm does not
// anticipate that, so we need to keep track of which typographic item
@@ -1034,7 +1039,7 @@ void KoSvgTextShape::Private::computeFontMetrics(// NOLINT(readability-function-
const bool disableFontMatching)
{
const int i = currentIndex;
- const int j = qMin(i + numChars(parent, true), result.size());
+ const int j = qMin(i + numChars(parent, true, parentProps), result.size());
KoSvgTextProperties properties = parent->properties;
properties.inheritFrom(parentProps, true);
@@ -1139,17 +1144,19 @@ void KoSvgTextShape::Private::handleLineBoxAlignment(KisForest<KoSvgTextContentE
QVector<CharacterResult> &result,
const QVector<LineBox> lineBoxes,
int &currentIndex,
- const bool isHorizontal)
+ const bool isHorizontal,
+ const KoSvgTextProperties resolvedProps)
{
const int i = currentIndex;
- const int j = qMin(i + numChars(parent, true), result.size());
+ const int j = qMin(i + numChars(parent, true, resolvedProps), result.size());
KoSvgTextProperties properties = parent->properties;
KoSvgText::BaselineShiftMode baselineShiftMode = KoSvgText::BaselineShiftMode(properties.property(KoSvgTextProperties::BaselineShiftModeId).toInt());
+ properties.inheritFrom(resolvedProps);
for (auto child = KisForestDetail::childBegin(parent); child != KisForestDetail::childEnd(parent); child++) {
- handleLineBoxAlignment(child, result, lineBoxes, currentIndex, isHorizontal);
+ handleLineBoxAlignment(child, result, lineBoxes, currentIndex, isHorizontal, properties);
}
if (baselineShiftMode == KoSvgText::ShiftLineTop || baselineShiftMode == KoSvgText::ShiftLineBottom) {
@@ -1211,12 +1218,11 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
bool ltr,
bool wrapping,
const qreal res,
- const KoSvgText::TextDecorationUnderlinePosition underlinePosH,
- const KoSvgText::TextDecorationUnderlinePosition underlinePosV)
+ const KoSvgTextProperties resolvedProps)
{
const int i = currentIndex;
- const int j = qMin(i + numChars(currentTextElement, true), result.size());
+ const int j = qMin(i + numChars(currentTextElement, true, resolvedProps), result.size());
using namespace KoSvgText;
KoPathShape *currentTextPath = nullptr;
@@ -1235,8 +1241,10 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
}
}
}
+ KoSvgTextProperties properties = currentTextElement->properties;
+ properties.inheritFrom(resolvedProps);
- KoSvgText::TextUnderlinePosition pos = currentTextElement->properties.propertyOrDefault(KoSvgTextProperties::TextDecorationPositionId).value<KoSvgText::TextUnderlinePosition>();
+ KoSvgText::TextUnderlinePosition pos = properties.propertyOrDefault(KoSvgTextProperties::TextDecorationPositionId).value<KoSvgText::TextUnderlinePosition>();
TextDecorationUnderlinePosition newUnderlinePosH = pos.horizontalPosition;
TextDecorationUnderlinePosition newUnderlinePosV = pos.verticalPosition;
@@ -1253,13 +1261,13 @@ void KoSvgTextShape::Private::computeTextDecorations(// NOLINT(readability-funct
ltr,
wrapping,
res,
- newUnderlinePosH,
- newUnderlinePosV);
+ properties
+ );
}
TextDecorations decor = currentTextElement->properties.propertyOrDefault(KoSvgTextProperties::TextDecorationLineId).value<TextDecorations>();
if (decor != DecorationNone && currentTextElement->properties.hasProperty(KoSvgTextProperties::TextDecorationLineId)) {
- KoSvgTextProperties properties =currentTextElement->properties;
+
TextDecorationStyle style = TextDecorationStyle(
properties.propertyOrDefault(
KoSvgTextProperties::TextDecorationStyleId).toInt());
@@ -1714,7 +1722,8 @@ QPainterPath KoSvgTextShape::Private::stretchGlyphOnPath(const QPainterPath &gly
void KoSvgTextShape::Private::applyTextPath(KisForest<KoSvgTextContentElement>::child_iterator root,
QVector<CharacterResult> &result,
bool isHorizontal,
- QPointF &startPos)
+ QPointF &startPos,
+ const KoSvgTextProperties resolvedProps)
{
// Unlike all the other applying functions, this one only iterrates over the
// top-level. SVG is not designed to have nested textPaths. Source:
@@ -1724,7 +1733,7 @@ void KoSvgTextShape::Private::applyTextPath(KisForest<KoSvgTextContentElement>::
int currentIndex = 0;
QPointF pathEnd;
for (auto textShapeElement = KisForestDetail::childBegin(root); textShapeElement != KisForestDetail::childEnd(root); textShapeElement++) {
- int endIndex = currentIndex + numChars(textShapeElement, true);
+ int endIndex = currentIndex + numChars(textShapeElement, true, resolvedProps);
KoPathShape *shape = dynamic_cast<KoPathShape *>(textShapeElement->textPath.data());
if (shape) {
@@ -1848,7 +1857,7 @@ QVector<SubChunk> KoSvgTextShape::Private::collectSubChunks(KisForest<KoSvgTextC
}
chunk.originalText = it->text;
- chunk.text = it->getTransformedString(chunk.newToOldPositions);
+ chunk.text = it->getTransformedString(chunk.newToOldPositions, chunk.inheritedProps);
result.append(chunk);
if (!bidiClosing.isEmpty()) {