diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-03-23 11:32:10 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-03-23 11:32:10 +0000 |
| commit | 605ef4a43ea0cf89d19d46679e9e0b5bb9e464b2 (patch) | |
| tree | 283dd62c5459007d9400dcf5195e6f68d386c82a /src/object/sp-text.cpp | |
| parent | Allow guide duplication in guides dialog (diff) | |
| download | inkscape-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.cpp | 46 |
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(); |
