Commit b7f2fd95 authored by Fabrice Salvaire's avatar Fabrice Salvaire

fixed SVG and path: arc, stringed and closed rectangle

parent a7b8f527
......@@ -997,11 +997,7 @@ class PathDataAttribute(StringAttribute):
i = next_i
# return commands
try:
return cls.to_geometry(commands)
except NotImplementedError:
self._logger.warning('Not Implemented Error on path')
return None
return cls.to_geometry(commands)
##############################################
......@@ -1031,11 +1027,11 @@ class PathDataAttribute(StringAttribute):
@classmethod
def to_geometry(cls, commands):
# cls._logger.debug('Path:\n' + str(commands))
cls._logger.info('Path:\n' + str(commands).replace('), ', '),\n '))
path = None
for command, args in commands:
command_lower = command.lower()
absolute = command_lower != command
absolute = command_lower != command # Upper case means absolute
# if is_lower:
# cls._logger.warning('incremental command')
# raise NotImplementedError
......@@ -1045,23 +1041,24 @@ class PathDataAttribute(StringAttribute):
# Fixme: m ???
path = Path2D(args) # Vector2D()
else:
# Fixme: incremental and (q t a) need Path support
if command_lower == 'l':
path.line_to(args, absolute=absolute)
elif command_lower == 'h':
path.horizontal_to(*args)
path.horizontal_to(*args, absolute=absolute)
elif command_lower == 'v':
path.vertical_to(*args)
path.vertical_to(*args, absolute=absolute)
elif command_lower == 'c':
path.cubic_to(*cls.as_vector(args))
path.cubic_to(*cls.as_vector(args), absolute=absolute)
elif command_lower == 's':
raise NotImplementedError
path.stringed_quadratic_to(*cls.as_vector(args), absolute=absolute)
elif command_lower == 'q':
path.quadratic_to(*cls.as_vector(args))
path.quadratic_to(*cls.as_vector(args), absolute=absolute)
elif command_lower == 't':
raise NotImplementedError
path.stringed_cubic_to(*cls.as_vector(args), absolute=absolute)
elif command_lower == 'a':
raise NotImplementedError
radius_x, radius_y, angle, large_arc, sweep, x, y = args
point = Vector2D(x, y)
path.arc_to(point, radius_x, radius_y, angle, bool(large_arc), bool(sweep), absolute=absolute)
elif command_lower == 'z':
path.close()
......@@ -1150,6 +1147,32 @@ class Rect(PositionMixin, RadiusMixin, SizeMixin, PathMixin, SvgElementMixin, Xm
__tag__ = 'rect'
##############################################
@property
def geometry(self):
# Fixme: width is str
width = float(self.width)
height = float(self.height)
# Fixme: which one ???
radius_x = self.rx
radius_y = self.ry
if radius_y == 0:
radius = None
else:
radius = radius_y
point = Vector2D(self.x, self.y)
path = Path2D(point)
path.horizontal_to(width)
path.vertical_to(height, radius=radius)
path.horizontal_to(-width, radius=radius)
path.close(radius=radius_y, close_radius=radius)
return path
####################################################################################################
class Stop(XmlObjectAdaptator):
......
This diff is collapsed.
......@@ -375,36 +375,57 @@ class GraphicSceneScope:
def add_path(self, path, path_style):
items = []
def add_bulge(segment):
arc = segment.bulge_geometry
arc_item = self.circle(
arc.center, arc.radius,
path_style,
start_angle=arc.domain.start,
stop_angle=arc.domain.stop,
user_data=segment,
)
items.append(arc_item)
def add_by_method(method, segment):
item = method(
*segment.points,
path_style,
user_data=segment,
)
items.append(item)
def add_segment(segment):
add_by_method(self.segment, segment)
def add_quadratic(segment):
add_by_method(self.quadratic_bezier, segment)
def add_cubic(segment):
add_by_method(self.cubic_bezier, segment)
for segment in path:
item = None
if isinstance(segment, Path.LinearSegment):
# if segment._start_radius is True:
# continue
if segment.radius is not None:
arc = segment.bulge_geometry
arc_item = self.circle(
arc.center, arc.radius,
path_style,
start_angle=arc.domain.start,
stop_angle=arc.domain.stop,
user_data=segment,
)
items.append(arc_item)
item = self.segment(
*segment.points,
path_style,
user_data=segment,
)
add_bulge(segment)
# if segment._closing is True:
# start_segment = path.start_segment
# add_bulge(start_segment)
# add_segment(start_segment)
add_segment(segment)
elif isinstance(segment, Path.QuadraticBezierSegment):
item = self.quadratic_bezier(
*segment.points,
path_style,
user_data=segment,
)
add_quadratic(segment)
elif isinstance(segment, Path.CubicBezierSegment):
item = self.cubic_bezier(
*segment.points,
path_style,
user_data=segment,
)
items.append(item)
add_cubic(segment)
elif isinstance(segment, Path.ArcSegment):
add_segment(segment)
elif isinstance(segment, Path.StringedQuadtraticBezierSegment):
pass
elif isinstance(segment, Path.StringedCubicBezierSegment):
pass
##############################################
......
......@@ -25,8 +25,10 @@ import logging
from pathlib import Path
# Disable if executed by patro
# from Patro.Common.Logging import Logging
# Logging.setup_logging()
use_qt = True
if not use_qt:
from Patro.Common.Logging import Logging
Logging.setup_logging()
from Patro.FileFormat.Svg import SvgFormat
from Patro.FileFormat.Svg.SvgFile import SvgFile, SvgFileInternal
......@@ -81,15 +83,15 @@ class SceneImporter(SvgFileInternal):
##############################################
def on_group(self, group):
pass
# self._logger.info('Group: {}\n{}'.format(group.id, group))
pass
##############################################
def on_graphic_item(self, item):
# self._logger.info('Item: {}\n{}'.format(item.id, item))
state = self._dispatcher.state.clone().merge(item)
self._logger.info('Item: {}\n{}'.format(item.id, item))
# self._logger.info('Item State:\n' + str(state))
self._item_counter += 1
......@@ -109,19 +111,24 @@ class SceneImporter(SvgFileInternal):
if isinstance(item, SvgFormat.Path):
# and state.stroke_dasharray is None
path = item.path_data
path = path.transform(transformation)
# Fixme:
for part in path:
self._update_bounding_box(part)
if path is not None: # Fixme:
# path = path.transform(transformation)
# Fixme:
for part in path:
self._update_bounding_box(part)
self._scene.add_path(path, path_style)
elif isinstance(item, SvgFormat.Rect):
path = item.geometry
self._scene.add_path(path, path_style)
####################################################################################################
# svg_path = find_data_path('svg', 'demo.svg')
svg_path = find_data_path('patterns-svg', 'veravenus-little-bias-dress.pattern-a0.svg')
# svg_path = find_data_path('patterns-svg', 'test.svg')
svg_path = find_data_path('svg', 'demo.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')
# svg_file = SvgFile(svg_path)
scene_importer = SceneImporter(svg_path)
application.qml_application.scene = scene_importer.scene
if use_qt:
application.qml_application.scene = scene_importer.scene
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