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

Unable to access references defined after an element #115

Open
bsweeney opened this issue Feb 10, 2024 · 0 comments
Open

Unable to access references defined after an element #115

bsweeney opened this issue Feb 10, 2024 · 0 comments
Milestone

Comments

@bsweeney
Copy link
Member

SvgLib operates as a stream processor, rendering elements as they are encountered. This means that a reference element (e.g., defs) and styling must occur in the document prior to any other elements. Otherwise, the reference element or styling will not yet be available.

For example, the following SVG document:

<svg width="600" height="600" xmlns="http://www.w3.org/2000/svg">
    <rect width="400" height="400" x="100" y="100" />
    <style>
        rect { stroke: blue; stroke-width: 20px; fill: orange; }
    </style>
</svg>

should produce the following output:

image

but SvgLib renders the following:

image

Switching the order of elements in the SVG produces the correct output:

<svg width="600" height="600" xmlns="http://www.w3.org/2000/svg">
    <style>
        rect { stroke: blue; stroke-width: 20px; fill: orange; }
    </style>
    <rect width="400" height="400" x="100" y="100" />
</svg>
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

1 participant