Add basic <symbol> support in SVG #1819
Conversation
|
Thank you for your feedback @andersonhc ! I think I've finally solved the scaling issue with Please let me know what you think. |
| viewbox = symbol.attrib.get("viewBox") | ||
| if viewbox: | ||
| parts = viewbox.replace(",", " ").split() | ||
| if len(parts) >= 4: | ||
| setattr(group, "_vw", float(parts[2])) | ||
| setattr(group, "_vh", float(parts[3])) |
There was a problem hiding this comment.
Right now the test is failing:
@force_nodocument
def build_symbol(self, symbol: "Element") -> GraphicsContext:
"""Parse <symbol> as reusable content, not rendered directly."""
group = self.build_group(symbol)
viewbox = symbol.attrib.get("viewBox")
if viewbox:
parts = viewbox.replace(",", " ").split()
if len(parts) >= 4:
> setattr(group, "_vw", float(parts[2]))
E AttributeError: 'GraphicsContext' object has no attribute '_vw'
I don't think adding the viewbox attribute to the GraphicsContext is the best approach.
I recommend looking into using the GaphicsContext's transform to apply the viewbox.
Apply translate(-vx, -vy) @ scale(1 / vw, 1 / vh) to the symbol group should make it normalized to unit coordinates. In build_xref(), apply scale(width, height) @ translate(x, y).

Add basic support in SVG parsing
This PR adds support for SVG
<symbol>elements.Checklist:
A unit test is covering the code added / modified by this PR
In case of a new feature, docstrings have been added, with also some documentation in the
docs/folder (N/A)A mention of the change is present in
CHANGELOG.mdThis PR is ready to be merged
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.