mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Merge pull request #394 from metajack/linux-font-styles
Fix linux font styles.
This commit is contained in:
commit
bf0f401e3a
5 changed files with 32 additions and 130 deletions
|
@ -22,12 +22,12 @@ impl Mul<Au,Au> for Au {
|
||||||
fn mul(&self, other: &Au) -> Au { Au(**self * **other) }
|
fn mul(&self, other: &Au) -> Au { Au(**self * **other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Div<Au,Au> for Au {
|
impl Quot<Au,Au> for Au {
|
||||||
fn div(&self, other: &Au) -> Au { Au(**self / **other) }
|
fn quot(&self, other: &Au) -> Au { Au(**self / **other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Modulo<Au,Au> for Au {
|
impl Rem<Au,Au> for Au {
|
||||||
fn modulo(&self, other: &Au) -> Au { Au(**self % **other) }
|
fn rem(&self, other: &Au) -> Au { Au(**self % **other) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Neg<Au> for Au {
|
impl Neg<Au> for Au {
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl FontContextHandleMethods for FontContextHandle {
|
||||||
fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)
|
fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)
|
||||||
-> Result<FontHandle, ()> {
|
-> Result<FontHandle, ()> {
|
||||||
debug!("Creating font handle for %s", name);
|
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);
|
debug!("Opening font face %s", file_name);
|
||||||
FontHandle::new_from_file(self, file_name, &style)
|
FontHandle::new_from_file(self, file_name, &style)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,20 @@
|
||||||
extern mod freetype;
|
extern mod freetype;
|
||||||
extern mod fontconfig;
|
extern mod fontconfig;
|
||||||
|
|
||||||
use self::fontconfig::fontconfig::{FcChar8, FcResultMatch, FcSetSystem,
|
use fontconfig::fontconfig::{
|
||||||
FcResultNoMatch, FcMatchPattern};
|
FcChar8, FcResultMatch, FcSetSystem,
|
||||||
use self::fontconfig::fontconfig::bindgen::{
|
FcResultNoMatch, FcMatchPattern, FC_SLANT_ITALIC, FC_WEIGHT_BOLD
|
||||||
|
};
|
||||||
|
use fontconfig::fontconfig::bindgen::{
|
||||||
FcConfigGetCurrent, FcConfigGetFonts, FcPatternGetString,
|
FcConfigGetCurrent, FcConfigGetFonts, FcPatternGetString,
|
||||||
FcPatternDestroy, FcFontSetDestroy, FcConfigSubstitute,
|
FcPatternDestroy, FcFontSetDestroy, FcConfigSubstitute,
|
||||||
FcDefaultSubstitute, FcPatternCreate, FcPatternAddString,
|
FcDefaultSubstitute, FcPatternCreate, FcPatternAddString, FcPatternAddInteger,
|
||||||
FcFontMatch, FcFontSetList, FcObjectSetCreate, FcObjectSetDestroy,
|
FcFontMatch, FcFontSetList, FcObjectSetCreate, FcObjectSetDestroy,
|
||||||
FcObjectSetAdd, FcPatternGetInteger
|
FcObjectSetAdd, FcPatternGetInteger
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
use font::FontHandleMethods;
|
use font::{FontHandleMethods, UsedFontStyle};
|
||||||
use font_context::FontContextHandleMethods;
|
use font_context::FontContextHandleMethods;
|
||||||
use font_list::{FontEntry, FontFamily, FontFamilyMap};
|
use font_list::{FontEntry, FontFamily, FontFamilyMap};
|
||||||
use platform::font::FontHandle;
|
use platform::font::FontHandle;
|
||||||
|
@ -25,22 +27,6 @@ use platform::font_context::FontContextHandle;
|
||||||
use core::hashmap::HashMap;
|
use core::hashmap::HashMap;
|
||||||
use core::libc::c_int;
|
use core::libc::c_int;
|
||||||
use core::ptr::Ptr;
|
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 {
|
pub struct FontListHandle {
|
||||||
fctx: FontContextHandle,
|
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 {
|
unsafe {
|
||||||
let config = FcConfigGetCurrent();
|
let config = FcConfigGetCurrent();
|
||||||
let pattern = FcPatternCreate();
|
let pattern = FcPatternCreate();
|
||||||
|
@ -152,6 +138,25 @@ pub fn path_from_identifier(name: ~str) -> Result<~str, ()> {
|
||||||
return Err(());
|
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 {
|
if FcConfigSubstitute(config, pattern, FcMatchPattern) != 1 {
|
||||||
debug!("substitution failed");
|
debug!("substitution failed");
|
||||||
return Err(());
|
return Err(());
|
||||||
|
|
|
@ -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<FontHandle, ()> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<CFStringRef> =
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue