Support additional offset for icon shape.

This commit is contained in:
Sergey Vartanov 2021-05-09 16:06:23 +03:00
parent f371e5bd39
commit 8d9b1e93fb
2 changed files with 11 additions and 4 deletions

View file

@ -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]})"

View file

@ -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)