Convert a Style to CSS rules for SVG.
(style: Style)
| 2384 | style_cache: Dict[Style, str] = {} |
| 2385 | |
| 2386 | def get_svg_style(style: Style) -> str: |
| 2387 | """Convert a Style to CSS rules for SVG.""" |
| 2388 | if style in style_cache: |
| 2389 | return style_cache[style] |
| 2390 | css_rules = [] |
| 2391 | color = ( |
| 2392 | _theme.foreground_color |
| 2393 | if (style.color is None or style.color.is_default) |
| 2394 | else style.color.get_truecolor(_theme) |
| 2395 | ) |
| 2396 | bgcolor = ( |
| 2397 | _theme.background_color |
| 2398 | if (style.bgcolor is None or style.bgcolor.is_default) |
| 2399 | else style.bgcolor.get_truecolor(_theme) |
| 2400 | ) |
| 2401 | if style.reverse: |
| 2402 | color, bgcolor = bgcolor, color |
| 2403 | if style.dim: |
| 2404 | color = blend_rgb(color, bgcolor, 0.4) |
| 2405 | css_rules.append(f"fill: {color.hex}") |
| 2406 | if style.bold: |
| 2407 | css_rules.append("font-weight: bold") |
| 2408 | if style.italic: |
| 2409 | css_rules.append("font-style: italic;") |
| 2410 | if style.underline: |
| 2411 | css_rules.append("text-decoration: underline;") |
| 2412 | if style.strike: |
| 2413 | css_rules.append("text-decoration: line-through;") |
| 2414 | |
| 2415 | css = ";".join(css_rules) |
| 2416 | style_cache[style] = css |
| 2417 | return css |
| 2418 | |
| 2419 | _theme = theme or SVG_EXPORT_THEME |
| 2420 |
nothing calls this directly
no test coverage detected