Draw a symbol's embedded text labels upright and unmirrored under any rotation/flip (companion to draw_subckt_pin_names; used by ComponentItem and the SVG/PDF exporter via the same text list).
(painter, texts, rotation: float,
h_flip: bool, v_flip: bool)
| 122 | |
| 123 | |
| 124 | def draw_symbol_texts(painter, texts, rotation: float, |
| 125 | h_flip: bool, v_flip: bool) -> None: |
| 126 | """Draw a symbol's embedded text labels upright and unmirrored under any |
| 127 | rotation/flip (companion to draw_subckt_pin_names; used by ComponentItem and |
| 128 | the SVG/PDF exporter via the same text list).""" |
| 129 | if not texts: |
| 130 | return |
| 131 | ct = _counter_transform(rotation, h_flip, v_flip) |
| 132 | painter.save() |
| 133 | painter.setPen(config.SYMBOL_TEXT_COLOR) |
| 134 | for t in texts: |
| 135 | content = t["content"] |
| 136 | if not content: |
| 137 | continue |
| 138 | f = QFont(_PARAM_FONT) |
| 139 | f.setPixelSize(max(1, round(t["size"]))) |
| 140 | painter.setFont(f) |
| 141 | painter.save() |
| 142 | painter.translate(t["x"], t["y"]) |
| 143 | painter.setTransform(ct, True) |
| 144 | # Centred horizontally AND vertically on the anchor point, so the counter |
| 145 | # transform pivots on the glyph centre — the text stays put (just upright) |
| 146 | # under any rotation/mirror. The previews render through the same path |
| 147 | # (paint_symbol) so the canvas and previews match exactly. |
| 148 | painter.drawText(QRectF(-100.0, -100.0, 200.0, 200.0), |
| 149 | Qt.AlignCenter, content) |
| 150 | painter.restore() |
| 151 | painter.restore() |
| 152 | |
| 153 | |
| 154 | def paint_symbol(painter, svg_bytes: bytes, rect: QRectF) -> None: |
no test coverage detected