MCPcopy Create free account
hub / github.com/Distrotech/reportlab / transformNode

Function transformNode

src/reportlab/graphics/renderSVG.py:64–93  ·  view source on GitHub ↗

Transform a DOM node into new node and copy selected attributes. Creates a new DOM node with tag name 'newTag' for document 'doc' and copies selected attributes from an existing 'node' as provided in 'attrDict'. The source 'node' can be None. Attribute values will be converted to st

(doc, newTag, node=None, **attrDict)

Source from the content-addressed store, hash-verified

62 return P
63
64def transformNode(doc, newTag, node=None, **attrDict):
65 """Transform a DOM node into new node and copy selected attributes.
66
67 Creates a new DOM node with tag name 'newTag' for document 'doc'
68 and copies selected attributes from an existing 'node' as provided
69 in 'attrDict'. The source 'node' can be None. Attribute values will
70 be converted to strings.
71
72 E.g.
73
74 n = transformNode(doc, "node1", x="0", y="1")
75 -> DOM node for <node1 x="0" y="1"/>
76
77 n = transformNode(doc, "node1", x=0, y=1+1)
78 -> DOM node for <node1 x="0" y="2"/>
79
80 n = transformNode(doc, "node1", node0, x="x0", y="x0", zoo=bar())
81 -> DOM node for <node1 x="[node0.x0]" y="[node0.y0]" zoo="[bar()]"/>
82 """
83
84 newNode = doc.createElement(newTag)
85 for newAttr, attr in attrDict.items():
86 sattr = str(attr)
87 if not node:
88 newNode.setAttribute(newAttr, sattr)
89 else:
90 attrVal = node.getAttribute(sattr)
91 newNode.setAttribute(newAttr, attrVal or sattr)
92
93 return newNode
94
95### classes ###
96class SVGCanvas:

Callers 13

__init__Method · 0.85
_fillAndStrokeMethod · 0.85
_add_linkMethod · 0.85
rectMethod · 0.85
roundRectMethod · 0.85
drawStringMethod · 0.85
lineMethod · 0.85
ellipseMethod · 0.85
circleMethod · 0.85
drawArcMethod · 0.85
polygonMethod · 0.85
polyLineMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected