Skip to content

Commit

Permalink
TechDraw: SVG export refactoring - Change tspan replacement strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
pavltom authored and WandererFan committed Jun 11, 2019
1 parent 044fe79 commit dab8a3c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Mod/TechDraw/App/DrawSVGTemplate.cpp
Expand Up @@ -181,20 +181,21 @@ App::DocumentObjectExecReturn * DrawSVGTemplate::execute(void)
std::map<std::string, std::string> substitutions = EditableTexts.getValues();
while (!queryResult.next().isNull())
{
QDomElement tspanTempl = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();
QDomElement tspan = model.toDomNode(queryResult.current().toNodeModelIndex()).toElement();

// Replace the editable text spans with new nodes holding actual values
std::map<std::string, std::string>::iterator item =
substitutions.find(tspanTempl.parentNode().toElement()
substitutions.find(tspan.parentNode().toElement()
.attribute(QString::fromUtf8("freecad:editable")).toStdString());
if (item != substitutions.end()) {
QDomElement tspanActual = templateDocument.createElement(QString::fromUtf8("tspan"));
tspanActual.appendChild(templateDocument.createTextNode(QString::fromUtf8(item->second.c_str())));

// Keep all spaces in the text node
tspanActual.setAttribute(QString::fromUtf8("xml:space"), QString::fromUtf8("preserve"));
tspan.setAttribute(QString::fromUtf8("xml:space"), QString::fromUtf8("preserve"));

tspanTempl.parentNode().replaceChild(tspanActual, tspanTempl);
// Remove all child nodes and append text node with editable replacement as the only descendant
while (!tspan.lastChild().isNull()) {
tspan.removeChild(tspan.lastChild());
}
tspan.appendChild(templateDocument.createTextNode(QString::fromUtf8(item->second.c_str())));
}
}

Expand Down

0 comments on commit dab8a3c

Please sign in to comment.