diff --git a/src/servo-gfx/geometry.rs b/src/servo-gfx/geometry.rs index f1803a7bbb4..e5835bf008b 100644 --- a/src/servo-gfx/geometry.rs +++ b/src/servo-gfx/geometry.rs @@ -22,12 +22,12 @@ impl Mul for Au { fn mul(&self, other: &Au) -> Au { Au(**self * **other) } } -impl Div for Au { - fn div(&self, other: &Au) -> Au { Au(**self / **other) } +impl Quot for Au { + fn quot(&self, other: &Au) -> Au { Au(**self / **other) } } -impl Modulo for Au { - fn modulo(&self, other: &Au) -> Au { Au(**self % **other) } +impl Rem for Au { + fn rem(&self, other: &Au) -> Au { Au(**self % **other) } } impl Neg for Au { diff --git a/src/servo-gfx/platform/linux/font_context.rs b/src/servo-gfx/platform/linux/font_context.rs index ceb5f679015..4797dddba1a 100644 --- a/src/servo-gfx/platform/linux/font_context.rs +++ b/src/servo-gfx/platform/linux/font_context.rs @@ -46,7 +46,7 @@ impl FontContextHandleMethods for FontContextHandle { fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) -> Result { debug!("Creating font handle for %s", name); - do path_from_identifier(name).chain |file_name| { + do path_from_identifier(name, &style).chain |file_name| { debug!("Opening font face %s", file_name); FontHandle::new_from_file(self, file_name, &style) } diff --git a/src/servo-gfx/platform/linux/font_list.rs b/src/servo-gfx/platform/linux/font_list.rs index 785dce2bb5c..f88df304391 100644 --- a/src/servo-gfx/platform/linux/font_list.rs +++ b/src/servo-gfx/platform/linux/font_list.rs @@ -5,18 +5,20 @@ extern mod freetype; extern mod fontconfig; -use self::fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem, - FcResultNoMatch, FcMatchPattern}; -use self::fontconfig::fontconfig::bindgen::{ +use fontconfig::fontconfig::{ + FcChar8, FcResultMatch, FcSetSystem, + FcResultNoMatch, FcMatchPattern, FC_SLANT_ITALIC, FC_WEIGHT_BOLD +}; +use fontconfig::fontconfig::bindgen::{ FcConfigGetCurrent, FcConfigGetFonts, FcPatternGetString, FcPatternDestroy, FcFontSetDestroy, FcConfigSubstitute, - FcDefaultSubstitute, FcPatternCreate, FcPatternAddString, + FcDefaultSubstitute, FcPatternCreate, FcPatternAddString, FcPatternAddInteger, FcFontMatch, FcFontSetList, FcObjectSetCreate, FcObjectSetDestroy, FcObjectSetAdd, FcPatternGetInteger }; -use font::FontHandleMethods; +use font::{FontHandleMethods, UsedFontStyle}; use font_context::FontContextHandleMethods; use font_list::{FontEntry, FontFamily, FontFamilyMap}; use platform::font::FontHandle; @@ -25,22 +27,6 @@ use platform::font_context::FontContextHandle; use core::hashmap::HashMap; use core::libc::c_int; use core::ptr::Ptr; -use fontconfig::fontconfig::bindgen::{FcConfigGetCurrent}; -use fontconfig::fontconfig::bindgen::{FcConfigGetFonts}; -use fontconfig::fontconfig::bindgen::{FcDefaultSubstitute}; -use fontconfig::fontconfig::bindgen::{FcPatternCreate}; -use fontconfig::fontconfig::bindgen::{FcFontSetDestroy}; -use fontconfig::fontconfig::bindgen::{FcConfigSubstitute}; -use fontconfig::fontconfig::bindgen::{FcFontSetList}; -use fontconfig::fontconfig::bindgen::{FcObjectSetCreate}; -use fontconfig::fontconfig::bindgen::{FcObjectSetDestroy}; -use fontconfig::fontconfig::bindgen::{FcObjectSetAdd}; -use fontconfig::fontconfig::bindgen::{FcPatternAddString, FcFontMatch}; -use fontconfig::fontconfig::bindgen::{FcPatternGetInteger}; -use fontconfig::fontconfig::bindgen::{FcPatternGetString}; -use fontconfig::fontconfig::bindgen::{FcPatternDestroy}; -use fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem}; -use fontconfig::fontconfig::{FcMatchPattern, FcResultNoMatch}; pub struct FontListHandle { fctx: FontContextHandle, @@ -138,7 +124,7 @@ pub impl FontListHandle { } } -pub fn path_from_identifier(name: ~str) -> Result<~str, ()> { +pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ()> { unsafe { let config = FcConfigGetCurrent(); let pattern = FcPatternCreate(); @@ -152,6 +138,25 @@ pub fn path_from_identifier(name: ~str) -> Result<~str, ()> { return Err(()); } + if style.italic { + let res = do str::as_c_str("slant") |FC_SLANT| { + FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) + }; + if res != 1 { + debug!("adding slant to pattern failed"); + return Err(()); + } + } + if style.weight.is_bold() { + let res = do str::as_c_str("weight") |FC_WEIGHT| { + FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD) + }; + if res != 1 { + debug!("adding weight to pattern failed"); + return Err(()); + } + } + if FcConfigSubstitute(config, pattern, FcMatchPattern) != 1 { debug!("substitution failed"); return Err(()); diff --git a/src/servo-gfx/quartz/font_context.rs b/src/servo-gfx/quartz/font_context.rs deleted file mode 100644 index ef47d2a2f10..00000000000 --- a/src/servo-gfx/quartz/font_context.rs +++ /dev/null @@ -1,38 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -extern mod core_foundation; -extern mod core_graphics; -extern mod core_text; - -use quartz; -use quartz::font::QuartzFontHandle; - -use gfx_font::{FontHandle, UsedFontStyle}; -use gfx_font_context::FontContextHandleMethods; - -pub struct QuartzFontContextHandle { - ctx: () -} - -pub impl QuartzFontContextHandle { - // this is a placeholder until NSFontManager or whatever is bound in here. - pub fn new() -> QuartzFontContextHandle { - QuartzFontContextHandle { ctx: () } - } -} - -impl FontContextHandleMethods for QuartzFontContextHandle { - fn clone(&self) -> QuartzFontContextHandle { - QuartzFontContextHandle { ctx: self.ctx } - } - - fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle) -> Result { - let ctfont_result = quartz::font_context::core_text::font::new_from_name(name, - style.pt_size); - do result::chain(ctfont_result) |ctfont| { - QuartzFontHandle::new_from_CTFont(self, ctfont) - } - } -} diff --git a/src/servo-gfx/quartz/font_list.rs b/src/servo-gfx/quartz/font_list.rs deleted file mode 100644 index bb48bf3e98a..00000000000 --- a/src/servo-gfx/quartz/font_list.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -extern mod core_foundation; -extern mod core_text; - -use native; -use quartz; -use quartz::font_list::core_foundation::array::CFArray; -use quartz::font_list::core_foundation::base::CFWrapper; -use quartz::font_list::core_foundation::string::{CFString, CFStringRef}; - -use quartz::font_list::core_text::font_descriptor::CTFontDescriptorRef; -use quartz::font_list::core_text::font_collection::CTFontCollectionMethods; - -use quartz::font::QuartzFontHandle; -use quartz::font_context::QuartzFontContextHandle; -use gfx_font::FontHandleMethods; -use gfx_font_context::FontContextHandleMethods; -use gfx_font_list::{FontEntry, FontFamily, FontFamilyMap}; - -use core::hashmap::HashMap; - -pub struct QuartzFontListHandle { - fctx: QuartzFontContextHandle, -} - -pub impl QuartzFontListHandle { - fn new(fctx: &native::FontContextHandle) -> QuartzFontListHandle { - QuartzFontListHandle { fctx: fctx.clone() } - } - - fn get_available_families(&self) -> FontFamilyMap { - let family_names: CFArray = - quartz::font_list::core_text::font_collection::get_family_names(); - let mut family_map : FontFamilyMap = HashMap::new(); - for family_names.each |&strref: &CFStringRef| { - let family_name = CFString::wrap_extern(strref).to_str(); - debug!("Creating new FontFamily for family: %s", family_name); - - let new_family = @mut FontFamily::new(family_name); - family_map.insert(family_name, new_family); - } - return family_map; - } - - fn load_variations_for_family(&self, family: @mut FontFamily) { - let fam : &mut FontFamily = family; // FIXME: borrow checker workaround - let family_name = &fam.family_name; - debug!("Looking for faces of family: %s", *family_name); - - let family_collection = - quartz::font_list::core_text::font_collection::create_for_family(*family_name); - for family_collection.get_descriptors().each |descref: &CTFontDescriptorRef| { - let desc = CFWrapper::wrap_shared(*descref); - let font = quartz::font_list::core_text::font::new_from_descriptor(&desc, 0.0); - let handle = result::unwrap(QuartzFontHandle::new_from_CTFont(&self.fctx, font)); - - debug!("Creating new FontEntry for face: %s", handle.face_name()); - let entry = @FontEntry::new(family, handle); - family.entries.push(entry); - } - } -}