mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: [css-fonts] Implement 'font-synthesis: small-caps'
Differential Revision: https://phabricator.services.mozilla.com/D114313
This commit is contained in:
parent
fd3d12e214
commit
0cb64672f4
1 changed files with 68 additions and 32 deletions
|
@ -1990,23 +1990,24 @@ impl Parse for FontFeatureSettings {
|
||||||
Debug,
|
Debug,
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
/// Whether user agents are allowed to synthesize bold or oblique font faces
|
/// Whether user agents are allowed to synthesize bold or oblique font faces
|
||||||
/// when a font family lacks bold or italic faces
|
/// when a font family lacks those faces, or a small-caps variant when this is
|
||||||
|
/// not supported by the face.
|
||||||
pub struct FontSynthesis {
|
pub struct FontSynthesis {
|
||||||
/// If a `font-weight` is requested that the font family does not contain,
|
/// If a `font-weight` is requested that the font family does not contain,
|
||||||
/// the user agent may synthesize the requested weight from the weights
|
/// the user agent may synthesize the requested weight from the weights
|
||||||
/// that do exist in the font family.
|
/// that do exist in the font family.
|
||||||
#[css(represents_keyword)]
|
|
||||||
pub weight: bool,
|
pub weight: bool,
|
||||||
/// If a font-style is requested that the font family does not contain,
|
/// If a font-style is requested that the font family does not contain,
|
||||||
/// the user agent may synthesize the requested style from the normal face in the font family.
|
/// the user agent may synthesize the requested style from the normal face in the font family.
|
||||||
#[css(represents_keyword)]
|
|
||||||
pub style: bool,
|
pub style: bool,
|
||||||
|
/// This bit controls whether the user agent is allowed to synthesize small caps variant
|
||||||
|
/// when a font face lacks it.
|
||||||
|
pub small_caps: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontSynthesis {
|
impl FontSynthesis {
|
||||||
|
@ -2016,6 +2017,7 @@ impl FontSynthesis {
|
||||||
FontSynthesis {
|
FontSynthesis {
|
||||||
weight: true,
|
weight: true,
|
||||||
style: true,
|
style: true,
|
||||||
|
small_caps: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2024,8 +2026,14 @@ impl FontSynthesis {
|
||||||
FontSynthesis {
|
FontSynthesis {
|
||||||
weight: false,
|
weight: false,
|
||||||
style: false,
|
style: false,
|
||||||
|
small_caps: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
/// Return true if this is the 'none' value
|
||||||
|
pub fn is_none(&self) -> bool {
|
||||||
|
*self == Self::none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for FontSynthesis {
|
impl Parse for FontSynthesis {
|
||||||
|
@ -2033,26 +2041,23 @@ impl Parse for FontSynthesis {
|
||||||
_: &ParserContext,
|
_: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<FontSynthesis, ParseError<'i>> {
|
) -> Result<FontSynthesis, ParseError<'i>> {
|
||||||
let mut result = FontSynthesis {
|
use crate::values::SelectorParseErrorKind;
|
||||||
weight: false,
|
let mut result = Self::none();
|
||||||
style: false,
|
while let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) {
|
||||||
};
|
match_ignore_ascii_case! { &ident,
|
||||||
try_match_ident_ignore_ascii_case! { input,
|
"none" if result.is_none() => return Ok(result),
|
||||||
"none" => Ok(result),
|
"weight" if !result.weight => result.weight = true,
|
||||||
"weight" => {
|
"style" if !result.style => result.style = true,
|
||||||
result.weight = true;
|
"small-caps" if !result.small_caps &&
|
||||||
if input.try_parse(|input| input.expect_ident_matching("style")).is_ok() {
|
static_prefs::pref!("layout.css.font-synthesis-small-caps.enabled")
|
||||||
result.style = true;
|
=> result.small_caps = true,
|
||||||
}
|
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident))),
|
||||||
Ok(result)
|
}
|
||||||
},
|
}
|
||||||
"style" => {
|
if !result.is_none() {
|
||||||
result.style = true;
|
Ok(result)
|
||||||
if input.try_parse(|input| input.expect_ident_matching("weight")).is_ok() {
|
} else {
|
||||||
result.weight = true;
|
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
|
||||||
Ok(result)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2062,14 +2067,41 @@ impl ToCss for FontSynthesis {
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
if self.weight && self.style {
|
if self.is_none() {
|
||||||
dest.write_str("weight style")
|
return dest.write_str("none");
|
||||||
} else if self.style {
|
}
|
||||||
dest.write_str("style")
|
|
||||||
} else if self.weight {
|
let mut need_space = false;
|
||||||
dest.write_str("weight")
|
if self.weight {
|
||||||
} else {
|
dest.write_str("weight")?;
|
||||||
dest.write_str("none")
|
need_space = true;
|
||||||
|
}
|
||||||
|
if self.style {
|
||||||
|
if need_space {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
}
|
||||||
|
dest.write_str("style")?;
|
||||||
|
need_space = true;
|
||||||
|
}
|
||||||
|
if self.small_caps {
|
||||||
|
if need_space {
|
||||||
|
dest.write_str(" ")?;
|
||||||
|
}
|
||||||
|
dest.write_str("small-caps")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpecifiedValueInfo for FontSynthesis {
|
||||||
|
fn collect_completion_keywords(f: KeywordsCollectFn) {
|
||||||
|
f(&[
|
||||||
|
"none",
|
||||||
|
"weight",
|
||||||
|
"style",
|
||||||
|
]);
|
||||||
|
if static_prefs::pref!("layout.css.font-synthesis-small-caps.enabled") {
|
||||||
|
f(&["small-caps"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2082,6 +2114,7 @@ impl From<u8> for FontSynthesis {
|
||||||
FontSynthesis {
|
FontSynthesis {
|
||||||
weight: bits & structs::NS_FONT_SYNTHESIS_WEIGHT as u8 != 0,
|
weight: bits & structs::NS_FONT_SYNTHESIS_WEIGHT as u8 != 0,
|
||||||
style: bits & structs::NS_FONT_SYNTHESIS_STYLE as u8 != 0,
|
style: bits & structs::NS_FONT_SYNTHESIS_STYLE as u8 != 0,
|
||||||
|
small_caps: bits & structs::NS_FONT_SYNTHESIS_SMALL_CAPS as u8 != 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2098,6 +2131,9 @@ impl From<FontSynthesis> for u8 {
|
||||||
if v.style {
|
if v.style {
|
||||||
bits |= structs::NS_FONT_SYNTHESIS_STYLE as u8;
|
bits |= structs::NS_FONT_SYNTHESIS_STYLE as u8;
|
||||||
}
|
}
|
||||||
|
if v.small_caps {
|
||||||
|
bits |= structs::NS_FONT_SYNTHESIS_SMALL_CAPS as u8;
|
||||||
|
}
|
||||||
bits
|
bits
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue