MCPcopy Create free account
hub / github.com/SLiCAP/SLiCAP_python / _hyperlink_block

Function _hyperlink_block

SLiCAP/schematic/export.py:654–673  ·  view source on GitHub ↗

Render a HyperlinkItem as an SVG element.

(parent, item, color, fs, family, underline: bool)

Source from the content-addressed store, hash-verified

652
653
654def _hyperlink_block(parent, item, color, fs, family, underline: bool):
655 """Render a HyperlinkItem as an SVG <a href> element."""
656 from PySide6.QtGui import QFontMetricsF
657 pos = item.pos()
658 label = item.label or item.url
659 url = item.url
660 # QGraphicsSimpleTextItem.pos() is the top-left; add ascent for SVG baseline.
661 fm = QFontMetricsF(item.font())
662 a = ET.SubElement(parent, f"{{{_SVG_NS}}}a")
663 a.set("href", url)
664 a.set(f"{{{_XLINK_NS}}}href", url) # SVG 1.1 compatibility
665 t = ET.SubElement(a, f"{{{_SVG_NS}}}text")
666 t.set("x", f"{pos.x():.2f}")
667 t.set("y", f"{pos.y() + fm.ascent():.2f}")
668 t.set("font-family", family)
669 t.set("font-size", f"{fs}pt")
670 t.set("fill", color)
671 if underline:
672 t.set("text-decoration", "underline")
673 t.text = label
674
675
676def export_svg(scene, output_path: Path, title: str = "") -> None:

Callers 1

_build_svgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected