inherit styles (#673)

pull/680/head
Kaalleen 2020-05-02 15:00:42 +02:00 zatwierdzone przez GitHub
rodzic 8994982d70
commit a67eace2cd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 18 dodań i 10 usunięć

Wyświetl plik

@ -147,25 +147,34 @@ class EmbroideryElement(object):
param = INKSTITCH_ATTRIBS[name]
self.node.set(param, str(value))
@property
@cache
def style(self):
declarations = tinycss2.parse_declaration_list(self.node.get("style", ""))
def parse_style(self, node=None):
if node is None:
node = self.node
declarations = tinycss2.parse_declaration_list(node.get("style", ""))
style = {declaration.lower_name: declaration.value[0].serialize() for declaration in declarations}
return style
@cache
def _get_style_raw(self, style_name):
style = self.parse_style()
style = style.get(style_name) or self.node.get(style_name)
parent = self.node.getparent()
# style not found, get inherited style elements
while not style and parent is not None:
style = self.parse_style(parent)
style = style.get(style_name) or parent.get(style_name)
parent = parent.getparent()
return style
def get_style(self, style_name, default=None):
style = self.style.get(style_name)
# Style not found, let's see if it is set as a separate attribute
if style is None:
style = self.node.get(style_name, default)
style = self._get_style_raw(style_name) or default
if style == 'none':
style = None
return style
def has_style(self, style_name):
return style_name in self.style
return self._get_style_raw(style_name) is not None
@property
@cache

Wyświetl plik

@ -210,7 +210,6 @@ class RunningStitch(object):
self.path = path_or_stroke
self.original_element = original_element
self.style = original_element.node.get('style', '')
self.running_stitch_length = \
original_element.node.get(INKSTITCH_ATTRIBS['running_stitch_length_mm'], '') or \
original_element.node.get(INKSTITCH_ATTRIBS['center_walk_underlay_stitch_length_mm'], '') or \
@ -221,7 +220,7 @@ class RunningStitch(object):
node.set("d", cubicsuperpath.formatPath(
line_strings_to_csp([self.path])))
style = simplestyle.parseStyle(self.style)
style = self.original_element.parse_style()
style['stroke-dasharray'] = "0.5,0.5"
style = simplestyle.formatStyle(style)
node.set("style", style)