Tidy up font schema a little

This commit is contained in:
Mikayla Maki 2023-06-19 11:36:42 -07:00
parent 193ad64d18
commit ea46947489
No known key found for this signature in database

View File

@ -66,7 +66,7 @@ pub struct TextStyle {
pub font_family_id: FamilyId, pub font_family_id: FamilyId,
pub font_id: FontId, pub font_id: FontId,
pub font_size: f32, pub font_size: f32,
#[serde(with = "PropertiesDef")] #[schemars(with = "PropertiesDef")]
pub font_properties: Properties, pub font_properties: Properties,
pub underline: Underline, pub underline: Underline,
} }
@ -77,13 +77,13 @@ pub struct PropertiesDef {
/// The font style, as defined in CSS. /// The font style, as defined in CSS.
pub style: StyleDef, pub style: StyleDef,
/// The font weight, as defined in CSS. /// The font weight, as defined in CSS.
pub weight: WeightDef, pub weight: f32,
/// The font stretchiness, as defined in CSS. /// The font stretchiness, as defined in CSS.
pub stretch: StretchDef, pub stretch: f32,
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
#[serde(remote = "Style")] #[schemars(remote = "Style")]
pub enum StyleDef { pub enum StyleDef {
/// A face that is neither italic not obliqued. /// A face that is neither italic not obliqued.
Normal, Normal,
@ -93,18 +93,10 @@ pub enum StyleDef {
Oblique, Oblique,
} }
#[derive(JsonSchema)]
#[serde(remote = "Weight")]
pub struct WeightDef(pub f32);
#[derive(JsonSchema)]
#[serde(remote = "Stretch")]
pub struct StretchDef(pub f32);
#[derive(Copy, Clone, Debug, Default, PartialEq, JsonSchema)] #[derive(Copy, Clone, Debug, Default, PartialEq, JsonSchema)]
pub struct HighlightStyle { pub struct HighlightStyle {
pub color: Option<Color>, pub color: Option<Color>,
#[serde(with = "WeightDef")] #[schemars(with = "Option::<f32>")]
pub weight: Option<Weight>, pub weight: Option<Weight>,
pub italic: Option<bool>, pub italic: Option<bool>,
pub underline: Option<Underline>, pub underline: Option<Underline>,
@ -116,15 +108,11 @@ impl Eq for HighlightStyle {}
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, JsonSchema)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, JsonSchema)]
pub struct Underline { pub struct Underline {
pub color: Option<Color>, pub color: Option<Color>,
#[serde(with = "OrderedFloatDef::<f32>")] #[schemars(with = "f32")]
pub thickness: OrderedFloat<f32>, pub thickness: OrderedFloat<f32>,
pub squiggly: bool, pub squiggly: bool,
} }
#[derive(JsonSchema)]
#[serde(remote = "OrderedFloat")]
pub struct OrderedFloatDef<T>(pub T);
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
#[derive(Deserialize)] #[derive(Deserialize)]
enum WeightJson { enum WeightJson {