Do not remove stroke:none; if a differing value would be inherited from a parent

(fixes rest of #22)
This commit is contained in:
Eduard Braun 2016-09-10 22:59:29 +02:00
parent 0b5eab7f2f
commit 0b5bb5184c

View file

@ -1468,9 +1468,9 @@ def repairStyle(node, options):
if strokestyle in styleMap and not styleInheritedByChild(node, strokestyle):
del styleMap[strokestyle]
num += 1
# TODO: This is actually a problem if a parent element has a specified stroke
# we need to properly calculate computed values
if not styleInheritedByChild(node, 'stroke'):
if styleInheritedFromParent(node, 'stroke') in [None, 'none']:
del styleMap['stroke']
num += 1
@ -1564,6 +1564,34 @@ def repairStyle(node, options):
return num
def styleInheritedFromParent(node, style):
"""
Returns the value of 'style' that is inherited from the parents of the passed-in node
Warning: This method only considers presentation attributes and inline styles,
any style sheets are ignored!
"""
parentNode = node.parentNode;
# return None if we reached the Document element
if parentNode.nodeType == 9:
return None
# check styles first (they take precedence over presentation attributes)
styles = _getStyle(parentNode)
if style in styles.keys():
value = styles[style]
if not value == 'inherit':
return value
# check attributes
value = parentNode.getAttribute(style)
if value not in ['', 'inherit']:
return parentNode.getAttribute(style)
# check the next parent recursively if we did not find a value yet
return styleInheritedFromParent(parentNode, style)
def styleInheritedByChild(node, style, nodeIsChild=False):
"""
Returns whether 'style' is inherited by any children of the passed-in node