MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / _latex_label

Function _latex_label

SLiCAP/schematic/export.py:400–444  ·  view source on GitHub ↗

Inline a LaTeX property label as scaled vector SVG content.

(parent, defs, item, lbl, sp, lbl_color, lbl_fs)

Source from the content-addressed store, hash-verified

398
399
400def _latex_label(parent, defs, item, lbl, sp, lbl_color, lbl_fs):
401 """Inline a LaTeX property label as scaled vector SVG content."""
402 svg_bytes = lbl._svg_bytes or None
403
404 if svg_bytes is None:
405 text = item._prop_text(lbl.prop_key)
406 if text:
407 t = ET.SubElement(parent, f"{{{_SVG_NS}}}text")
408 t.set("x", f"{sp.x():.2f}")
409 t.set("y", f"{sp.y():.2f}")
410 t.set("font-family", "sans-serif")
411 t.set("font-size", f"{lbl_fs}pt")
412 t.set("fill", lbl_color)
413 if item.h_flip:
414 t.set("text-anchor", "end")
415 t.text = text
416 return
417
418 rect = lbl._svg_rect # QRectF(prefix_w, -h, svg_w, h) in label-local coords
419 svg_h = rect.height()
420 svg_w = rect.width()
421 prefix_w = lbl._prefix_w # 0 when no prefix
422
423 # sp = scene position of label local (0,0).
424 # local (0,0) is the bottom of the SVG (bottom-aligned, matching text baseline).
425 # For h_flip=False: local (0,0) is bottom-left → prefix starts at sp.x()
426 # For h_flip=True: local (0,0) is bottom-right → content ends at sp.x()
427 if item.h_flip:
428 svg_x = sp.x() - svg_w
429 prefix_x = sp.x() - svg_w - prefix_w
430 else:
431 prefix_x = sp.x()
432 svg_x = sp.x() + prefix_w
433
434 if lbl._prefix:
435 t = ET.SubElement(parent, f"{{{_SVG_NS}}}text")
436 t.set("x", f"{prefix_x:.2f}")
437 # Prefix text centred on SVG: baseline at SVG centre (sp.y() - svg_h/2)
438 t.set("y", f"{sp.y() - svg_h / 2:.2f}")
439 t.set("font-family", "sans-serif")
440 t.set("font-size", f"{lbl_fs}pt")
441 t.set("fill", lbl_color)
442 t.text = lbl._prefix
443
444 _inline_latex_svg(parent, defs, svg_bytes, svg_x, sp.y(), svg_w, svg_h)
445
446
447def _inline_latex_svg(parent, defs, svg_bytes, x, y, w, h):

Callers 1

_componentFunction · 0.85

Calls 2

_inline_latex_svgFunction · 0.85
_prop_textMethod · 0.80

Tested by

no test coverage detected