mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Define constant parameters strings as statics.
This commit is contained in:
parent
cc24e68186
commit
d218815394
1 changed files with 11 additions and 21 deletions
|
@ -25,6 +25,10 @@ use libc::c_int;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::string;
|
use std::string;
|
||||||
|
|
||||||
|
static FC_FAMILY: &'static [u8] = b"family\0";
|
||||||
|
static FC_FILE: &'static [u8] = b"file\0";
|
||||||
|
static FC_INDEX: &'static [u8] = b"index\0";
|
||||||
|
|
||||||
pub fn get_available_families(callback: |String|) {
|
pub fn get_available_families(callback: |String|) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let config = FcConfigGetCurrent();
|
let config = FcConfigGetCurrent();
|
||||||
|
@ -33,9 +37,7 @@ pub fn get_available_families(callback: |String|) {
|
||||||
let font = (*fontSet).fonts.offset(i);
|
let font = (*fontSet).fonts.offset(i);
|
||||||
let mut family: *mut FcChar8 = ptr::mut_null();
|
let mut family: *mut FcChar8 = ptr::mut_null();
|
||||||
let mut v: c_int = 0;
|
let mut v: c_int = 0;
|
||||||
let mut FC_FAMILY_C = "family".to_c_str();
|
while FcPatternGetString(*font, FC_FAMILY.as_ptr() as *mut i8, v, &mut family) == FcResultMatch {
|
||||||
let FC_FAMILY = FC_FAMILY_C.as_mut_ptr();
|
|
||||||
while FcPatternGetString(*font, FC_FAMILY, v, &mut family) == FcResultMatch {
|
|
||||||
let family_name = string::raw::from_buf(family as *const i8 as *const u8);
|
let family_name = string::raw::from_buf(family as *const i8 as *const u8);
|
||||||
callback(family_name);
|
callback(family_name);
|
||||||
v += 1;
|
v += 1;
|
||||||
|
@ -52,22 +54,16 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
||||||
let font_set_array_ptr = &mut font_set;
|
let font_set_array_ptr = &mut font_set;
|
||||||
let pattern = FcPatternCreate();
|
let pattern = FcPatternCreate();
|
||||||
assert!(pattern.is_not_null());
|
assert!(pattern.is_not_null());
|
||||||
let mut FC_FAMILY_C = "family".to_c_str();
|
|
||||||
let FC_FAMILY = FC_FAMILY_C.as_mut_ptr();
|
|
||||||
let mut family_name_c = family_name.to_c_str();
|
let mut family_name_c = family_name.to_c_str();
|
||||||
let family_name = family_name_c.as_mut_ptr();
|
let family_name = family_name_c.as_mut_ptr();
|
||||||
let ok = FcPatternAddString(pattern, FC_FAMILY, family_name as *mut FcChar8);
|
let ok = FcPatternAddString(pattern, FC_FAMILY.as_ptr() as *mut i8, family_name as *mut FcChar8);
|
||||||
assert!(ok != 0);
|
assert!(ok != 0);
|
||||||
|
|
||||||
let object_set = FcObjectSetCreate();
|
let object_set = FcObjectSetCreate();
|
||||||
assert!(object_set.is_not_null());
|
assert!(object_set.is_not_null());
|
||||||
|
|
||||||
let mut FC_FILE_C = "file".to_c_str();
|
FcObjectSetAdd(object_set, FC_FILE.as_ptr() as *mut i8);
|
||||||
let FC_FILE = FC_FILE_C.as_mut_ptr();
|
FcObjectSetAdd(object_set, FC_INDEX.as_ptr() as *mut i8);
|
||||||
FcObjectSetAdd(object_set, FC_FILE);
|
|
||||||
let mut FC_INDEX_C = "index".to_c_str();
|
|
||||||
let FC_INDEX = FC_INDEX_C.as_mut_ptr();
|
|
||||||
FcObjectSetAdd(object_set, FC_INDEX);
|
|
||||||
|
|
||||||
let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set);
|
let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set);
|
||||||
|
|
||||||
|
@ -75,18 +71,14 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
||||||
|
|
||||||
for i in range(0, (*matches).nfont as int) {
|
for i in range(0, (*matches).nfont as int) {
|
||||||
let font = (*matches).fonts.offset(i);
|
let font = (*matches).fonts.offset(i);
|
||||||
let mut FC_FILE_C = "file".to_c_str();
|
|
||||||
let FC_FILE = FC_FILE_C.as_mut_ptr();
|
|
||||||
let mut file: *mut FcChar8 = ptr::mut_null();
|
let mut file: *mut FcChar8 = ptr::mut_null();
|
||||||
let file = if FcPatternGetString(*font, FC_FILE, 0, &mut file) == FcResultMatch {
|
let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut i8, 0, &mut file) == FcResultMatch {
|
||||||
string::raw::from_buf(file as *const i8 as *const u8)
|
string::raw::from_buf(file as *const i8 as *const u8)
|
||||||
} else {
|
} else {
|
||||||
fail!();
|
fail!();
|
||||||
};
|
};
|
||||||
let mut FC_INDEX_C = "index".to_c_str();
|
|
||||||
let FC_INDEX = FC_INDEX_C.as_mut_ptr();
|
|
||||||
let mut index: libc::c_int = 0;
|
let mut index: libc::c_int = 0;
|
||||||
let index = if FcPatternGetInteger(*font, FC_INDEX, 0, &mut index) == FcResultMatch {
|
let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut i8, 0, &mut index) == FcResultMatch {
|
||||||
index
|
index
|
||||||
} else {
|
} else {
|
||||||
fail!();
|
fail!();
|
||||||
|
@ -118,10 +110,8 @@ pub fn get_system_default_family(generic_name: &str) -> Option<String> {
|
||||||
let family_match = FcFontMatch(ptr::mut_null(), pattern, &mut result);
|
let family_match = FcFontMatch(ptr::mut_null(), pattern, &mut result);
|
||||||
|
|
||||||
let family_name = if result == FcResultMatch {
|
let family_name = if result == FcResultMatch {
|
||||||
let mut FC_FAMILY_C = "family".to_c_str();
|
|
||||||
let FC_FAMILY = FC_FAMILY_C.as_mut_ptr();
|
|
||||||
let mut match_string: *mut FcChar8 = ptr::mut_null();
|
let mut match_string: *mut FcChar8 = ptr::mut_null();
|
||||||
FcPatternGetString(family_match, FC_FAMILY, 0, &mut match_string);
|
FcPatternGetString(family_match, FC_FAMILY.as_ptr() as *mut i8, 0, &mut match_string);
|
||||||
let result = string::raw::from_buf(match_string as *const i8 as *const u8);
|
let result = string::raw::from_buf(match_string as *const i8 as *const u8);
|
||||||
FcPatternDestroy(family_match);
|
FcPatternDestroy(family_match);
|
||||||
Some(result)
|
Some(result)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue