[Bf-extensions-cvs] [b302fdf0] master: Fix T52822: Incorrect dimensions of imported svg files

Sergey Sharybin noreply at git.blender.org
Tue Sep 19 09:53:58 CEST 2017


Commit: b302fdf053557cf6c3a8caadcd1583ae6900bc89
Author: Sergey Sharybin
Date:   Tue Sep 19 12:52:34 2017 +0500
Branches: master
https://developer.blender.org/rBAb302fdf053557cf6c3a8caadcd1583ae6900bc89

Fix T52822: Incorrect dimensions of imported svg files

Was caused by fix for T45460. Now both reports should be fixed properly.

===================================================================

M	io_curve_svg/import_svg.py

===================================================================

diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 91cff022..0dfc70a4 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -202,6 +202,7 @@ def SVGMatrixFromNode(node, context):
         return Matrix()
 
     rect = context['rect']
+    has_user_coordinate = (len(context['rects']) > 1)
 
     m = Matrix()
     x = SVGParseCoord(node.getAttribute('x') or '0', rect[0])
@@ -210,7 +211,7 @@ def SVGMatrixFromNode(node, context):
     h = SVGParseCoord(node.getAttribute('height') or str(rect[1]), rect[1])
 
     m = Matrix.Translation(Vector((x, y, 0.0)))
-    if len(context['rects']) > 1:
+    if has_user_coordinate:
         if rect[0] != 0 and rect[1] != 0:
             m = m * Matrix.Scale(w / rect[0], 4, Vector((1.0, 0.0, 0.0)))
             m = m * Matrix.Scale(h / rect[1], 4, Vector((0.0, 1.0, 0.0)))
@@ -225,9 +226,14 @@ def SVGMatrixFromNode(node, context):
         if vw == 0 or vh == 0:
             return m
 
-        sx = w / vw
-        sy = h / vh
-        scale = min(sx, sy)
+        if has_user_coordinate or (w != 0 and h != 0):
+            sx = w / vw
+            sy = h / vh
+            scale = min(sx, sy)
+        else:
+            scale = 1.0
+            w = vw
+            h = vh
 
         tx = (w - vw * scale) / 2
         ty = (h - vh * scale) / 2
@@ -1784,7 +1790,6 @@ class SVGGeometrySVG(SVGGeometryContainer):
         """
 
         rect = SVGRectFromNode(self._node, self._context)
-        self._pushRect(rect)
 
         matrix = self.getNodeMatrix()
 
@@ -1796,6 +1801,7 @@ class SVGGeometrySVG(SVGGeometryContainer):
             matrix = matrix * Matrix.Translation([0.0, -document_height , 0.0])
 
         self._pushMatrix(matrix)
+        self._pushRect(rect)
 
         super()._doCreateGeom(False)
 
@@ -1829,7 +1835,7 @@ class SVGLoader(SVGGeometryContainer):
         m = m * Matrix.Scale(1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((1.0, 0.0, 0.0)))
         m = m * Matrix.Scale(-1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((0.0, 1.0, 0.0)))
 
-        rect = (1, 1)
+        rect = (0, 0)
 
         self._context = {'defines': {},
                          'transform': [],



More information about the Bf-extensions-cvs mailing list