use crate::ir::{BorderLineStyle, BorderSide, Color};
pub(super) fn rgb(color: &Color) -> String {
format!("rgb({}, {}, {})", color.r, color.g, color.b)
}
pub(super) fn rgb_with_alpha(color: &Color, alpha: u8) -> String {
format!("rgb({}, {}, {}, {})", color.r, color.g, color.b, alpha)
}
pub(super) fn stroke_value(side: &BorderSide, double_is_plain: bool) -> String {
let is_plain = match side.style {
BorderLineStyle::Solid | BorderLineStyle::None => true,
BorderLineStyle::Double => double_is_plain,
_ => false,
};
if is_plain {
format!("{}pt + {}", format_f64(side.width), rgb(&side.color))
} else {
format!(
"(paint: {}, thickness: {}pt, dash: \"{}\")",
rgb(&side.color),
format_f64(side.width),
super::border_line_style_to_typst(side.style),
)
}
}
pub(super) fn format_f64(v: f64) -> String {
if v.fract() == 0.0 {
format!("{}", v as i64)
} else {
format!("{v}")
}
}
#[cfg(test)]
#[path = "typst_gen_fmt_tests.rs"]
mod tests;