mirror of
https://github.com/enzet/map-machine.git
synced 2025-08-06 10:09:52 +02:00
Add scale to icon grid.
This commit is contained in:
parent
d812058ecb
commit
c543ddf894
2 changed files with 23 additions and 20 deletions
|
@ -279,6 +279,7 @@ class ShapeSpecification:
|
|||
tags: dict[str, Any] = None,
|
||||
outline: bool = False,
|
||||
outline_opacity: float = 1.0,
|
||||
scale: float = 1.0,
|
||||
) -> None:
|
||||
"""
|
||||
Draw icon shape into SVG file.
|
||||
|
@ -289,15 +290,18 @@ class ShapeSpecification:
|
|||
displayed, this argument should be None
|
||||
:param outline: draw outline for the shape
|
||||
:param outline_opacity: opacity of the outline
|
||||
:param scale: scale icon by the magnitude
|
||||
"""
|
||||
scale: np.ndarray = np.array((1, 1))
|
||||
scale_vector: np.ndarray = np.array((scale, scale))
|
||||
if self.flip_vertically:
|
||||
scale = np.array((1, -1))
|
||||
scale_vector = np.array((scale, -scale))
|
||||
if self.flip_horizontally:
|
||||
scale = np.array((-1, 1))
|
||||
scale_vector = np.array((-scale, scale))
|
||||
|
||||
point: np.ndarray = np.array(list(map(int, point)))
|
||||
path: SVGPath = self.shape.get_path(point, self.offset, scale)
|
||||
path: SVGPath = self.shape.get_path(
|
||||
point, self.offset * scale, scale_vector
|
||||
)
|
||||
path.update({"fill": self.color.hex})
|
||||
|
||||
if outline and self.use_outline:
|
||||
|
@ -355,6 +359,7 @@ class Icon:
|
|||
point: np.ndarray,
|
||||
tags: dict[str, Any] = None,
|
||||
outline: bool = False,
|
||||
scale: float = 1,
|
||||
) -> None:
|
||||
"""
|
||||
Draw icon to SVG.
|
||||
|
@ -369,12 +374,14 @@ class Icon:
|
|||
opacity: float = 0.7 if bright else 0.5
|
||||
outline_group: Group = Group(opacity=opacity)
|
||||
for shape_specification in self.shape_specifications:
|
||||
shape_specification.draw(outline_group, point, tags, True)
|
||||
shape_specification.draw(
|
||||
outline_group, point, tags, True, scale=scale
|
||||
)
|
||||
svg.add(outline_group)
|
||||
else:
|
||||
group: Group = Group(opacity=self.opacity)
|
||||
for shape_specification in self.shape_specifications:
|
||||
shape_specification.draw(group, point, tags)
|
||||
shape_specification.draw(group, point, tags, scale=scale)
|
||||
svg.add(group)
|
||||
|
||||
def draw_to_file(
|
||||
|
|
|
@ -9,7 +9,6 @@ from typing import Optional
|
|||
import numpy as np
|
||||
from colour import Color
|
||||
from svgwrite import Drawing
|
||||
from svgwrite.shapes import Rect
|
||||
|
||||
from map_machine.pictogram.icon import (
|
||||
Icon,
|
||||
|
@ -166,6 +165,7 @@ class IconCollection:
|
|||
columns: int = 16,
|
||||
step: float = 24,
|
||||
background_color: Color = Color("white"),
|
||||
scale: float = 1.0,
|
||||
) -> None:
|
||||
"""
|
||||
Draw icons in the form of table.
|
||||
|
@ -174,26 +174,22 @@ class IconCollection:
|
|||
:param columns: number of columns in grid
|
||||
:param step: horizontal and vertical distance between icons in grid
|
||||
:param background_color: background color
|
||||
:param scale: scale icon by the magnitude
|
||||
"""
|
||||
point: np.ndarray = np.array((step / 2, step / 2))
|
||||
width: float = step * columns
|
||||
point: np.ndarray = np.array((step / 2 * scale, step / 2 * scale))
|
||||
width: float = step * columns * scale
|
||||
|
||||
height: int = int(int(len(self.icons) / (width / step) + 1) * step)
|
||||
height: int = int(int(len(self.icons) / columns + 1) * step * scale)
|
||||
svg: Drawing = Drawing(str(file_name), (width, height))
|
||||
svg.add(svg.rect((0, 0), (width, height), fill=background_color.hex))
|
||||
|
||||
for icon in self.icons:
|
||||
icon: Icon
|
||||
rectangle: Rect = svg.rect(
|
||||
point - np.array((10, 10)), (20, 20), fill=background_color.hex
|
||||
)
|
||||
svg.add(rectangle)
|
||||
icon.draw(svg, point)
|
||||
point += np.array((step, 0))
|
||||
icon.draw(svg, point, scale=scale)
|
||||
point += np.array((step * scale, 0))
|
||||
if point[0] > width - 8:
|
||||
point[0] = step / 2
|
||||
point += np.array((0, step))
|
||||
height += step
|
||||
point[0] = step / 2 * scale
|
||||
point += np.array((0, step * scale))
|
||||
height += step * scale
|
||||
|
||||
with file_name.open("w", encoding="utf-8") as output_file:
|
||||
svg.write(output_file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue