[Bf-extensions-cvs] [8db12f14] master: SVG Import: Match SVG-document units with Blender units:

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


Commit: 8db12f14561cf8bb123f7933738d5e62d1c50850
Author: Michael Soluyanov
Date:   Wed Sep 11 12:38:09 2019 +0200
Branches: master
https://developer.blender.org/rBA8db12f14561cf8bb123f7933738d5e62d1c50850

SVG Import: Match SVG-document units with Blender units:

Differential Revision: https://developer.blender.org/D4319

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

M	io_curve_svg/import_svg.py

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

diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 9bc48a21..57d0c70f 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -1816,6 +1816,35 @@ class SVGGeometrySVG(SVGGeometryContainer):
 
         matrix = self.getNodeMatrix()
 
+        # Better SVG compatibility: match svg-document units
+        # with blender units    
+       
+        viewbox = []
+        unit = ''
+         
+        if self._node.getAttribute('height'):
+            raw_height = self._node.getAttribute('height')
+            token, last_char = SVGParseFloat(raw_height)
+            document_height = float(token)
+            unit = raw_height[last_char:].strip() 
+       
+        if self._node.getAttribute('viewBox'):
+            viewbox = parse_array_of_floats(self._node.getAttribute('viewBox'))
+            
+        if len(viewbox) == 4 and unit in ('cm', 'mm', 'in', 'pt', 'pc'):
+
+            #one unit equals whis svg units:
+            unitscale = document_height / (viewbox[3] - viewbox[1])
+            
+            #convert units to BU: 
+            unitscale = unitscale * SVGUnits[unit] / 90 * 1000 / 39.3701 
+            
+            #apply blender unit scale: 
+            unitscale = unitscale / bpy.context.scene.unit_settings.scale_length
+        
+            matrix = matrix @ Matrix.Scale(unitscale, 4, Vector((1.0, 0.0, 0.0)))
+            matrix = matrix @ Matrix.Scale(unitscale, 4, Vector((0.0, 1.0, 0.0)))    
+
         # match document origin with 3D space origin.
         if self._node.getAttribute('viewBox'):
             viewbox = parse_array_of_floats(self._node.getAttribute('viewBox'))



More information about the Bf-extensions-cvs mailing list