mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #16931 - nox:font-feature-descriptor, r=emilio
Support font-feature-settings as a @font-face descriptor <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16931) <!-- Reviewable:end -->
This commit is contained in:
commit
61d64daf4c
7 changed files with 191 additions and 124 deletions
|
@ -4,18 +4,19 @@
|
|||
|
||||
//! 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 counter_style;
|
||||
use cssparser::UnicodeRange;
|
||||
use font_face::{FontFaceRuleData, Source};
|
||||
use font_face::{FontFaceRuleData, Source, FontDisplay};
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs::{self, nsCSSFontFaceRule, nsCSSValue};
|
||||
use gecko_bindings::structs::{nsCSSCounterDesc, nsCSSCounterStyleRule};
|
||||
use gecko_bindings::sugar::ns_css_value::ToNsCssValue;
|
||||
use gecko_bindings::sugar::refptr::{RefPtr, UniqueRefPtr};
|
||||
use shared_lock::{ToCssWithGuard, SharedRwLockReadGuard};
|
||||
use std::fmt;
|
||||
use std::{fmt, str};
|
||||
|
||||
/// A @font-face rule
|
||||
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 {
|
||||
(
|
||||
$(
|
||||
|
@ -115,6 +137,18 @@ impl ToNsCssValue for Vec<UnicodeRange> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToNsCssValue for FontDisplay {
|
||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||
nscssvalue.set_enum(match self {
|
||||
FontDisplay::Auto => structs::NS_FONT_DISPLAY_AUTO,
|
||||
FontDisplay::Block => structs::NS_FONT_DISPLAY_BLOCK,
|
||||
FontDisplay::Swap => structs::NS_FONT_DISPLAY_SWAP,
|
||||
FontDisplay::Fallback => structs::NS_FONT_DISPLAY_FALLBACK,
|
||||
FontDisplay::Optional => structs::NS_FONT_DISPLAY_OPTIONAL,
|
||||
} as i32)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FontFaceRuleData> for FontFaceRule {
|
||||
fn from(data: FontFaceRuleData) -> FontFaceRule {
|
||||
let mut result = unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue