Skip to main content

merman_render/text/
types.rs

1//! Shared text measurement types.
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
6pub enum WrapMode {
7    #[default]
8    SvgLike,
9    /// SVG `<text>` behaves as a single shaping run (no whitespace-to-`<tspan>` tokenization).
10    ///
11    /// Mermaid uses this behavior in some diagrams (e.g. sequence message labels), where the
12    /// resulting `getBBox()` width differs measurably from per-word `<tspan>` tokenization.
13    SvgLikeSingleRun,
14    HtmlLike,
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct TextStyle {
19    pub font_family: Option<String>,
20    pub font_size: f64,
21    pub font_weight: Option<String>,
22}
23
24impl Default for TextStyle {
25    fn default() -> Self {
26        Self {
27            font_family: None,
28            font_size: 16.0,
29            font_weight: None,
30        }
31    }
32}
33
34#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
35pub struct TextMetrics {
36    pub width: f64,
37    pub height: f64,
38    pub line_count: usize,
39}