Skip to content

ofxSvg::fixSvgString(): addition to xml preprocessor#7679

Merged
ofTheo merged 2 commits intoopenframeworks:masterfrom
artificiel:svg-geom
Sep 28, 2023
Merged

ofxSvg::fixSvgString(): addition to xml preprocessor#7679
ofTheo merged 2 commits intoopenframeworks:masterfrom
artificiel:svg-geom

Conversation

@artificiel
Copy link
Copy Markdown
Contributor

@artificiel artificiel commented Sep 26, 2023

Affinity designer exports "flattened" SVG like this:

<svg width="100%" height="100%" viewBox="0 0 1920 1080" 
version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">

this % approach throws of svgtiny and it generates all vertices at (0, 0).

as a reference, the tiger.svg:

<svg version="1.2" baseProfile="tiny" id="svg2" xmlns:svg="http://www.w3.org/2000/svg"
    xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
    x="0px" y="0px" width="900px" height="900px"
    viewBox="0 0 900 900" overflow="inherit" xml:space="preserve">

the proposed addition "fixes" this by: (1) checking if a viewBox is defined and (2) checking if width and height are set to 100%. if so, it replaces the 100%'s with the viewBox corresponding values.

(in other words, it should not be a breaking change as an SVG that has width/height defined as values with not be affected, and an SVG without them (or as %) would not work).

It emits warning when operating.

it also makes fixSvgString() static and public, this is to allow it's use outside of an instance, making it possible to slip into a preprocessing step in ofxSvgLoader(). (note that the method was already processing an inout string reference without accessing any member variables, so was not and instance method per se).

@ofTheo ofTheo merged commit cb9281f into openframeworks:master Sep 28, 2023
@artificiel artificiel deleted the svg-geom branch September 28, 2023 02:11
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

Successfully merging this pull request may close these issues.

2 participants