mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Integrate font-variation-settings descriptor with stylo
This commit is contained in:
parent
4c3f1756da
commit
6ffa888dd6
6 changed files with 82 additions and 18 deletions
|
@ -26,7 +26,7 @@ use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
||||||
use style_traits::{StyleParseErrorKind, ToCss};
|
use style_traits::{StyleParseErrorKind, ToCss};
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::specified::font::SpecifiedFontFeatureSettings;
|
use values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A source for a font-face rule.
|
/// A source for a font-face rule.
|
||||||
|
@ -235,6 +235,12 @@ macro_rules! is_descriptor_enabled {
|
||||||
mozilla::StylePrefs_sFontDisplayEnabled
|
mozilla::StylePrefs_sFontDisplayEnabled
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
("font-variation-settings") => {
|
||||||
|
unsafe {
|
||||||
|
use gecko_bindings::structs::mozilla;
|
||||||
|
mozilla::StylePrefs_sFontVariationsEnabled
|
||||||
|
}
|
||||||
|
};
|
||||||
($name: tt) => { true }
|
($name: tt) => { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +251,7 @@ macro_rules! font_face_descriptors_common {
|
||||||
/// Data inside a `@font-face` rule.
|
/// Data inside a `@font-face` rule.
|
||||||
///
|
///
|
||||||
/// <https://drafts.csswg.org/css-fonts/#font-face-rule>
|
/// <https://drafts.csswg.org/css-fonts/#font-face-rule>
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct FontFaceRuleData {
|
pub struct FontFaceRuleData {
|
||||||
$(
|
$(
|
||||||
#[$doc]
|
#[$doc]
|
||||||
|
@ -405,6 +411,11 @@ font_face_descriptors! {
|
||||||
font_feature_settings::SpecifiedValue::normal()
|
font_feature_settings::SpecifiedValue::normal()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// The variation settings of this font face.
|
||||||
|
"font-variation-settings" variation_settings / mFontVariationSettings: FontVariationSettings = {
|
||||||
|
font_variation_settings::SpecifiedValue::normal()
|
||||||
|
},
|
||||||
|
|
||||||
/// The language override of this font face.
|
/// The language override of this font face.
|
||||||
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue = {
|
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue = {
|
||||||
font_language_override::SpecifiedValue::Normal
|
font_language_override::SpecifiedValue::Normal
|
||||||
|
|
|
@ -1471,6 +1471,9 @@ extern "C" {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_CSSValue_SetInt(css_value: nsCSSValueBorrowedMut, integer: i32, unit: nsCSSUnit);
|
pub fn Gecko_CSSValue_SetInt(css_value: nsCSSValueBorrowedMut, integer: i32, unit: nsCSSUnit);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Gecko_CSSValue_SetFloat(css_value: nsCSSValueBorrowedMut, value: f32, unit: nsCSSUnit);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_CSSValue_SetPair(
|
pub fn Gecko_CSSValue_SetPair(
|
||||||
css_value: nsCSSValueBorrowedMut,
|
css_value: nsCSSValueBorrowedMut,
|
||||||
|
|
|
@ -10230,6 +10230,10 @@ pub mod root {
|
||||||
#[link_name = "\u{1}_ZN7mozilla10StylePrefs32sGridTemplateSubgridValueEnabledE"]
|
#[link_name = "\u{1}_ZN7mozilla10StylePrefs32sGridTemplateSubgridValueEnabledE"]
|
||||||
pub static mut StylePrefs_sGridTemplateSubgridValueEnabled: bool;
|
pub static mut StylePrefs_sGridTemplateSubgridValueEnabled: bool;
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "\u{1}_ZN7mozilla10StylePrefs22sFontVariationsEnabledE"]
|
||||||
|
pub static mut StylePrefs_sFontVariationsEnabled: bool;
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "\u{1}_ZN7mozilla10StylePrefs22sEmulateMozBoxWithFlexE"]
|
#[link_name = "\u{1}_ZN7mozilla10StylePrefs22sEmulateMozBoxWithFlexE"]
|
||||||
pub static mut StylePrefs_sEmulateMozBoxWithFlex: bool;
|
pub static mut StylePrefs_sEmulateMozBoxWithFlex: bool;
|
||||||
|
@ -11885,6 +11889,7 @@ pub mod root {
|
||||||
pub mSrc: root::nsCSSValue,
|
pub mSrc: root::nsCSSValue,
|
||||||
pub mUnicodeRange: root::nsCSSValue,
|
pub mUnicodeRange: root::nsCSSValue,
|
||||||
pub mFontFeatureSettings: root::nsCSSValue,
|
pub mFontFeatureSettings: root::nsCSSValue,
|
||||||
|
pub mFontVariationSettings: root::nsCSSValue,
|
||||||
pub mFontLanguageOverride: root::nsCSSValue,
|
pub mFontLanguageOverride: root::nsCSSValue,
|
||||||
pub mDisplay: root::nsCSSValue,
|
pub mDisplay: root::nsCSSValue,
|
||||||
}
|
}
|
||||||
|
@ -11896,7 +11901,7 @@ pub mod root {
|
||||||
fn bindgen_test_layout_CSSFontFaceDescriptors() {
|
fn bindgen_test_layout_CSSFontFaceDescriptors() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::size_of::<CSSFontFaceDescriptors>(),
|
::std::mem::size_of::<CSSFontFaceDescriptors>(),
|
||||||
144usize,
|
160usize,
|
||||||
concat!("Size of: ", stringify!(CSSFontFaceDescriptors))
|
concat!("Size of: ", stringify!(CSSFontFaceDescriptors))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -11992,10 +11997,23 @@ pub mod root {
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
unsafe {
|
unsafe {
|
||||||
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontLanguageOverride
|
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontVariationSettings
|
||||||
as *const _ as usize
|
as *const _ as usize
|
||||||
},
|
},
|
||||||
112usize,
|
112usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(CSSFontFaceDescriptors),
|
||||||
|
"::",
|
||||||
|
stringify!(mFontVariationSettings)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe {
|
||||||
|
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontLanguageOverride
|
||||||
|
as *const _ as usize
|
||||||
|
},
|
||||||
|
128usize,
|
||||||
concat!(
|
concat!(
|
||||||
"Offset of field: ",
|
"Offset of field: ",
|
||||||
stringify!(CSSFontFaceDescriptors),
|
stringify!(CSSFontFaceDescriptors),
|
||||||
|
@ -12007,7 +12025,7 @@ pub mod root {
|
||||||
unsafe {
|
unsafe {
|
||||||
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mDisplay as *const _ as usize
|
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mDisplay as *const _ as usize
|
||||||
},
|
},
|
||||||
128usize,
|
144usize,
|
||||||
concat!(
|
concat!(
|
||||||
"Offset of field: ",
|
"Offset of field: ",
|
||||||
stringify!(CSSFontFaceDescriptors),
|
stringify!(CSSFontFaceDescriptors),
|
||||||
|
@ -21749,9 +21767,10 @@ pub mod root {
|
||||||
eCSSFontDesc_Src = 4,
|
eCSSFontDesc_Src = 4,
|
||||||
eCSSFontDesc_UnicodeRange = 5,
|
eCSSFontDesc_UnicodeRange = 5,
|
||||||
eCSSFontDesc_FontFeatureSettings = 6,
|
eCSSFontDesc_FontFeatureSettings = 6,
|
||||||
eCSSFontDesc_FontLanguageOverride = 7,
|
eCSSFontDesc_FontVariationSettings = 7,
|
||||||
eCSSFontDesc_Display = 8,
|
eCSSFontDesc_FontLanguageOverride = 8,
|
||||||
eCSSFontDesc_COUNT = 9,
|
eCSSFontDesc_Display = 9,
|
||||||
|
eCSSFontDesc_COUNT = 10,
|
||||||
}
|
}
|
||||||
#[repr(i32)]
|
#[repr(i32)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
@ -37537,7 +37556,7 @@ pub mod root {
|
||||||
fn bindgen_test_layout_nsCSSFontFaceStyleDecl() {
|
fn bindgen_test_layout_nsCSSFontFaceStyleDecl() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::size_of::<nsCSSFontFaceStyleDecl>(),
|
::std::mem::size_of::<nsCSSFontFaceStyleDecl>(),
|
||||||
176usize,
|
192usize,
|
||||||
concat!("Size of: ", stringify!(nsCSSFontFaceStyleDecl))
|
concat!("Size of: ", stringify!(nsCSSFontFaceStyleDecl))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -37599,7 +37618,7 @@ pub mod root {
|
||||||
fn bindgen_test_layout_nsCSSFontFaceRule() {
|
fn bindgen_test_layout_nsCSSFontFaceRule() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
::std::mem::size_of::<nsCSSFontFaceRule>(),
|
::std::mem::size_of::<nsCSSFontFaceRule>(),
|
||||||
240usize,
|
256usize,
|
||||||
concat!("Size of: ", stringify!(nsCSSFontFaceRule))
|
concat!("Size of: ", stringify!(nsCSSFontFaceRule))
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -21,7 +21,7 @@ use std::fmt::{self, Write};
|
||||||
use std::str;
|
use std::str;
|
||||||
use str::CssStringWriter;
|
use str::CssStringWriter;
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
use values::specified::font::SpecifiedFontFeatureSettings;
|
use values::specified::font::{FontTag, FontVariationSettings, SpecifiedFontFeatureSettings};
|
||||||
|
|
||||||
/// A @font-face rule
|
/// A @font-face rule
|
||||||
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
||||||
|
@ -50,6 +50,14 @@ impl ToNsCssValue for FontWeight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToNsCssValue for FontTag {
|
||||||
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
|
let mut raw = [0u8; 4];
|
||||||
|
(&mut raw[..]).write_u32::<BigEndian>(self.0).unwrap();
|
||||||
|
nscssvalue.set_string(str::from_utf8(&raw).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToNsCssValue for SpecifiedFontFeatureSettings {
|
impl ToNsCssValue for SpecifiedFontFeatureSettings {
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
if self.0.is_empty() {
|
if self.0.is_empty() {
|
||||||
|
@ -58,15 +66,24 @@ impl ToNsCssValue for SpecifiedFontFeatureSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
nscssvalue.set_pair_list(self.0.into_iter().map(|entry| {
|
nscssvalue.set_pair_list(self.0.into_iter().map(|entry| {
|
||||||
let mut feature = nsCSSValue::null();
|
|
||||||
let mut raw = [0u8; 4];
|
|
||||||
(&mut raw[..]).write_u32::<BigEndian>(entry.tag.0).unwrap();
|
|
||||||
feature.set_string(str::from_utf8(&raw).unwrap());
|
|
||||||
|
|
||||||
let mut index = nsCSSValue::null();
|
let mut index = nsCSSValue::null();
|
||||||
index.set_integer(entry.value.value());
|
index.set_integer(entry.value.value());
|
||||||
|
(entry.tag.into(), index)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(feature, index)
|
impl ToNsCssValue for FontVariationSettings {
|
||||||
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
|
if self.0.is_empty() {
|
||||||
|
nscssvalue.set_normal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nscssvalue.set_pair_list(self.0.into_iter().map(|entry| {
|
||||||
|
let mut value = nsCSSValue::null();
|
||||||
|
value.set_number(entry.value.into());
|
||||||
|
(entry.tag.into(), value)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,11 @@ impl nsCSSValue {
|
||||||
self.set_int_internal(value.into(), nsCSSUnit::eCSSUnit_Enumerated);
|
self.set_int_internal(value.into(), nsCSSUnit::eCSSUnit_Enumerated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set to a number value
|
||||||
|
pub fn set_number(&mut self, number: f32) {
|
||||||
|
unsafe { bindings::Gecko_CSSValue_SetFloat(self, number, nsCSSUnit::eCSSUnit_Number) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Set to a url value
|
/// Set to a url value
|
||||||
pub fn set_url(&mut self, url: &SpecifiedUrl) {
|
pub fn set_url(&mut self, url: &SpecifiedUrl) {
|
||||||
unsafe { bindings::Gecko_CSSValue_SetURL(self, url.for_ffi()) }
|
unsafe { bindings::Gecko_CSSValue_SetURL(self, url.for_ffi()) }
|
||||||
|
@ -408,3 +413,11 @@ pub trait ToNsCssValue {
|
||||||
/// Convert
|
/// Convert
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue);
|
fn convert(self, nscssvalue: &mut nsCSSValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: ToNsCssValue> From<T> for nsCSSValue {
|
||||||
|
fn from(value: T) -> nsCSSValue {
|
||||||
|
let mut result = nsCSSValue::null();
|
||||||
|
value.convert(&mut result);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4746,7 +4746,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
use style::font_face::{FontDisplay, FontWeight, Source};
|
use style::font_face::{FontDisplay, FontWeight, Source};
|
||||||
use style::properties::longhands::font_language_override;
|
use style::properties::longhands::font_language_override;
|
||||||
use style::values::computed::font::FamilyName;
|
use style::values::computed::font::FamilyName;
|
||||||
use style::values::specified::font::SpecifiedFontFeatureSettings;
|
use style::values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
|
||||||
|
|
||||||
let string = unsafe { (*value).to_string() };
|
let string = unsafe { (*value).to_string() };
|
||||||
let mut input = ParserInput::new(&string);
|
let mut input = ParserInput::new(&string);
|
||||||
|
@ -4796,6 +4796,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
eCSSFontDesc_Src / Vec<Source>,
|
eCSSFontDesc_Src / Vec<Source>,
|
||||||
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
||||||
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
|
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
|
||||||
|
eCSSFontDesc_FontVariationSettings / FontVariationSettings,
|
||||||
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
||||||
eCSSFontDesc_Display / FontDisplay,
|
eCSSFontDesc_Display / FontDisplay,
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue