From 042f5bf57076b18d68086ebffb03f97358ee44cd Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 9 Nov 2019 12:09:03 +0100 Subject: Fix SVG 1.1 fallback for SVG 2 text in a shape with 'text-align' not equal to 'start'. --- src/extension/internal/svg.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index cee0936eb..932ece46a 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -351,7 +351,7 @@ static void remove_marker_context_paint (Inkscape::XML::Node *repr, * Notes: * Text must have been layed out. Access via old document. */ -static void insert_text_fallback( Inkscape::XML::Node *repr, SPDocument *doc, Inkscape::XML::Node *defs = nullptr ) +static void insert_text_fallback( Inkscape::XML::Node *repr, SPDocument *original_doc, Inkscape::XML::Node *defs = nullptr ) { if (repr) { @@ -360,8 +360,8 @@ static void insert_text_fallback( Inkscape::XML::Node *repr, SPDocument *doc, In auto id = repr->attribute("id"); // std::cout << "insert_text_fallback: found text! id: " << (id?id:"null") << std::endl; - // We need to get SPText object to access layout. - SPText* text = static_cast(doc->getObjectById( id )); + // We need to get original SPText object to access layout. + SPText* text = static_cast(original_doc->getObjectById( id )); if (text == nullptr) { std::cerr << "insert_text_fallback: bad cast" << std::endl; return; @@ -375,6 +375,15 @@ static void insert_text_fallback( Inkscape::XML::Node *repr, SPDocument *doc, In // We will keep this text node but replace all children. + // For text in a shape, We need to unset 'text-anchor' or SVG 1.1 fallback won't work. + // Note 'text' here refers to original document while 'repr' refers to new document copy. + if (text->has_shape_inside()) { + SPCSSAttr *css = sp_repr_css_attr(repr, "style" ); + sp_repr_css_unset_property(css, "text-anchor"); + sp_repr_css_set(repr, css, "style"); + sp_repr_css_attr_unref(css); + } + // Make a list of children to delete at end: std::vector old_children; for (auto child = repr->firstChild(); child; child = child->next()) { @@ -513,7 +522,7 @@ static void insert_text_fallback( Inkscape::XML::Node *repr, SPDocument *doc, In } for ( Node *child = repr->firstChild(); child; child = child->next() ) { - insert_text_fallback (child, doc, defs); + insert_text_fallback (child, original_doc, defs); } } } -- cgit v1.2.3