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

Function paint_symbol

SLiCAP/schematic/component_item.py:154–175  ·  view source on GitHub ↗

Render a symbol (artwork + centred embedded text, default orientation) into ``rect`` of ``painter``, preserving aspect ratio. Shared by the palette icons and the place-symbol preview so they render the embedded text identically to the canvas (ComponentItem.paint).

(painter, svg_bytes: bytes, rect: QRectF)

Source from the content-addressed store, hash-verified

152
153
154def paint_symbol(painter, svg_bytes: bytes, rect: QRectF) -> None:
155 """Render a symbol (artwork + centred embedded text, default orientation)
156 into ``rect`` of ``painter``, preserving aspect ratio.
157
158 Shared by the palette icons and the place-symbol preview so they render the
159 embedded text identically to the canvas (ComponentItem.paint)."""
160 stripped, texts = _split_symbol_text(svg_bytes)
161 renderer = QSvgRenderer(QByteArray(_apply_symbol_colors(stripped)))
162 vb = renderer.viewBoxF()
163 if vb.width() <= 0 or vb.height() <= 0:
164 return
165 sc = min(rect.width() / vb.width(), rect.height() / vb.height())
166 w, h = vb.width() * sc, vb.height() * sc
167 ox = rect.x() + (rect.width() - w) / 2.0
168 oy = rect.y() + (rect.height() - h) / 2.0
169 renderer.render(painter, QRectF(ox, oy, w, h))
170 painter.save()
171 painter.translate(ox, oy)
172 painter.scale(sc, sc)
173 painter.translate(-vb.left(), -vb.top())
174 draw_symbol_texts(painter, texts, 0.0, False, False)
175 painter.restore()
176
177
178# ── symbol metadata ───────────────────────────────────────────────────────────

Callers 2

_on_selection_changedMethod · 0.85
_render_iconFunction · 0.85

Calls 4

_split_symbol_textFunction · 0.85
_apply_symbol_colorsFunction · 0.85
draw_symbol_textsFunction · 0.85
saveMethod · 0.45

Tested by

no test coverage detected