mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-05 12:21:54 +02:00
Add standard SVG object ID checking.
This commit is contained in:
parent
555285da85
commit
ef921370fa
2 changed files with 32 additions and 15 deletions
|
@ -148,8 +148,8 @@
|
||||||
showgrid="true"
|
showgrid="true"
|
||||||
inkscape:document-units="px"
|
inkscape:document-units="px"
|
||||||
inkscape:current-layer="layer1"
|
inkscape:current-layer="layer1"
|
||||||
inkscape:cy="134.56631"
|
inkscape:cy="141.63738"
|
||||||
inkscape:cx="310.63103"
|
inkscape:cx="360.12851"
|
||||||
inkscape:zoom="11.313708"
|
inkscape:zoom="11.313708"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:pageopacity="0.0"
|
inkscape:pageopacity="0.0"
|
||||||
|
@ -543,6 +543,16 @@
|
||||||
inkscape:label="main"
|
inkscape:label="main"
|
||||||
id="layer1"
|
id="layer1"
|
||||||
style="display:inline">
|
style="display:inline">
|
||||||
|
<path
|
||||||
|
style="opacity:1;fill:none;fill-opacity:1;stroke:#cccccc;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||||
|
d="m 289.5,451.5 6,-2 6,2 z"
|
||||||
|
id="path6939"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path6941"
|
||||||
|
d="m 305.5,451.5 6,-2 6,2 z"
|
||||||
|
style="opacity:1;fill:none;fill-opacity:1;stroke:#cccccc;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
||||||
<path
|
<path
|
||||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:#cccccc;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
style="opacity:1;fill:#000000;fill-opacity:1;stroke:#cccccc;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||||
d="m 227.5,425.5 1,5"
|
d="m 227.5,425.5 1,5"
|
||||||
|
@ -14888,16 +14898,6 @@
|
||||||
<title
|
<title
|
||||||
id="title6917">pergola</title>
|
id="title6917">pergola</title>
|
||||||
</path>
|
</path>
|
||||||
<path
|
|
||||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
|
||||||
d="m 289.5,451.5 6,-2 6,2 z"
|
|
||||||
id="path6939"
|
|
||||||
inkscape:connector-curvature="0" />
|
|
||||||
<path
|
|
||||||
inkscape:connector-curvature="0"
|
|
||||||
id="path6941"
|
|
||||||
d="m 305.5,451.5 6,-2 6,2 z"
|
|
||||||
style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
|
|
||||||
<path
|
<path
|
||||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||||
d="m 311.51172,465 c -0.0577,-0.001 -0.11517,0.007 -0.16992,0.0254 l -6,2 c -0.20422,0.0681 -0.34191,0.25932 -0.3418,0.47461 -2.1e-4,0.008 -2.1e-4,0.0169 0,0.0254 l 0,1.47461 1,0 0,-1 11,0 0,1 1,0 0,-1.46484 c 0.016,-0.22808 -0.12472,-0.43797 -0.3418,-0.50977 l -6,-2 c -0.0473,-0.0157 -0.0967,-0.0243 -0.14648,-0.0254 z"
|
d="m 311.51172,465 c -0.0577,-0.001 -0.11517,0.007 -0.16992,0.0254 l -6,2 c -0.20422,0.0681 -0.34191,0.25932 -0.3418,0.47461 -2.1e-4,0.008 -2.1e-4,0.0169 0,0.0254 l 0,1.47461 1,0 0,-1 11,0 0,1 1,0 0,-1.46484 c 0.016,-0.22808 -0.12472,-0.43797 -0.3418,-0.50977 l -6,-2 c -0.0473,-0.0157 -0.0967,-0.0243 -0.14648,-0.0254 z"
|
||||||
|
|
Before Width: | Height: | Size: 823 KiB After Width: | Height: | Size: 823 KiB |
|
@ -82,6 +82,17 @@ class Icon:
|
||||||
svg.add(path)
|
svg.add(path)
|
||||||
|
|
||||||
|
|
||||||
|
def is_standard(id_: str):
|
||||||
|
""" Check whether SVG object ID is standard Inkscape ID. """
|
||||||
|
if id_ == "base":
|
||||||
|
return True
|
||||||
|
for prefix in ["path", "circle", "rect", "defs", "use", "metadata"]:
|
||||||
|
matcher = re.match(prefix + "\\d+", id_)
|
||||||
|
if matcher:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class IconExtractor:
|
class IconExtractor:
|
||||||
"""
|
"""
|
||||||
Extract icons from SVG file.
|
Extract icons from SVG file.
|
||||||
|
@ -116,9 +127,14 @@ class IconExtractor:
|
||||||
self.parse(sub_node)
|
self.parse(sub_node)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (node.hasAttribute("id") and node.hasAttribute("d") and
|
if not node.hasAttribute("id") or not node.getAttribute("id"):
|
||||||
node.getAttribute("id")):
|
return
|
||||||
|
|
||||||
|
id_: str = node.getAttribute("id")
|
||||||
|
if is_standard(id_):
|
||||||
|
return
|
||||||
|
|
||||||
|
if node.hasAttribute("d"):
|
||||||
path: str = node.getAttribute("d")
|
path: str = node.getAttribute("d")
|
||||||
matcher = re.match("[Mm] ([0-9.e-]*)[, ]([0-9.e-]*)", path)
|
matcher = re.match("[Mm] ([0-9.e-]*)[, ]([0-9.e-]*)", path)
|
||||||
if not matcher:
|
if not matcher:
|
||||||
|
@ -139,10 +155,11 @@ class IconExtractor:
|
||||||
name = child_node.childNodes[0].nodeValue
|
name = child_node.childNodes[0].nodeValue
|
||||||
break
|
break
|
||||||
|
|
||||||
id_: str = node.getAttribute("id")
|
|
||||||
matcher = re.match(STANDARD_INKSCAPE_ID, id_)
|
matcher = re.match(STANDARD_INKSCAPE_ID, id_)
|
||||||
if not matcher:
|
if not matcher:
|
||||||
self.icons[id_] = Icon(path, point, id_, name)
|
self.icons[id_] = Icon(path, point, id_, name)
|
||||||
|
else:
|
||||||
|
ui.error(f"not standard ID {id_}")
|
||||||
|
|
||||||
def get_path(self, id_: str) -> (Icon, bool):
|
def get_path(self, id_: str) -> (Icon, bool):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue