Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change text of SvgTextSpan before Render fails #125

Closed
ravjak opened this issue Feb 3, 2015 · 3 comments
Closed

Change text of SvgTextSpan before Render fails #125

ravjak opened this issue Feb 3, 2015 · 3 comments

Comments

@ravjak
Copy link

ravjak commented Feb 3, 2015

Hi,
Has anyone tried to change text of SvgTextSpan dynamically? I'm using SvgViewer App as a test field. In open_Click function I add a search code for a uniq id and try replace it with some magic string "mariola"

SvgDocument svgDoc = SvgDocument.Open(openSvgFile.FileName);
SvgTextSpan tspan = svgDoc.GetElementById<SvgTextSpan>("tspan9936-4");
if (tspan != null)
{
    tspan.Text = "mariola";
}
RenderSvg(svgDoc);

I saw text change in debugger but it renders text previously read in open function.
I know that it is possible to parse svg as xml, change some values in it and use SvgDocument::Open(Stream stream). But this does not seems to be an elegant way.

@ravjak
Copy link
Author

ravjak commented Feb 7, 2015

I have found the problem in SvgTextBase::Text setter. I had to add code for setting it's content for all content nodes. I do not know if this is good solution but it works in my case.

public virtual string Text
{
    get {return base.Content;}
    set
    {           
        foreach (SvgContentNode node in this.GetContentNodes())
        {
            if (node.Content == this.Content)
                node.Content = value;
        }
        base.Content = value; this.IsPathDirty = true; this.Content = value;
    }
}

@avogelba
Copy link
Contributor

avogelba commented Nov 16, 2016

with ravjak suggestion this I get Exception:

Unable to cast object of type 'Svg.SvgTextSpan' to type 'Svg.SvgContentNode'.

@mrbean-bremen
Copy link
Member

Looks like that has been fixed with #262 - closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants