mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Pass font style on to font config pattern search.
This commit is contained in:
parent
5e4d59423b
commit
b33970d0be
2 changed files with 28 additions and 23 deletions
|
@ -46,7 +46,7 @@ impl FontContextHandleMethods for FontContextHandle {
|
|||
fn create_font_from_identifier(&self, name: ~str, style: UsedFontStyle)
|
||||
-> Result<FontHandle, ()> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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(());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue