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

Styles in the style tag instead of as attributes on the tags? #24

Closed
PeteMichaud opened this issue Mar 13, 2022 · 4 comments
Closed

Styles in the style tag instead of as attributes on the tags? #24

PeteMichaud opened this issue Mar 13, 2022 · 4 comments

Comments

@PeteMichaud
Copy link

Hey Giorgio, nice work on the library!

I'm experimenting with using your library to handle widget rendering in my Map Projection software and one feature I'd like is the ability to have all the style information output as css in the style tag, rather than as attributes on the various paths.

My use case involves passing the svg file to the user for further editing, and all the styles for every line will be identical, so for file size and ease of editing, I'd like to consolidate the style information.

Does VectSharp already support such a thing, or is it something you're interested in adding?

@arklumpus
Copy link
Owner

Hi! Sorry for the delay.

Unfortuately, VectSharp.SVG currently does not support this; I can think about it, but I have no idea when/if I will be able to implement it.

In the meantime, if you know (or have a way of knowing) the attributes that are the same for all objects, maybe you could "post-process" the SVG code, e.g. by replacing stroke="#000000" stroke-opacity="1" stroke-width="2" stroke-linecap="butt" stroke-linejoin="miter" fill="none" transform="matrix(1,0,0,1,0,0)" with class="myClass" or something like this?

@AlexanderMagdysyuk
Copy link

AFAIK XML can be compressed: https://github.com/managed-commons/SvgNet/blob/70658aa68592125d95b4cd602df23efe1fd827d9/SvgNet/SvgFactory.cs - see method CompressXML (line 99).

@arklumpus
Copy link
Owner

From what I understand, that code uses XML entities to compress the attributes; this is not really necessary for an SVG document, because you can just use CSS classes.

I just released VectSharp.SVG version 1.7.0, which adds an optional useStyles parameter to the SaveAsSVG extension methods. The default value (false) results in the usual behaviour (SVG presentation attributes as individual attributes on the SVG elements), but if you set this to true, CSS classes will be used instead. Classes are reused if possible, but only if multiple elements have exactly the same style (e.g., stroke colour, stroke thickness, etc.).

Hopefully this will be helpful with your use case!

@arklumpus
Copy link
Owner

I'm closing this for now, feel free to reopen or to create another issue if you have any problems!

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