Skip to content
Snippets Groups Projects
Commit 539e2404 authored by Michael Soluyanov's avatar Michael Soluyanov Committed by Antonio Vazquez
Browse files

SVG Import: Fix offset while import SVG files

The file saved as Inkscape SVG moved to the top, regular SVG stays in place. Blender checks if SVG have an special attribute  `inkscape:version`, and if it has one, it move all SVG to the top. The idea is to match bottom right corner with world origin, instead top right corner:

But why height is not equal the real height of the SVG?  Well, because it's not a height of SVG itself, it is size of SVG on printing or displaying in web-page or in previewer. The real height of SVG in SVG-units is located in viewbox attribute:

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox

So I suggest to move SVG content to real height of SVG located in viewbox attribute:

Reviewers: sergey, antoniov

Reviewed By: antoniov

Subscribers: meta-androcto, antoniov, jms, sergey

Tags: #add-ons

Differential Revision: https://developer.blender.org/D5727
parent 0f5738d9
No related branches found
No related tags found
No related merge requests found
...@@ -1816,12 +1816,10 @@ class SVGGeometrySVG(SVGGeometryContainer): ...@@ -1816,12 +1816,10 @@ class SVGGeometrySVG(SVGGeometryContainer):
matrix = self.getNodeMatrix() matrix = self.getNodeMatrix()
# Better Inkscape compatibility: match document origin with # match document origin with 3D space origin.
# 3D space origin. if self._node.getAttribute('viewBox'):
if self._node.getAttribute('inkscape:version'): viewbox = parse_array_of_floats(self._node.getAttribute('viewBox'))
raw_height = self._node.getAttribute('height') matrix = matrix @ matrix.Translation([0.0, - viewbox[1] - viewbox[3], 0.0])
document_height = SVGParseCoord(raw_height, 1.0)
matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0])
self._pushMatrix(matrix) self._pushMatrix(matrix)
self._pushRect(rect) self._pushRect(rect)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment