use crate::layout::style::unexpected_token;
use cssparser::{Parser, Token, match_ignore_ascii_case};
use typed_builder::TypedBuilder;
use crate::layout::style::{
CssToken, FromCss, MakeComputed, ParseResult, declare_enum_from_css_impl,
};
#[derive(Debug, Clone, Copy, PartialEq, Default, TypedBuilder)]
#[non_exhaustive]
#[builder(field_defaults(default))]
pub struct FontSynthesis {
pub weight: FontSynthesic,
pub style: FontSynthesic,
}
impl MakeComputed for FontSynthesis {}
impl<'i> FromCss<'i> for FontSynthesis {
fn from_css(input: &mut Parser<'i, '_>) -> ParseResult<'i, Self> {
let mut weight = FontSynthesic::None;
let mut style = FontSynthesic::None;
while !input.is_exhausted() {
let location = input.current_source_location();
let ident = input.expect_ident()?;
match_ignore_ascii_case! {ident,
"none" => {
weight = FontSynthesic::None;
style = FontSynthesic::None;
},
"weight" => {
weight = FontSynthesic::Auto;
},
"style" => {
style = FontSynthesic::Auto;
},
_ => return Err(unexpected_token!(location, &Token::Ident(ident.to_owned()))),
};
}
if !input.is_exhausted() {
return Err(input.new_error_for_next_token());
}
Ok(Self { weight, style })
}
const VALID_TOKENS: &'static [CssToken] = &[
CssToken::Keyword("none"),
CssToken::Keyword("weight"),
CssToken::Keyword("style"),
];
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
#[non_exhaustive]
pub enum FontSynthesic {
#[default]
Auto,
None,
}
impl FontSynthesic {
pub(crate) fn is_allowed(self) -> bool {
self == FontSynthesic::Auto
}
}
declare_enum_from_css_impl!(
FontSynthesic,
"auto" => FontSynthesic::Auto,
"none" => FontSynthesic::None,
);