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

Update / rewrite of the ofxSvg addon to remove dependency on libTinySvg and libxml2. #8266

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

NickHardeman
Copy link
Contributor

@NickHardeman NickHardeman commented Feb 15, 2025

Proposing this update to ofxSvg with the following implementation based on my ofx::svg::Parser addon (https://github.com/NickHardeman/ofxSvgParser).
This rewrite adds the following functionality:

  • Loading of elements with search functionality

  • Remove libtinysvg and libxml2 dependencies. The parsing is happening in the ofxSvg class ( it took a while getting through the spec on paths :0 and parsing/writing CSS manually ;) )

  • Add elements to the document

  • Save the document after loading or adding / removing elements.

  • Works with the current ofxSvg example.

Grab a group by passing in the name of the group.
auto logoGroup = svg.get("logo");

Grab nested groups by passing in the hierarchy to the group separated by colons.
auto cloudGroup = svg.get("sky:clouds");

Get all of the elements of a certain type by calling getElementsForType
vector< shared_ptr > trees = svg.getElementsForType("trees");

Currently supports the following types:
Group, Rectangle, Image, Ellipse, Circle, Path, Polygon and Line

Limited Parsing Support ( no adding or saving currently ):
Text

We have been using some version of this for parsing svg in our projects for the last several years. The adding and saving of svgs is not well tested at the moment.

TODO:

  • Update scripts to remove libsvgtiny and libxml2
  • Add example for creating a svg document, adding items to it and saving.
  • Implement same constructors as previous ofxSvg ( copy and with default file path string ).
  • Complete in-line documentation.
  • Fix failed builds on certain platforms.
  • Discuss use of ofx::svg for subsequent classes, ofx::svg::Group vs. ofxSvgGroup.

@NickHardeman NickHardeman self-assigned this Feb 15, 2025
@NickHardeman
Copy link
Contributor Author

This issue on windows might make the argument for ofxSvgEllipse instead of ofx::svg::Ellipse

../../../addons/ofxSvg/src/ofxSvg.cpp:1988:17: error: reference to 'Ellipse' is ambiguous
   1988 | std::shared_ptr<Ellipse> ofxSvg::addEllipse( const glm::vec3& apos, float aradiusX, float aradiusY ) {
        |                 ^
  D:/a/_temp/msys64/clang64/include/wingdi.h:3009:28: note: candidate found by name lookup is 'Ellipse'
   3009 |   WINGDIAPI WINBOOL WINAPI Ellipse(HDC hdc,int left,int top,int right,int bottom);

@dimitre
Copy link
Member

dimitre commented Feb 15, 2025

Fantastic @NickHardeman let me know when it is ready to test and I can test with a lot of SVGs from previous projects here

@NickHardeman
Copy link
Contributor Author

Fantastic @NickHardeman let me know when it is ready to test and I can test with a lot of SVGs from previous projects here

Great, will do. I can also send a test app that loads an svg from a folder, saves it and reloads the saved one. Arrow keys to change index and load again in the directory.

@NickHardeman
Copy link
Contributor Author

@dimitre I think it's ready for some testing now that it's passed the checks. Attached is a quick app for testing loading, saving and loading the saved svgs. The svgs in the folder are from https://www.svgviewer.dev and are just for testing complex paths.
SvgTester.zip

@dimitre
Copy link
Member

dimitre commented Feb 21, 2025

Great I've just seen now and tested some things. I'm testing with a very crude set of svgs and will report some things.
sharing the files here if you want to check
svgs.zip

@dimitre
Copy link
Member

dimitre commented Feb 21, 2025

Most of the things work great for reading and rewriting.
I've noticed in art made with lines only, contours are thicker than the macos quickLook preview
and open outlines appear as closed.
Novapadrao6
Anitta2

@NickHardeman
Copy link
Contributor Author

@dimitre thank you for trying it out. I have fixed some of the fill issues that you mentioned.

@NickHardeman
Copy link
Contributor Author

I think the line width is due to the ofScale I am applying in the example to get the entire svg to fit within the window. When I remove the scaling, here is a comparison between OF and osx quicklook preview. The preview is on top and the OF app is in the bg.

image

@NickHardeman
Copy link
Contributor Author

Lines are scaled with attenuation by the very hidden function

auto rend = std::dynamic_pointer_cast<ofGLProgrammableRenderer>( ofGetCurrentRenderer() );
rend->enableLineSizeAttenuation();

Screenshot 2025-02-21 at 10 27 53 PM

Default screen space lines:
Screenshot 2025-02-21 at 10 28 15 PM

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

Successfully merging this pull request may close these issues.

2 participants