aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/layout/layout_task.rs
diff options
context:
space:
mode:
authorGlenn Watson <gw@intuitionlibrary.com>2014-07-08 14:55:38 +1000
committerGlenn Watson <gw@intuitionlibrary.com>2014-07-24 13:24:22 +1000
commit4e949cb58c9f91426dba32ce0359213edd752629 (patch)
tree137614f8d763c50e4cef494a64671f29380204ca /src/components/layout/layout_task.rs
parent4b689caa5d374778e8169e8253a7b903a5c6dfa1 (diff)
downloadservo-4e949cb58c9f91426dba32ce0359213edd752629.tar.gz
servo-4e949cb58c9f91426dba32ce0359213edd752629.zip
Add basic support for web fonts. Synchronous loading only
for now, and only deals with TTF format fonts. For an example, try loading http://icons.marekventur.de
Diffstat (limited to 'src/components/layout/layout_task.rs')
-rw-r--r--src/components/layout/layout_task.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/components/layout/layout_task.rs b/src/components/layout/layout_task.rs
index bed0096ff69..eb7cfade084 100644
--- a/src/components/layout/layout_task.rs
+++ b/src/components/layout/layout_task.rs
@@ -60,6 +60,8 @@ use std::mem;
use std::ptr;
use std::task::TaskBuilder;
use style::{AuthorOrigin, Stylesheet, Stylist};
+use style::CSSFontFaceRule;
+use style::TtfFormat;
use sync::{Arc, Mutex};
use url::Url;
@@ -450,7 +452,26 @@ impl LayoutTask {
}
fn handle_add_stylesheet(&mut self, sheet: Stylesheet) {
- self.stylist.add_stylesheet(sheet, AuthorOrigin)
+ // Find all font-face rules and notify the font cache of them.
+ // GWTODO: Need to handle unloading web fonts (when we handle unloading stylesheets!)
+ // GWTODO: Need to handle font-face nested within media rules.
+ for rule in sheet.rules.iter() {
+ match rule {
+ &CSSFontFaceRule(ref font_face_rule) => {
+ for source in font_face_rule.sources.iter() {
+ match source.format {
+ TtfFormat => {
+ self.font_cache_task.add_web_font(source.url.clone(), font_face_rule.family.as_slice());
+ },
+ _ => {}
+ }
+ }
+ },
+ _ => {}
+ }
+ }
+
+ self.stylist.add_stylesheet(sheet, AuthorOrigin);
}
/// Retrieves the flow tree root from the root node.