diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index add281b48ab..8096b9cb622 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -15,7 +15,7 @@ use std::rc::RcMut; use servo_util::cache::{Cache, HashCache}; use servo_util::range::Range; use servo_util::time::ProfilerChan; -use style::computed_values::{text_decoration, font_weight}; +use style::computed_values::{text_decoration, font_weight, font_style}; use color::Color; use font_context::FontContext; @@ -100,9 +100,8 @@ pub struct FontMetrics { pub struct FontStyle { pt_size: f64, weight: font_weight::T, - italic: bool, - oblique: bool, - families: ~str, + style: font_style::T, + families: ~[~str], // TODO(Issue #198): font-stretch, text-decoration, font-variant, size-adjust } @@ -150,7 +149,7 @@ pub enum FontSelector { // The ordering of font instances is mainly decided by the CSS // 'font-family' property. The last font is a system fallback font. pub struct FontGroup { - families: ~str, + families: ~[~str], // style of the first western font in group, which is // used for purposes of calculating text run metrics. style: UsedFontStyle, @@ -158,7 +157,7 @@ pub struct FontGroup { } impl FontGroup { - pub fn new(families: ~str, style: &UsedFontStyle, fonts: ~[RcMut]) -> FontGroup { + pub fn new(families: ~[~str], style: &UsedFontStyle, fonts: ~[RcMut]) -> FontGroup { FontGroup { families: families, style: (*style).clone(), diff --git a/src/components/gfx/font_context.rs b/src/components/gfx/font_context.rs index 707fb11d328..5493cf7c9b4 100644 --- a/src/components/gfx/font_context.rs +++ b/src/components/gfx/font_context.rs @@ -99,12 +99,10 @@ impl<'self> FontContext { } } - fn transform_family(&self, family: &str) -> ~str { - // FIXME: Need a find_like() in HashMap. - let family = family.to_str(); - debug!("(transform family) searching for `{:s}`", family); - match self.generic_fonts.find(&family) { - None => family, + fn transform_family(&self, family: &~str) -> ~str { + debug!("(transform family) searching for `{:s}`", family.as_slice()); + match self.generic_fonts.find(family) { + None => family.to_owned(), Some(mapped_family) => (*mapped_family).clone() } } @@ -115,9 +113,8 @@ impl<'self> FontContext { debug!("(create font group) --- starting ---"); // TODO(Issue #193): make iteration over 'font-family' more robust. - for family in style.families.split_iter(',') { - let family_name = family.trim(); - let transformed_family_name = self.transform_family(family_name); + for family in style.families.iter() { + let transformed_family_name = self.transform_family(family); debug!("(create font group) transformed family is `{:s}`", transformed_family_name); let mut found = false; @@ -197,7 +194,7 @@ impl<'self> FontContext { debug!("(create font group) --- finished ---"); - unsafe { RcMut::new_unchecked(FontGroup::new(style.families.to_owned(), &used_style, fonts)) } + unsafe { RcMut::new_unchecked(FontGroup::new(style.families.clone(), &used_style, fonts)) } } fn create_font_instance(&self, desc: &FontDescriptor) -> Result, ()> { diff --git a/src/components/gfx/font_list.rs b/src/components/gfx/font_list.rs index c280ae30c7d..543610bb517 100644 --- a/src/components/gfx/font_list.rs +++ b/src/components/gfx/font_list.rs @@ -10,7 +10,7 @@ use platform::font_list::FontListHandle; use servo_util::time; use servo_util::time::profile; use servo_util::time::ProfilerChan; -use style::computed_values::font_weight; +use style::computed_values::{font_weight, font_style}; use std::hashmap::HashMap; @@ -115,8 +115,8 @@ impl<'self> FontFamily { // TODO(Issue #190): if not in the fast path above, do // expensive matching of weights, etc. for entry in self.entries.iter() { - if (style.weight.is_bold() == entry.is_bold()) && - (style.italic == entry.is_italic()) { + if (style.weight.is_bold() == entry.is_bold()) && + ((style.style == font_style::italic) == entry.is_italic()) { return Some(entry); } diff --git a/src/components/gfx/platform/android/font_list.rs b/src/components/gfx/platform/android/font_list.rs index 87a355e35b9..3d538c9876d 100644 --- a/src/components/gfx/platform/android/font_list.rs +++ b/src/components/gfx/platform/android/font_list.rs @@ -17,6 +17,8 @@ use fontconfig::fontconfig::{ FcObjectSetAdd, FcPatternGetInteger }; +use style::computed_values::font_style; + use font::{FontHandleMethods, UsedFontStyle}; use font_context::FontContextHandleMethods; @@ -164,23 +166,25 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( return Err(()); } - if style.italic { - let res = do "slant".to_c_str().with_ref |FC_SLANT| { - FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) - }; - if res != 1 { - debug!("adding slant(italic) to pattern failed"); - return Err(()); - } - } - - if style.oblique { - let res = do "slant".to_c_str().with_ref |FC_SLANT| { - FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_OBLIQUE) - }; - if res != 1 { - debug!("adding slant(oblique) to pattern failed"); - return Err(()); + match style.style { + font_style::normal => (), + font_style::italic => { + let res = do "slant".to_c_str().with_ref |FC_SLANT| { + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) + }; + if res != 1 { + debug!("adding slant to pattern failed"); + return Err(()); + } + }, + font_style::oblique => { + let res = do "slant".to_c_str().with_ref |FC_SLANT| { + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_OBLIQUE) + }; + if res != 1 { + debug!("adding slant(oblique) to pattern failed"); + return Err(()); + } } } diff --git a/src/components/gfx/platform/linux/font_list.rs b/src/components/gfx/platform/linux/font_list.rs index 2c9c734da6c..61838a44683 100644 --- a/src/components/gfx/platform/linux/font_list.rs +++ b/src/components/gfx/platform/linux/font_list.rs @@ -17,6 +17,8 @@ use fontconfig::fontconfig::{ FcObjectSetAdd, FcPatternGetInteger }; +use style::computed_values::font_style; + use font::{FontHandleMethods, UsedFontStyle}; use font_list::{FontEntry, FontFamily, FontFamilyMap}; @@ -163,23 +165,25 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( return Err(()); } - if style.italic { - let res = do "slant".to_c_str().with_ref |FC_SLANT| { - FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) - }; - if res != 1 { - debug!("adding slant(italic) to pattern failed"); - return Err(()); - } - } - - if style.oblique { - let res = do "slant".to_c_str().with_ref |FC_SLANT| { - FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_OBLIQUE) - }; - if res != 1 { - debug!("adding slant(oblique) to pattern failed"); - return Err(()); + match style.style { + font_style::normal => (), + font_style::italic => { + let res = do "slant".to_c_str().with_ref |FC_SLANT| { + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) + }; + if res != 1 { + debug!("adding slant to pattern failed"); + return Err(()); + } + }, + font_style::oblique => { + let res = do "slant".to_c_str().with_ref |FC_SLANT| { + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_OBLIQUE) + }; + if res != 1 { + debug!("adding slant(oblique) to pattern failed"); + return Err(()); + } } } diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index d8721f68267..145bb95b039 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -29,7 +29,7 @@ use std::cmp::ApproxEq; use std::num::Zero; use style::{ComputedValues, TElement, TNode}; use style::computed_values::{LengthOrPercentage, overflow}; -use style::computed_values::{border_style, clear, font_family, font_style, line_height}; +use style::computed_values::{border_style, clear, font_family, line_height}; use style::computed_values::{text_align, text_decoration, vertical_align, visibility}; use css::node_style::StyledNode; @@ -404,25 +404,15 @@ impl Box { font_family::FamilyName(ref name) => (*name).clone(), } }; - let font_families = font_families.connect(", "); - debug!("(font style) font families: `{:s}`", font_families); + debug!("(font style) font families: `{:?}`", font_families); let font_size = my_style.Font.font_size.to_f64().unwrap() / 60.0; debug!("(font style) font size: `{:f}px`", font_size); - let (italic, oblique) = match my_style.Font.font_style { - font_style::normal => (false, false), - font_style::italic => (true, false), - font_style::oblique => (false, true), - }; - - let font_weight = my_style.Font.font_weight; - FontStyle { pt_size: font_size, - weight: font_weight, - italic: italic, - oblique: oblique, + weight: my_style.Font.font_weight, + style: my_style.Font.font_style, families: font_families, } }