Commit 4fec6da5 authored by Fabrice Salvaire's avatar Fabrice Salvaire

SVG: fixed transformation composition

parent eb2bf7f4
......@@ -117,7 +117,9 @@ class RenderState:
value = getattr(item, state)
if state == 'transform':
if value is not None:
self.transform = value * self.transform
# Transform matrix is composed from top to item
# thus left to right
self.transform = self.transform * value
elif state == 'style':
pass
else:
......@@ -130,7 +132,7 @@ class RenderState:
state, value = [x.strip() for x in pair.split(':')]
state = state.replace('-', '_')
if state == 'transform':
self.transform = value * self.transform
self.transform = self.transform * value
else:
setattr(self, state, self.to_python(value))
......
......@@ -180,6 +180,8 @@ class Transformation:
def __mul__(self, obj):
"""Return self * obj composition."""
if isinstance(obj, Transformation):
# T = T1 * T2
array = np.matmul(self._m, obj.array)
......@@ -202,6 +204,10 @@ class Transformation:
def __imul__(self, obj):
"""Set transformation to obj * self composition."""
# Fixme: order ???
if isinstance(obj, Transformation):
if obj.type != TransformationType.Identity:
# (T = T1) *= T2
......
......@@ -104,6 +104,11 @@ class SceneImporter(SvgFileInternal):
# 'path12085',
# ):
# return
# if item.id not in (
# 'rounded-rectangle',
# 'polygon',
# ):
# return
# from Patro.FileFormat.Svg.SvgFormat import PathDataAttribute
# self._logger.info(str(item.id) + '\n' + str(item.path_data))
# item.path_data = PathDataAttribute.to_geometry(item.path_data)
......@@ -126,6 +131,7 @@ class SceneImporter(SvgFileInternal):
)
transformation = self._screen_transformation * state.transform
# transformation = state.transform
self._logger.info('Sate Transform\n' + str(transformation))
if isinstance(item, SvgFormat.Path):
# and state.stroke_dasharray is None
......@@ -133,19 +139,20 @@ class SceneImporter(SvgFileInternal):
if path is not None: # Fixme:
# self._logger.info(str(item.id) + '\n' + str(path[0].geometry))
path = path.transform(transformation)
for part in path:
self._update_bounding_box(part)
# self._logger.info(str(item.id) + '\n' + str(path[0].geometry))
self._update_bounding_box(path)
# self._logger.info('after ' + str(item.id) + '\n' + str(path[0].geometry))
self._scene.add_path(path, path_style)
elif isinstance(item, SvgFormat.Rect):
path = item.geometry
path = path.transform(transformation)
self._update_bounding_box(path)
self._scene.add_path(path, path_style)
####################################################################################################
# svg_path = find_data_path('svg', 'basic-demo-2.by-hand.svg')
svg_path = find_data_path('svg', 'demo.svg')
# svg_path = find_data_path('svg', 'demo.simple.svg')
# svg_path = find_data_path('patterns-svg', 'veravenus-little-bias-dress.pattern-a0.svg')
# svg_path = find_data_path('patterns-svg', 'veravenus-little-bias-dress.pattern-a0.no-text-zaggy.svg')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment