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

Write SVG file #2

Open
paolofulgoni opened this issue Feb 10, 2020 · 6 comments
Open

Write SVG file #2

paolofulgoni opened this issue Feb 10, 2020 · 6 comments

Comments

@paolofulgoni
Copy link

I'd like to use the EquinoxLabs.SVGSharpie library to create SVG documents programmatically and save them to disk.
I'm afraid this isn't a use case that you considered. For example I couldn't find methods to write an SvgDocument to file.
Do you think that this feature could be added? Or is it out of scope?

@UkooLabs
Copy link
Owner

@paolofulgoni I’m sure it can be added, I found an issue with the rendering using image sharp (due to winding rule support). How ever this has now been fixed but not had chance to update library as of yet.

@paolofulgoni
Copy link
Author

I'm afraid my question wasn't very clear. What I'd like to do is to create the XML file, not a rendered image.

To give you a bit more context, I'm currently using another library to do that job, but unfortunately it's not fully cross-platform because of the System.Drawing dependency. Therefore some people are thinking about rewriting a part of the library, more details here: svg-net/SVG#590.
Your library caught my attention as the base NuGet package EquinoxLabs.SVGSharpie doesn't have such dependencies.

@rafntor
Copy link

rafntor commented Feb 12, 2020

@paolofulgoni Have you checked out NGraphics ?

@paolofulgoni
Copy link
Author

paolofulgoni commented Feb 12, 2020

@rafntor thanks for the suggestion! I took a quick look at it, looks interesting
Nevertheless it seems to me that SVG is just an import/export feature, whereas I need the ability to manipulate every single bit of the SVG document (e.g. element IDs, CSS classes, etc)

@rafntor
Copy link

rafntor commented Feb 13, 2020

Import/export yes, but also more - this little example creates from scratch & saves SVG (including custom 'ID')

void make_svg()
{
   var graphic = new NGraphics.Graphic(new NGraphics.Size(100));
   
   graphic.Children.Add(new NGraphics.Rectangle( // add blue rectangle
      new NGraphics.Rect(graphic.Size), NGraphics.Size.Zero, NGraphics.Pens.Black, NGraphics.Brushes.Blue));

   graphic.Children.Add(new NGraphics.Ellipse( // add yellow circle
      new NGraphics.Rect(10, 10, 30, 30), null, NGraphics.Brushes.Yellow));

   graphic.Children[0].Id = "Custom-Element-Id"; // set custom element-id

   using (var file = System.IO.File.CreateText(@"c:\temp\moon.svg"))
   {
      var writer = new NGraphics.SvgWriter(graphic, file);

      writer.Write();
   }
}

View/inspect the result in Edge gives ;
image

(Sorry team SVGSharpie @UkooLabs for 'polluting' your space, just thought the request was a good match for the lib I have looked a little bit into)

@paolofulgoni
Copy link
Author

Thanks again @rafntor, I'll take a closer look!
@UkooLabs the original request is still valid anyway ;-)

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