Skip to content

Commit

Permalink
Integrate font-variation-settings descriptor with stylo
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed Feb 14, 2018
1 parent 4c3f175 commit 6ffa888
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 18 deletions.
15 changes: 13 additions & 2 deletions components/style/font_face.rs
Expand Up @@ -26,7 +26,7 @@ use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
use style_traits::{StyleParseErrorKind, ToCss};
use values::computed::font::FamilyName;
#[cfg(feature = "gecko")]
use values::specified::font::SpecifiedFontFeatureSettings;
use values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
use values::specified::url::SpecifiedUrl;

/// A source for a font-face rule.
Expand Down Expand Up @@ -235,6 +235,12 @@ macro_rules! is_descriptor_enabled {
mozilla::StylePrefs_sFontDisplayEnabled
}
};
("font-variation-settings") => {
unsafe {
use gecko_bindings::structs::mozilla;
mozilla::StylePrefs_sFontVariationsEnabled
}
};
($name: tt) => { true }
}

Expand All @@ -245,7 +251,7 @@ macro_rules! font_face_descriptors_common {
/// Data inside a `@font-face` rule.
///
/// <https://drafts.csswg.org/css-fonts/#font-face-rule>
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct FontFaceRuleData {
$(
#[$doc]
Expand Down Expand Up @@ -405,6 +411,11 @@ font_face_descriptors! {
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.
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue = {
font_language_override::SpecifiedValue::Normal
Expand Down
3 changes: 3 additions & 0 deletions components/style/gecko/generated/bindings.rs
Expand Up @@ -1471,6 +1471,9 @@ extern "C" {
extern "C" {
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" {
pub fn Gecko_CSSValue_SetPair(
css_value: nsCSSValueBorrowedMut,
Expand Down
35 changes: 27 additions & 8 deletions components/style/gecko/generated/structs.rs
Expand Up @@ -10230,6 +10230,10 @@ pub mod root {
#[link_name = "\u{1}_ZN7mozilla10StylePrefs32sGridTemplateSubgridValueEnabledE"]
pub static mut StylePrefs_sGridTemplateSubgridValueEnabled: bool;
}
extern "C" {
#[link_name = "\u{1}_ZN7mozilla10StylePrefs22sFontVariationsEnabledE"]
pub static mut StylePrefs_sFontVariationsEnabled: bool;
}
extern "C" {
#[link_name = "\u{1}_ZN7mozilla10StylePrefs22sEmulateMozBoxWithFlexE"]
pub static mut StylePrefs_sEmulateMozBoxWithFlex: bool;
Expand Down Expand Up @@ -11885,6 +11889,7 @@ pub mod root {
pub mSrc: root::nsCSSValue,
pub mUnicodeRange: root::nsCSSValue,
pub mFontFeatureSettings: root::nsCSSValue,
pub mFontVariationSettings: root::nsCSSValue,
pub mFontLanguageOverride: root::nsCSSValue,
pub mDisplay: root::nsCSSValue,
}
Expand All @@ -11896,7 +11901,7 @@ pub mod root {
fn bindgen_test_layout_CSSFontFaceDescriptors() {
assert_eq!(
::std::mem::size_of::<CSSFontFaceDescriptors>(),
144usize,
160usize,
concat!("Size of: ", stringify!(CSSFontFaceDescriptors))
);
assert_eq!(
Expand Down Expand Up @@ -11992,10 +11997,23 @@ pub mod root {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontLanguageOverride
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontVariationSettings
as *const _ as usize
},
112usize,
concat!(
"Offset of field: ",
stringify!(CSSFontFaceDescriptors),
"::",
stringify!(mFontVariationSettings)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mFontLanguageOverride
as *const _ as usize
},
128usize,
concat!(
"Offset of field: ",
stringify!(CSSFontFaceDescriptors),
Expand All @@ -12007,7 +12025,7 @@ pub mod root {
unsafe {
&(*(::std::ptr::null::<CSSFontFaceDescriptors>())).mDisplay as *const _ as usize
},
128usize,
144usize,
concat!(
"Offset of field: ",
stringify!(CSSFontFaceDescriptors),
Expand Down Expand Up @@ -21749,9 +21767,10 @@ pub mod root {
eCSSFontDesc_Src = 4,
eCSSFontDesc_UnicodeRange = 5,
eCSSFontDesc_FontFeatureSettings = 6,
eCSSFontDesc_FontLanguageOverride = 7,
eCSSFontDesc_Display = 8,
eCSSFontDesc_COUNT = 9,
eCSSFontDesc_FontVariationSettings = 7,
eCSSFontDesc_FontLanguageOverride = 8,
eCSSFontDesc_Display = 9,
eCSSFontDesc_COUNT = 10,
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -37537,7 +37556,7 @@ pub mod root {
fn bindgen_test_layout_nsCSSFontFaceStyleDecl() {
assert_eq!(
::std::mem::size_of::<nsCSSFontFaceStyleDecl>(),
176usize,
192usize,
concat!("Size of: ", stringify!(nsCSSFontFaceStyleDecl))
);
assert_eq!(
Expand Down Expand Up @@ -37599,7 +37618,7 @@ pub mod root {
fn bindgen_test_layout_nsCSSFontFaceRule() {
assert_eq!(
::std::mem::size_of::<nsCSSFontFaceRule>(),
240usize,
256usize,
concat!("Size of: ", stringify!(nsCSSFontFaceRule))
);
assert_eq!(
Expand Down
31 changes: 24 additions & 7 deletions components/style/gecko/rules.rs
Expand Up @@ -21,7 +21,7 @@ use std::fmt::{self, Write};
use std::str;
use str::CssStringWriter;
use values::computed::font::FamilyName;
use values::specified::font::SpecifiedFontFeatureSettings;
use values::specified::font::{FontTag, FontVariationSettings, SpecifiedFontFeatureSettings};

/// A @font-face rule
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
Expand Down Expand Up @@ -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 {
fn convert(self, nscssvalue: &mut nsCSSValue) {
if self.0.is_empty() {
Expand All @@ -58,15 +66,24 @@ impl ToNsCssValue for SpecifiedFontFeatureSettings {
}

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();
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)
}))
}
}
Expand Down
13 changes: 13 additions & 0 deletions components/style/gecko_bindings/sugar/ns_css_value.rs
Expand Up @@ -205,6 +205,11 @@ impl nsCSSValue {
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
pub fn set_url(&mut self, url: &SpecifiedUrl) {
unsafe { bindings::Gecko_CSSValue_SetURL(self, url.for_ffi()) }
Expand Down Expand Up @@ -408,3 +413,11 @@ pub trait ToNsCssValue {
/// Convert
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
}
}
3 changes: 2 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -4746,7 +4746,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
use style::font_face::{FontDisplay, FontWeight, Source};
use style::properties::longhands::font_language_override;
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 mut input = ParserInput::new(&string);
Expand Down Expand Up @@ -4796,6 +4796,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
eCSSFontDesc_Src / Vec<Source>,
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
eCSSFontDesc_FontVariationSettings / FontVariationSettings,
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
eCSSFontDesc_Display / FontDisplay,
]
Expand Down

0 comments on commit 6ffa888

Please sign in to comment.