mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Support font-feature-settings as a @font-face descriptor
This commit is contained in:
parent
7d66e65d94
commit
a0886213b6
3 changed files with 44 additions and 12 deletions
|
@ -9,7 +9,7 @@
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use computed_values::{font_style, font_weight, font_stretch};
|
use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
|
||||||
use computed_values::font_family::FamilyName;
|
use computed_values::font_family::FamilyName;
|
||||||
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
|
||||||
use cssparser::SourceLocation;
|
use cssparser::SourceLocation;
|
||||||
|
@ -337,7 +337,12 @@ font_face_descriptors! {
|
||||||
UnicodeRange { start: 0, end: 0x10FFFF }
|
UnicodeRange { start: 0, end: 0x10FFFF }
|
||||||
],
|
],
|
||||||
|
|
||||||
// FIXME: add font-feature-settings, font-language-override, and font-display
|
/// The feature settings of this font face.
|
||||||
|
"font-feature-settings" feature_settings / mFontFeatureSettings: font_feature_settings::T = {
|
||||||
|
font_feature_settings::T::Normal
|
||||||
|
},
|
||||||
|
|
||||||
|
// FIXME: add font-language-override, and font-display.
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
//! Bindings for CSS Rule objects
|
//! Bindings for CSS Rule objects
|
||||||
|
|
||||||
use computed_values::{font_style, font_weight, font_stretch};
|
use byteorder::{BigEndian, WriteBytesExt};
|
||||||
|
use computed_values::{font_feature_settings, font_stretch, font_style, font_weight};
|
||||||
use computed_values::font_family::FamilyName;
|
use computed_values::font_family::FamilyName;
|
||||||
use counter_style;
|
use counter_style;
|
||||||
use cssparser::UnicodeRange;
|
use cssparser::UnicodeRange;
|
||||||
|
@ -15,7 +16,7 @@ use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
|
||||||
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
|
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
|
||||||
use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
|
use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
|
||||||
use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
|
use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
|
||||||
use std::fmt;
|
use std::{fmt, str};
|
||||||
|
|
||||||
/// A @font-face rule
|
/// A @font-face rule
|
||||||
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
||||||
|
@ -32,6 +33,27 @@ impl ToNsCssValue for font_weight::T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToNsCssValue for font_feature_settings::T {
|
||||||
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
|
match self {
|
||||||
|
font_feature_settings::T::Normal => nscssvalue.set_normal(),
|
||||||
|
font_feature_settings::T::Tag(tags) => {
|
||||||
|
nscssvalue.set_pair_list(tags.into_iter().map(|entry| {
|
||||||
|
let mut feature = nsCSSValue::null();
|
||||||
|
let mut raw = [0u8; 4];
|
||||||
|
(&mut raw[..]).write_u32::<BigEndian>(entry.tag).unwrap();
|
||||||
|
feature.set_string(str::from_utf8(&raw).unwrap());
|
||||||
|
|
||||||
|
let mut index = nsCSSValue::null();
|
||||||
|
index.set_integer(entry.value as i32);
|
||||||
|
|
||||||
|
(feature, index)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! map_enum {
|
macro_rules! map_enum {
|
||||||
(
|
(
|
||||||
$(
|
$(
|
||||||
|
|
|
@ -1804,14 +1804,14 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum T {
|
pub enum T {
|
||||||
Normal,
|
Normal,
|
||||||
Tag(Vec<FeatureTagValue>)
|
Tag(Vec<FeatureTagValue>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct FeatureTagValue {
|
pub struct FeatureTagValue {
|
||||||
pub tag: u32,
|
pub tag: u32,
|
||||||
|
@ -1837,6 +1837,16 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Parse for T {
|
||||||
|
/// https://www.w3.org/TR/css-fonts-3/#propdef-font-feature-settings
|
||||||
|
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
|
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||||
|
return Ok(T::Normal);
|
||||||
|
}
|
||||||
|
input.parse_comma_separated(|i| FeatureTagValue::parse(context, i)).map(T::Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToCss for FeatureTagValue {
|
impl ToCss for FeatureTagValue {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -1909,12 +1919,7 @@ ${helpers.single_keyword_system("font-variant-position",
|
||||||
|
|
||||||
/// normal | <feature-tag-value>#
|
/// normal | <feature-tag-value>#
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||||
if input.try(|input| input.expect_ident_matching("normal")).is_ok() {
|
computed_value::T::parse(context, input).map(SpecifiedValue::Value)
|
||||||
Ok(SpecifiedValue::Value(computed_value::T::Normal))
|
|
||||||
} else {
|
|
||||||
input.parse_comma_separated(|i| computed_value::FeatureTagValue::parse(context, i))
|
|
||||||
.map(computed_value::T::Tag).map(SpecifiedValue::Value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%helpers:longhand>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue