Programmatically generate SVG (vector) images, animations, and interactive Jupyter widgets

Add ForeignObject (#104)

authored by

Aljosha Papsch and committed by
GitHub
94221031 fdf5e610

+24
+24
drawsvg/elements.py
··· 597 597 def __init__(self, cx, cy, r, start_deg, end_deg, cw=False, **kwargs): 598 598 super().__init__(d='', **kwargs) 599 599 self.arc(cx, cy, r, start_deg, end_deg, cw=cw, include_m=True) 600 + 601 + class ForeignObject(DrawingBasicElement): 602 + '''A foreign object, i.e. for embedding HTML. 603 + 604 + In the context of SVG embedded in an HTML document, the XHTML namespace 605 + could be omitted in the foreignObject content, but it is mandatory in the 606 + context of an SVG document. 607 + 608 + This element works best when viewing the SVG in a browser. Drawing.rasterize() 609 + and Drawing.save_png() are unable to display this element. 610 + 611 + Additional keyword arguments are output as additional arguments to the SVG 612 + node e.g. fill="red", stroke="#ff4477", stroke_width=2. 613 + ''' 614 + TAG_NAME = 'foreignObject' 615 + has_content = True 616 + def __init__(self, content, **kwargs): 617 + super().__init__(**kwargs) 618 + self.content = content 619 + def write_content(self, id_map, is_duplicate, output_file, lcontext, 620 + dry_run): 621 + if dry_run: 622 + return 623 + output_file.write(self.content)