mirror of
https://github.com/enzet/map-machine.git
synced 2025-08-06 10:09:52 +02:00
Close #38: fix icon outline drawing.
This commit is contained in:
parent
22e6c07526
commit
437b4e8cd9
1 changed files with 14 additions and 8 deletions
|
@ -12,6 +12,7 @@ import numpy as np
|
||||||
import svgwrite
|
import svgwrite
|
||||||
from colour import Color
|
from colour import Color
|
||||||
from svgwrite import Drawing
|
from svgwrite import Drawing
|
||||||
|
from svgwrite.container import Group
|
||||||
from svgwrite.path import Path as SvgPath
|
from svgwrite.path import Path as SvgPath
|
||||||
|
|
||||||
from roentgen.color import is_bright
|
from roentgen.color import is_bright
|
||||||
|
@ -88,7 +89,6 @@ class Shape:
|
||||||
|
|
||||||
def get_path(
|
def get_path(
|
||||||
self,
|
self,
|
||||||
svg: Drawing,
|
|
||||||
point: np.array,
|
point: np.array,
|
||||||
offset: np.array = np.array((0, 0)),
|
offset: np.array = np.array((0, 0)),
|
||||||
scale: np.array = np.array((1, 1)),
|
scale: np.array = np.array((1, 1)),
|
||||||
|
@ -111,7 +111,7 @@ class Shape:
|
||||||
|
|
||||||
transformations.append(f"translate({self.offset[0]},{self.offset[1]})")
|
transformations.append(f"translate({self.offset[0]},{self.offset[1]})")
|
||||||
|
|
||||||
return svg.path(d=self.path, transform=" ".join(transformations))
|
return svgwrite.path.Path(d=self.path, transform=" ".join(transformations))
|
||||||
|
|
||||||
|
|
||||||
class ShapeExtractor:
|
class ShapeExtractor:
|
||||||
|
@ -265,7 +265,7 @@ class ShapeSpecification:
|
||||||
|
|
||||||
def draw(
|
def draw(
|
||||||
self,
|
self,
|
||||||
svg: svgwrite.Drawing,
|
svg,
|
||||||
point: np.array,
|
point: np.array,
|
||||||
tags: Dict[str, Any] = None,
|
tags: Dict[str, Any] = None,
|
||||||
outline: bool = False,
|
outline: bool = False,
|
||||||
|
@ -285,20 +285,18 @@ class ShapeSpecification:
|
||||||
scale = np.array((-1, 1))
|
scale = np.array((-1, 1))
|
||||||
|
|
||||||
point = np.array(list(map(int, point)))
|
point = np.array(list(map(int, point)))
|
||||||
path = self.shape.get_path(svg, point, self.offset, scale)
|
path = self.shape.get_path(point, self.offset, scale)
|
||||||
path.update({"fill": self.color.hex})
|
path.update({"fill": self.color.hex})
|
||||||
|
|
||||||
if outline and self.use_outline:
|
if outline and self.use_outline:
|
||||||
bright: bool = is_bright(self.color)
|
bright: bool = is_bright(self.color)
|
||||||
color: Color = Color("black") if bright else Color("white")
|
color: Color = Color("black") if bright else Color("white")
|
||||||
opacity: float = 0.7 if bright else 0.5
|
|
||||||
|
|
||||||
style: Dict[str, Any] = {
|
style: Dict[str, Any] = {
|
||||||
"fill": color.hex,
|
"fill": color.hex,
|
||||||
"stroke": color.hex,
|
"stroke": color.hex,
|
||||||
"stroke-width": 2.2,
|
"stroke-width": 2.2,
|
||||||
"stroke-linejoin": "round",
|
"stroke-linejoin": "round",
|
||||||
"opacity": opacity,
|
|
||||||
}
|
}
|
||||||
path.update(style)
|
path.update(style)
|
||||||
if tags:
|
if tags:
|
||||||
|
@ -356,8 +354,16 @@ class Icon:
|
||||||
:param tags: tags to be displayed as hint
|
:param tags: tags to be displayed as hint
|
||||||
:param outline: draw outline for the icon
|
:param outline: draw outline for the icon
|
||||||
"""
|
"""
|
||||||
for shape_specification in self.shape_specifications:
|
bright: bool = is_bright(self.shape_specifications[0].color)
|
||||||
shape_specification.draw(svg, point, tags, outline)
|
opacity: float = 0.7 if bright else 0.5
|
||||||
|
if outline:
|
||||||
|
outline_group: Group = Group(opacity=opacity)
|
||||||
|
for shape_specification in self.shape_specifications:
|
||||||
|
shape_specification.draw(outline_group, point, tags, True)
|
||||||
|
svg.add(outline_group)
|
||||||
|
else:
|
||||||
|
for shape_specification in self.shape_specifications:
|
||||||
|
shape_specification.draw(svg, point, tags)
|
||||||
|
|
||||||
def draw_to_file(self, file_name: Path):
|
def draw_to_file(self, file_name: Path):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue