mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Fix issue with some SVG symbols that could not be used in GNS3.
This was due to the height and width values being percentages.
This commit is contained in:
parent
19c5ff8521
commit
fd5df0052a
@ -239,6 +239,7 @@ class Node:
|
|||||||
|
|
||||||
@symbol.setter
|
@symbol.setter
|
||||||
def symbol(self, val):
|
def symbol(self, val):
|
||||||
|
|
||||||
if val is None:
|
if val is None:
|
||||||
val = ":/symbols/computer.svg"
|
val = ":/symbols/computer.svg"
|
||||||
|
|
||||||
@ -252,8 +253,9 @@ class Node:
|
|||||||
self._symbol = val
|
self._symbol = val
|
||||||
try:
|
try:
|
||||||
self._width, self._height, filetype = self._project.controller.symbols.get_size(val)
|
self._width, self._height, filetype = self._project.controller.symbols.get_size(val)
|
||||||
# If symbol is invalid we replace it by default
|
except (ValueError, OSError) as e:
|
||||||
except (ValueError, OSError):
|
log.error("Could not write symbol: {}".format(e))
|
||||||
|
# If symbol is invalid we replace it by the default
|
||||||
self.symbol = ":/symbols/computer.svg"
|
self.symbol = ":/symbols/computer.svg"
|
||||||
if self._label is None:
|
if self._label is None:
|
||||||
# Apply to label user style or default
|
# Apply to label user style or default
|
||||||
|
@ -103,10 +103,16 @@ def get_size(data, default_width=0, default_height=0):
|
|||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
width = _svg_convert_size(root.attrib.get("width", "0"))
|
width_attr = root.attrib.get("width", "0")
|
||||||
height = _svg_convert_size(root.attrib.get("height", "0"))
|
height_attr = root.attrib.get("height", "0")
|
||||||
except IndexError:
|
if width_attr.endswith("%") or height_attr.endswith("%"):
|
||||||
raise ValueError("Invalid SVG file")
|
# check to viewBox attribute if width or height value is a percentage
|
||||||
|
_, _, width_attr, height_attr = root.attrib.get("viewBox").split()
|
||||||
|
else:
|
||||||
|
width = _svg_convert_size(width_attr)
|
||||||
|
height = _svg_convert_size(height_attr)
|
||||||
|
except (AttributeError, IndexError) as e:
|
||||||
|
raise ValueError("Invalid SVG file: {}".format(e))
|
||||||
|
|
||||||
return width, height, filetype
|
return width, height, filetype
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user