mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Fix drawing some SVG text elements that contain tspan elements
This commit mainly aims to fix some regressions caused by
20afcb5bf3, but it also fixes cases that
were rendered incorrectly even before.
This commit is contained in:
parent
b03a23503a
commit
ebc15c877c
1 changed files with 52 additions and 2 deletions
|
|
@ -1127,10 +1127,24 @@ private:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool getPreviousTokenEndedWithSpace() const
|
||||
{
|
||||
return previousTokenEndedWithSpace;
|
||||
}
|
||||
|
||||
void setPreviousTokenEndedWithSpace (bool endedWithSpace)
|
||||
{
|
||||
previousTokenEndedWithSpace = endedWithSpace;
|
||||
|
||||
if (parent != nullptr)
|
||||
parent->setPreviousTokenEndedWithSpace (endedWithSpace);
|
||||
}
|
||||
|
||||
private:
|
||||
StringLayoutState* parent = nullptr;
|
||||
Point<float> nextStartingPos;
|
||||
Array<float> xCoords, yCoords;
|
||||
bool previousTokenEndedWithSpace = false;
|
||||
};
|
||||
|
||||
Drawable* parseText (const XmlPath& xml, bool shouldParseTransform,
|
||||
|
|
@ -1163,11 +1177,46 @@ private:
|
|||
auto dc = new DrawableComposite();
|
||||
setCommonAttributes (*dc, xml);
|
||||
|
||||
for (auto* e : xml->getChildIterator())
|
||||
const auto children = xml->getChildIterator();
|
||||
|
||||
for (auto childIt = children.begin(); childIt != children.end(); ++childIt)
|
||||
{
|
||||
const auto firstChild = childIt == children.begin();
|
||||
const auto lastChild = std::next (childIt) == children.end();
|
||||
auto* e = *childIt;
|
||||
|
||||
if (e->isTextElement())
|
||||
{
|
||||
auto fullText = e->getText();
|
||||
auto fullText = e->getText().replace ("\r\n", " ").replace ("\n", " ");
|
||||
|
||||
if (layoutState.getPreviousTokenEndedWithSpace())
|
||||
fullText = fullText.trimStart();
|
||||
|
||||
if (xml->hasTagName ("text"))
|
||||
{
|
||||
if (firstChild)
|
||||
fullText = fullText.trimStart();
|
||||
else if (lastChild)
|
||||
fullText = fullText.trimEnd();
|
||||
}
|
||||
|
||||
const auto collapseSpaces = [] (const String& s)
|
||||
{
|
||||
auto tokens = StringArray::fromTokens (s, false);
|
||||
tokens.removeEmptyStrings();
|
||||
auto collapsed = tokens.joinIntoString (" ");
|
||||
|
||||
if (s.startsWithChar (' '))
|
||||
collapsed = " " + collapsed;
|
||||
|
||||
if (s.endsWithChar (' '))
|
||||
collapsed += " ";
|
||||
|
||||
return collapsed;
|
||||
};
|
||||
|
||||
fullText = collapseSpaces (fullText);
|
||||
layoutState.setPreviousTokenEndedWithSpace (fullText.endsWithChar (' '));
|
||||
|
||||
const auto subtextElements = [&]
|
||||
{
|
||||
|
|
@ -1189,6 +1238,7 @@ private:
|
|||
auto dt = new DrawableText();
|
||||
dc->addAndMakeVisible (dt);
|
||||
|
||||
dt->setPreserveWhitespace (true);
|
||||
dt->setText (text);
|
||||
dt->setFont (font, true);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue