summaryrefslogtreecommitdiffstats
path: root/src/object/sp-text.cpp
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2019-03-23 11:32:10 +0000
committerTavmjong Bah <tavmjong@free.fr>2019-03-23 11:32:10 +0000
commit605ef4a43ea0cf89d19d46679e9e0b5bb9e464b2 (patch)
tree283dd62c5459007d9400dcf5195e6f68d386c82a /src/object/sp-text.cpp
parentAllow guide duplication in guides dialog (diff)
downloadinkscape-605ef4a43ea0cf89d19d46679e9e0b5bb9e464b2.tar.gz
inkscape-605ef4a43ea0cf89d19d46679e9e0b5bb9e464b2.zip
Fix text rendering when Inkscape multi-line text has an empty first line.
Possible fix for GitLab issue #45.
Diffstat (limited to 'src/object/sp-text.cpp')
-rw-r--r--src/object/sp-text.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/object/sp-text.cpp b/src/object/sp-text.cpp
index ff8bd9af7..b65170642 100644
--- a/src/object/sp-text.cpp
+++ b/src/object/sp-text.cpp
@@ -617,7 +617,7 @@ unsigned SPText::_buildLayoutInput(SPObject *object, Inkscape::Text::Layout::Opt
// we've found 'x' and 'y' and then creating the Shape at the end.)
if (is_horizontal()) {
// Horizontal text
- SVGLength* y = attributes.getFirstYLength();
+ SVGLength* y = _getFirstYLength();
if (y) {
optional_attrs.y.push_back(*y);
} else {
@@ -625,14 +625,13 @@ unsigned SPText::_buildLayoutInput(SPObject *object, Inkscape::Text::Layout::Opt
}
} else {
// Vertical text
- SVGLength* x = attributes.getFirstXLength();
+ SVGLength* x = _getFirstXLength();
if (x) {
optional_attrs.x.push_back(*x);
} else {
std::cerr << "SPText::_buildLayoutInput: No 'x' attribute value with vertical 'inline-size'!" << std::endl;
}
}
-
}
// set textLength on the entire layout, see note in TNG-Layout.h
@@ -773,6 +772,47 @@ Shape* SPText::_buildExclusionShape() const
return result;
}
+
+// SVG requires one to use the first x/y value found on a child element if x/y not given on text
+// element. TODO: Recurse.
+SVGLength*
+SPText::_getFirstXLength()
+{
+ SVGLength* x = attributes.getFirstXLength();
+
+ if (!x) {
+ for (auto& child: children) {
+ if (SP_IS_TSPAN(&child)) {
+ SPTSpan *tspan = SP_TSPAN(&child);
+ x = tspan->attributes.getFirstXLength();
+ break;
+ }
+ }
+ }
+
+ return x;
+}
+
+
+SVGLength*
+SPText::_getFirstYLength()
+{
+ SVGLength* y = attributes.getFirstYLength();
+
+ if (!y) {
+ for (auto& child: children) {
+ if (SP_IS_TSPAN(&child)) {
+ SPTSpan *tspan = SP_TSPAN(&child);
+ y = tspan->attributes.getFirstYLength();
+ break;
+ }
+ }
+ }
+
+ return y;
+}
+
+
void SPText::rebuildLayout()
{
layout.clear();