diff options
author | Boris Chiou <boris.chiou@gmail.com> | 2017-12-05 13:47:36 +0800 |
---|---|---|
committer | Boris Chiou <boris.chiou@gmail.com> | 2017-12-05 21:33:07 +0800 |
commit | 1e29e64000b0ccc49b8e23f1105c24cd22cbff44 (patch) | |
tree | 917d8f918a3a95dadee5b65223a3bf00495b2a75 /ports | |
parent | 8f30880d362ef54a2c6881c4927b96303ff763ef (diff) | |
download | servo-1e29e64000b0ccc49b8e23f1105c24cd22cbff44.tar.gz servo-1e29e64000b0ccc49b8e23f1105c24cd22cbff44.zip |
Implement the Servo parser for font descriptors Web API.
According to the spec, this parser should follow what we do for
@font_face rule, so we use the same type to parse the input, instead of
using the parser of their specified values.
Diffstat (limited to 'ports')
-rw-r--r-- | ports/geckolib/glue.rs | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 8ccd2895f22..46b0dbb5607 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -77,6 +77,7 @@ use style::gecko_bindings::bindings::RawServoDeclarationBlockBorrowedOrNull; use style::gecko_bindings::bindings::RawServoStyleRuleBorrowed; use style::gecko_bindings::bindings::RawServoStyleSet; use style::gecko_bindings::bindings::ServoStyleContextBorrowedOrNull; +use style::gecko_bindings::bindings::nsCSSValueBorrowedMut; use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; use style::gecko_bindings::bindings::nsTimingFunctionBorrowed; use style::gecko_bindings::bindings::nsTimingFunctionBorrowedMut; @@ -85,7 +86,7 @@ use style::gecko_bindings::structs::{CallerType, CSSPseudoElementType, Composite use style::gecko_bindings::structs::{Loader, LoaderReusableStyleSheets}; use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong, RustString}; use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsAtom, nsCSSPropertyID}; -use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule}; +use style::gecko_bindings::structs::{nsCSSFontDesc, nsCSSFontFaceRule, nsCSSCounterStyleRule}; use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair}; use style::gecko_bindings::structs::AtomArray; use style::gecko_bindings::structs::IterationCompositeOperation; @@ -4734,6 +4735,81 @@ pub extern "C" fn Servo_ParseTransformIntoMatrix( true } +// https://drafts.csswg.org/css-font-loading/#dom-fontface-fontface +#[no_mangle] +pub extern "C" fn Servo_ParseFontDescriptor( + desc_id: nsCSSFontDesc, + value: *const nsAString, + data: *mut URLExtraData, + result: nsCSSValueBorrowedMut, +) -> bool { + use cssparser::UnicodeRange; + use self::nsCSSFontDesc::*; + use style::computed_values::{font_feature_settings, font_stretch, font_style}; + use style::font_face::{FontDisplay, FontWeight, Source}; + use style::properties::longhands::font_language_override; + use style::values::computed::font::FamilyName; + + let string = unsafe { (*value).to_string() }; + let mut input = ParserInput::new(&string); + let mut parser = Parser::new(&mut input); + let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; + let context = ParserContext::new( + Origin::Author, + url_data, + Some(CssRuleType::FontFace), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); + + macro_rules! parse_font_desc { + ( + valid = [ $( $v_enum_name: ident / $t: ty, )* ] + invalid = [ $( $i_enum_name: ident, )* ] + ) => { + match desc_id { + $( + $v_enum_name => { + let f = match parser.parse_entirely(|i| <$t as Parse>::parse(&context, i)) { + Ok(f) => f, + Err(..) => return false, + }; + result.set_from(f); + }, + )* + $( + $i_enum_name => { + debug_assert!(false, "$i_enum_name is not a valid font descriptor"); + return false; + }, + )* + } + } + } + + // We implement the parser of each arm according to the implementation of @font-face rule. + // see component/style/font_face.rs for more detail. + parse_font_desc!( + valid = [ + eCSSFontDesc_Family / FamilyName, + eCSSFontDesc_Style / font_style::T, + eCSSFontDesc_Weight / FontWeight, + eCSSFontDesc_Stretch / font_stretch::T, + eCSSFontDesc_Src / Vec<Source>, + eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>, + eCSSFontDesc_FontFeatureSettings / font_feature_settings::T, + eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue, + eCSSFontDesc_Display / FontDisplay, + ] + invalid = [ + eCSSFontDesc_UNKNOWN, + eCSSFontDesc_COUNT, + ] + ); + + true +} + #[no_mangle] pub unsafe extern "C" fn Servo_SourceSizeList_Parse( value: *const nsACString, |