Files
lxc-streamutils/apps/server-rust/src/typography.rs
T
2026-08-13 12:05:47 -07:00

45 lines
1.2 KiB
Rust

//! Shared, validated typography settings for all built-in OBS components.
//!
//! Font IDs map to fixed, same-origin WOFF2 assets in the frontend rather than
//! accepting arbitrary CSS. This keeps settings portable between OBS hosts and
//! prevents untrusted component settings from becoming a CSS injection boundary.
use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum FontFamilyId {
Song,
#[default]
FangSong,
Kai,
LiyuShoushu,
}
pub const fn default_font_brightness() -> u16 {
130
}
pub fn sanitize_font_brightness(value: u16) -> u16 {
value.clamp(70, 180)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn font_ids_are_stable_and_brightness_is_bounded() {
assert_eq!(
serde_json::to_string(&FontFamilyId::FangSong).unwrap(),
"\"fang-song\""
);
assert_eq!(sanitize_font_brightness(1), 70);
assert_eq!(sanitize_font_brightness(u16::MAX), 180);
assert_eq!(
serde_json::to_string(&FontFamilyId::LiyuShoushu).unwrap(),
"\"liyu-shoushu\""
);
}
}