Skip to main content

build_font_string

Function build_font_string 

Source
pub fn build_font_string(style: &TextStyle) -> String
Expand description

Builds a CSS font shorthand string from a TextStyle.

The resulting string follows the CSS font shorthand syntax: "[weight] [size]px [family]". If no family is specified, "sans-serif" is used as a sensible default that works across all browsers.

ยงExamples

use plotkit_render_wasm::{build_font_string, TextStyle, FontWeight};

let style = TextStyle::new(14.0);
assert_eq!(build_font_string(&style), "14px sans-serif");

let mut bold = TextStyle::new(16.0);
bold.weight = FontWeight::Bold;
bold.family = Some("Helvetica".to_string());
assert_eq!(build_font_string(&bold), "bold 16px Helvetica");