Render all scene items to a vector SVG document, returning UTF-8 bytes.
(scene, title: str = "")
| 82 | |
| 83 | |
| 84 | def _build_svg(scene, title: str = "") -> bytes: |
| 85 | """Render all scene items to a vector SVG document, returning UTF-8 bytes.""" |
| 86 | from .component_item import ComponentItem |
| 87 | from .wire_item import WireItem |
| 88 | from .junction_item import JunctionItem |
| 89 | from .free_text_item import FreeTextItem |
| 90 | from .command_item import CommandItem |
| 91 | from .analysis_item import AnalysisItem |
| 92 | from .hyperlink_item import HyperlinkItem |
| 93 | from .shape_item import ShapeItem |
| 94 | from .image_item import ImageItem |
| 95 | from .latex_fragment_item import LatexFragmentItem |
| 96 | from .parameter_item import ParameterItem |
| 97 | from .model_item import ModelItem |
| 98 | from .library_item import LibraryItem |
| 99 | from .config import ( |
| 100 | WIRE_COLOR, WIRE_WIDTH, |
| 101 | JUNCTION_COLOR, JUNCTION_RADIUS, |
| 102 | COMP_LABEL_COLOR, COMP_LABEL_FONT_SIZE, |
| 103 | NET_LABEL_COLOR, NET_LABEL_FONT_SIZE, |
| 104 | TEXT_COLOR, TEXT_FONT_SIZE, TEXT_FONT_FAMILY, TEXT_FONT, |
| 105 | HYPERLINK_COLOR, HYPERLINK_FONT_SIZE, HYPERLINK_FONT_FAMILY, HYPERLINK_UNDERLINE, |
| 106 | COMMAND_COLOR, COMMAND_FONT_SIZE, COMMAND_FONT, |
| 107 | ) |
| 108 | |
| 109 | bounds = export_bounds(scene) |
| 110 | vx, vy = bounds.x(), bounds.y() |
| 111 | vw, vh = bounds.width(), bounds.height() |
| 112 | |
| 113 | root = ET.Element(f"{{{_SVG_NS}}}svg") |
| 114 | root.set("version", "1.1") |
| 115 | root.set("viewBox", f"{vx:.3f} {vy:.3f} {vw:.3f} {vh:.3f}") |
| 116 | root.set("width", f"{int(vw)}") |
| 117 | root.set("height", f"{int(vh)}") |
| 118 | if title: |
| 119 | ET.SubElement(root, f"{{{_SVG_NS}}}title").text = title |
| 120 | |
| 121 | # Collects glyph <defs> extracted from inlined LaTeX SVGs. |
| 122 | defs = ET.SubElement(root, f"{{{_SVG_NS}}}defs") |
| 123 | |
| 124 | bg = ET.SubElement(root, f"{{{_SVG_NS}}}rect") |
| 125 | bg.set("x", f"{vx:.3f}"); bg.set("y", f"{vy:.3f}") |
| 126 | bg.set("width", f"{vw:.3f}"); bg.set("height", f"{vh:.3f}") |
| 127 | bg.set("fill", "white") |
| 128 | |
| 129 | wire_color = _qhex(WIRE_COLOR) |
| 130 | junc_color = _qhex(JUNCTION_COLOR) |
| 131 | lbl_color = _qhex(COMP_LABEL_COLOR) |
| 132 | net_color = _qhex(NET_LABEL_COLOR) |
| 133 | txt_color = _qhex(TEXT_COLOR) |
| 134 | cmd_color = _qhex(COMMAND_COLOR) |
| 135 | lnk_color = _qhex(HYPERLINK_COLOR) |
| 136 | |
| 137 | for item in reversed(scene.items()): |
| 138 | if item.parentItem() is not None: |
| 139 | continue # child items (labels, net labels) handled by their parents |
| 140 | |
| 141 | from .border_item import BorderItem |
no test coverage detected