aboutsummaryrefslogtreecommitdiffstats
path: root/ports
diff options
context:
space:
mode:
authorBoris Chiou <boris.chiou@gmail.com>2017-12-05 13:50:50 +0800
committerBoris Chiou <boris.chiou@gmail.com>2017-12-05 21:33:14 +0800
commitaa52e644fe69fcd59b43f77dd5db4bd0f5678182 (patch)
tree1a049e1579f0bcf76849a026107b6b764f5ae7c1 /ports
parent1e29e64000b0ccc49b8e23f1105c24cd22cbff44 (diff)
downloadservo-aa52e644fe69fcd59b43f77dd5db4bd0f5678182.tar.gz
servo-aa52e644fe69fcd59b43f77dd5db4bd0f5678182.zip
Implement the Servo parser for FontFaceSet Web API.
Diffstat (limited to 'ports')
-rw-r--r--ports/geckolib/glue.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs
index 46b0dbb5607..fdd491985f1 100644
--- a/ports/geckolib/glue.rs
+++ b/ports/geckolib/glue.rs
@@ -4811,6 +4811,64 @@ pub extern "C" fn Servo_ParseFontDescriptor(
}
#[no_mangle]
+pub extern "C" fn Servo_ParseFontShorthandForMatching(
+ value: *const nsAString,
+ data: *mut URLExtraData,
+ family: *mut structs::RefPtr<structs::SharedFontList>,
+ style: nsCSSValueBorrowedMut,
+ stretch: nsCSSValueBorrowedMut,
+ weight: nsCSSValueBorrowedMut
+) -> bool {
+ use style::properties::longhands::{font_stretch, font_style};
+ use style::properties::shorthands::font;
+ use style::values::specified::font::{FontFamily, FontWeight};
+
+ 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,
+ );
+
+ let font = match parser.parse_entirely(|f| font::parse_value(&context, f)) {
+ Ok(f) => f,
+ Err(..) => return false,
+ };
+
+ // The system font is not acceptable, so we return false.
+ let family = unsafe { &mut *family };
+ match font.font_family {
+ FontFamily::Values(list) => family.set_move(list.0),
+ FontFamily::System(_) => return false,
+ }
+ style.set_from(match font.font_style {
+ font_style::SpecifiedValue::Keyword(kw) => kw,
+ font_style::SpecifiedValue::System(_) => return false,
+ });
+ stretch.set_from(match font.font_stretch {
+ font_stretch::SpecifiedValue::Keyword(kw) => kw,
+ font_stretch::SpecifiedValue::System(_) => return false,
+ });
+ match font.font_weight {
+ FontWeight::Weight(w) => weight.set_from(w),
+ FontWeight::Normal => weight.set_enum(structs::NS_STYLE_FONT_WEIGHT_NORMAL as i32),
+ FontWeight::Bold => weight.set_enum(structs::NS_STYLE_FONT_WEIGHT_BOLD as i32),
+ // Resolve relative font weights against the initial of font-weight
+ // (normal, which is equivalent to 400).
+ FontWeight::Bolder => weight.set_enum(structs::NS_FONT_WEIGHT_BOLD as i32),
+ FontWeight::Lighter => weight.set_enum(structs::NS_FONT_WEIGHT_THIN as i32),
+ FontWeight::System(_) => return false,
+ }
+
+ true
+}
+
+#[no_mangle]
pub unsafe extern "C" fn Servo_SourceSizeList_Parse(
value: *const nsACString,
) -> *mut RawServoSourceSizeList {