[Bf-extensions-cvs] [539e2404] master: SVG Import: Fix offset while import SVG files

Michael Soluyanov noreply at git.blender.org
Wed Sep 11 12:41:36 CEST 2019

Commit: 539e24046e61bb3468ac70c660cebe5315d154a3
Author: Michael Soluyanov
Date:   Wed Sep 11 12:30:21 2019 +0200
Branches: master

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:


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


M	io_curve_svg/import_svg.py


diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 7079d3f9..9bc48a21 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -1816,12 +1816,10 @@ class SVGGeometrySVG(SVGGeometryContainer):
         matrix = self.getNodeMatrix()
-        # Better Inkscape compatibility: match document origin with
-        # 3D space origin.
-        if self._node.getAttribute('inkscape:version'):
-            raw_height = self._node.getAttribute('height')
-            document_height = SVGParseCoord(raw_height, 1.0)
-            matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0])
+        # match document origin with 3D space origin.
+        if self._node.getAttribute('viewBox'):
+            viewbox = parse_array_of_floats(self._node.getAttribute('viewBox'))
+            matrix = matrix @ matrix.Translation([0.0, - viewbox[1] - viewbox[3], 0.0])

More information about the Bf-extensions-cvs mailing list