From 8d9b1e93fbf9a4e1c0c7ca91e5a648dd55ff672e Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Sun, 9 May 2021 16:06:23 +0300 Subject: [PATCH] Support additional offset for icon shape. --- roentgen/icon.py | 7 +++++-- roentgen/scheme.py | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/roentgen/icon.py b/roentgen/icon.py index d23ab73..e1182ff 100644 --- a/roentgen/icon.py +++ b/roentgen/icon.py @@ -40,14 +40,17 @@ class Shape: """ return self.id_ in [DEFAULT_SHAPE_ID, DEFAULT_SMALL_SHAPE_ID] - def get_path(self, svg: Drawing, point: np.array): + def get_path( + self, svg: Drawing, point: np.array, offset: np.array = np.array((0, 0)) + ): """ Draw icon into SVG file. :param svg: SVG file to draw to :param point: icon position + :param offset: additional offset """ - shift: np.array = self.offset + point + shift: np.array = self.offset + point + offset return svg.path( d=self.path, transform=f"translate({shift[0]},{shift[1]})" diff --git a/roentgen/scheme.py b/roentgen/scheme.py index 0289a1c..b714f9a 100644 --- a/roentgen/scheme.py +++ b/roentgen/scheme.py @@ -27,6 +27,7 @@ class ShapeSpecification: shape: Shape color: Color = DEFAULT_COLOR + offset: np.array = np.array((0, 0)) @classmethod def from_structure( @@ -39,6 +40,7 @@ class ShapeSpecification: shape: Shape shape, _ = extractor.get_path(DEFAULT_SHAPE_ID) color: Color = color + offset: np.array = np.array((0, 0)) if isinstance(structure, str): shape, _ = extractor.get_path(structure) elif isinstance(structure, dict): @@ -46,7 +48,9 @@ class ShapeSpecification: shape, _ = extractor.get_path(structure["shape"]) if "color" in structure: color = scheme.get_color(structure["color"]) - return cls(shape, color) + if "offset" in structure: + offset = np.array(structure["offset"]) + return cls(shape, color, offset) def is_default(self) -> bool: """ @@ -69,7 +73,7 @@ class ShapeSpecification: """ point = np.array(list(map(int, point))) - path: svgwrite.path.Path = self.shape.get_path(svg, point) + path: svgwrite.path.Path = self.shape.get_path(svg, point, self.offset) path.update({"fill": self.color.hex}) if outline: bright: bool = is_bright(self.color)