mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.
This commit is contained in:
parent
ff8cbff810
commit
95fc29fa0d
255 changed files with 3550 additions and 3362 deletions
|
@ -8,6 +8,7 @@ use font::{FontHandleMethods, FontMetrics, FontTableMethods};
|
|||
use font::{FontTableTag, FractionalPixel};
|
||||
use servo_util::geometry::Au;
|
||||
use servo_util::geometry;
|
||||
use servo_util::str::c_str_to_string;
|
||||
use platform::font_context::FontContextHandle;
|
||||
use text::glyph::GlyphId;
|
||||
use text::util::{float_to_fixed, fixed_to_float};
|
||||
|
@ -25,11 +26,10 @@ use freetype::freetype::{FT_SizeRec, FT_UInt, FT_Size_Metrics, struct_FT_Vector_
|
|||
use freetype::freetype::{ft_sfnt_os2};
|
||||
use freetype::tt_os2::TT_OS2;
|
||||
|
||||
use libc::c_char;
|
||||
use std::mem;
|
||||
use std::num::Float;
|
||||
use std::ptr;
|
||||
use std::string::String;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
fn float_to_fixed_ft(f: f64) -> i32 {
|
||||
|
@ -43,7 +43,7 @@ fn fixed_to_float_ft(f: i32) -> f64 {
|
|||
pub struct FontTable;
|
||||
|
||||
impl FontTableMethods for FontTable {
|
||||
fn with_buffer(&self, _blk: |*const u8, uint|) {
|
||||
fn with_buffer<F>(&self, _blk: F) where F: FnOnce(*const u8, uint) {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
@ -121,10 +121,14 @@ impl FontHandleMethods for FontHandle {
|
|||
self.font_data.clone()
|
||||
}
|
||||
fn family_name(&self) -> String {
|
||||
unsafe { String::from_raw_buf(&*(*self.face).family_name as *const i8 as *const u8) }
|
||||
unsafe {
|
||||
c_str_to_string((*self.face).family_name as *const c_char)
|
||||
}
|
||||
}
|
||||
fn face_name(&self) -> String {
|
||||
unsafe { String::from_raw_buf(&*FT_Get_Postscript_Name(self.face) as *const i8 as *const u8) }
|
||||
unsafe {
|
||||
c_str_to_string(FT_Get_Postscript_Name(self.face) as *const c_char)
|
||||
}
|
||||
}
|
||||
fn is_italic(&self) -> bool {
|
||||
unsafe { (*self.face).style_flags & FT_STYLE_FLAG_ITALIC != 0 }
|
||||
|
@ -253,7 +257,7 @@ impl FontHandleMethods for FontHandle {
|
|||
line_gap: height,
|
||||
};
|
||||
|
||||
debug!("Font metrics (@{} pt): {}", geometry::to_pt(em_size), metrics);
|
||||
debug!("Font metrics (@{} pt): {:?}", geometry::to_pt(em_size), metrics);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,12 +37,12 @@ extern fn ft_realloc(_mem: FT_Memory, _cur_size: c_long, new_size: c_long, block
|
|||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct FreeTypeLibraryHandle {
|
||||
pub ctx: FT_Library,
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct FontContextHandle {
|
||||
pub ctx: Rc<FreeTypeLibraryHandle>,
|
||||
}
|
||||
|
|
|
@ -20,17 +20,19 @@ use fontconfig::fontconfig::{
|
|||
FcObjectSetAdd, FcPatternGetInteger
|
||||
};
|
||||
|
||||
use servo_util::str::c_str_to_string;
|
||||
|
||||
use libc;
|
||||
use libc::c_int;
|
||||
use libc::{c_int, c_char};
|
||||
use std::borrow::ToOwned;
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
use std::string::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<F>(mut callback: F) where F: FnMut(String) {
|
||||
unsafe {
|
||||
let config = FcConfigGetCurrent();
|
||||
let fontSet = FcConfigGetFonts(config, FcSetSystem);
|
||||
|
@ -38,8 +40,8 @@ pub fn get_available_families(callback: |String|) {
|
|||
let font = (*fontSet).fonts.offset(i);
|
||||
let mut family: *mut FcChar8 = ptr::null_mut();
|
||||
let mut v: c_int = 0;
|
||||
while FcPatternGetString(*font, FC_FAMILY.as_ptr() as *mut i8, v, &mut family) == FcResultMatch {
|
||||
let family_name = String::from_raw_buf(family as *const i8 as *const u8);
|
||||
while FcPatternGetString(*font, FC_FAMILY.as_ptr() as *mut c_char, v, &mut family) == FcResultMatch {
|
||||
let family_name = c_str_to_string(family as *const c_char);
|
||||
callback(family_name);
|
||||
v += 1;
|
||||
}
|
||||
|
@ -47,7 +49,9 @@ pub fn get_available_families(callback: |String|) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
||||
pub fn get_variations_for_family<F>(family_name: &str, mut callback: F)
|
||||
where F: FnMut(String)
|
||||
{
|
||||
debug!("getting variations for {}", family_name);
|
||||
unsafe {
|
||||
let config = FcConfigGetCurrent();
|
||||
|
@ -55,16 +59,16 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
|||
let font_set_array_ptr = &mut font_set;
|
||||
let pattern = FcPatternCreate();
|
||||
assert!(!pattern.is_null());
|
||||
let mut family_name_c = family_name.to_c_str();
|
||||
let family_name = family_name_c.as_mut_ptr();
|
||||
let ok = FcPatternAddString(pattern, FC_FAMILY.as_ptr() as *mut i8, family_name as *mut FcChar8);
|
||||
let family_name_c = CString::from_slice(family_name.as_bytes());
|
||||
let family_name = family_name_c.as_ptr();
|
||||
let ok = FcPatternAddString(pattern, FC_FAMILY.as_ptr() as *mut c_char, family_name as *mut FcChar8);
|
||||
assert!(ok != 0);
|
||||
|
||||
let object_set = FcObjectSetCreate();
|
||||
assert!(!object_set.is_null());
|
||||
|
||||
FcObjectSetAdd(object_set, FC_FILE.as_ptr() as *mut i8);
|
||||
FcObjectSetAdd(object_set, FC_INDEX.as_ptr() as *mut i8);
|
||||
FcObjectSetAdd(object_set, FC_FILE.as_ptr() as *mut c_char);
|
||||
FcObjectSetAdd(object_set, FC_INDEX.as_ptr() as *mut c_char);
|
||||
|
||||
let matches = FcFontSetList(config, font_set_array_ptr, 1, pattern, object_set);
|
||||
|
||||
|
@ -73,13 +77,13 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
|||
for i in range(0, (*matches).nfont as int) {
|
||||
let font = (*matches).fonts.offset(i);
|
||||
let mut file: *mut FcChar8 = ptr::null_mut();
|
||||
let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut i8, 0, &mut file) == FcResultMatch {
|
||||
String::from_raw_buf(file as *const i8 as *const u8)
|
||||
let file = if FcPatternGetString(*font, FC_FILE.as_ptr() as *mut c_char, 0, &mut file) == FcResultMatch {
|
||||
c_str_to_string(file as *const c_char)
|
||||
} else {
|
||||
panic!();
|
||||
};
|
||||
let mut index: libc::c_int = 0;
|
||||
let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut i8, 0, &mut index) == FcResultMatch {
|
||||
let index = if FcPatternGetInteger(*font, FC_INDEX.as_ptr() as *mut c_char, 0, &mut index) == FcResultMatch {
|
||||
index
|
||||
} else {
|
||||
panic!();
|
||||
|
@ -98,8 +102,8 @@ pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
|||
}
|
||||
|
||||
pub fn get_system_default_family(generic_name: &str) -> Option<String> {
|
||||
let mut generic_name_c = generic_name.to_c_str();
|
||||
let generic_name_ptr = generic_name_c.as_mut_ptr();
|
||||
let generic_name_c = CString::from_slice(generic_name.as_bytes());
|
||||
let generic_name_ptr = generic_name_c.as_ptr();
|
||||
|
||||
unsafe {
|
||||
let pattern = FcNameParse(generic_name_ptr as *mut FcChar8);
|
||||
|
@ -112,8 +116,8 @@ pub fn get_system_default_family(generic_name: &str) -> Option<String> {
|
|||
|
||||
let family_name = if result == FcResultMatch {
|
||||
let mut match_string: *mut FcChar8 = ptr::null_mut();
|
||||
FcPatternGetString(family_match, FC_FAMILY.as_ptr() as *mut i8, 0, &mut match_string);
|
||||
let result = String::from_raw_buf(match_string as *const i8 as *const u8);
|
||||
FcPatternGetString(family_match, FC_FAMILY.as_ptr() as *mut c_char, 0, &mut match_string);
|
||||
let result = c_str_to_string(match_string as *const c_char);
|
||||
FcPatternDestroy(family_match);
|
||||
Some(result)
|
||||
} else {
|
||||
|
|
|
@ -47,7 +47,7 @@ impl FontTable {
|
|||
}
|
||||
|
||||
impl FontTableMethods for FontTable {
|
||||
fn with_buffer(&self, blk: |*const u8, uint|) {
|
||||
fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, uint) {
|
||||
blk(self.data.bytes().as_ptr(), self.data.len() as uint);
|
||||
}
|
||||
}
|
||||
|
@ -112,8 +112,8 @@ impl FontHandleMethods for FontHandle {
|
|||
}
|
||||
|
||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphId> {
|
||||
let characters: [UniChar, ..1] = [codepoint as UniChar];
|
||||
let mut glyphs: [CGGlyph, ..1] = [0 as CGGlyph];
|
||||
let characters: [UniChar; 1] = [codepoint as UniChar];
|
||||
let mut glyphs: [CGGlyph; 1] = [0 as CGGlyph];
|
||||
let count: CFIndex = 1;
|
||||
|
||||
let result = self.ctfont.get_glyphs_for_characters(&characters[0],
|
||||
|
@ -179,7 +179,7 @@ impl FontHandleMethods for FontHandle {
|
|||
average_advance: average_advance,
|
||||
line_gap: Au::from_frac_px(line_gap),
|
||||
};
|
||||
debug!("Font metrics (@{} pt): {}", self.ctfont.pt_size() as f64, metrics);
|
||||
debug!("Font metrics (@{} pt): {:?}", self.ctfont.pt_size() as f64, metrics);
|
||||
return metrics;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
#[deriving(Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct FontContextHandle {
|
||||
ctx: ()
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use core_text;
|
|||
use std::borrow::ToOwned;
|
||||
use std::mem;
|
||||
|
||||
pub fn get_available_families(callback: |String|) {
|
||||
pub fn get_available_families<F>(mut callback: F) where F: FnMut(String) {
|
||||
let family_names = core_text::font_collection::get_family_names();
|
||||
for strref in family_names.iter() {
|
||||
let family_name_ref: CFStringRef = unsafe { mem::transmute(strref) };
|
||||
|
@ -20,7 +20,7 @@ pub fn get_available_families(callback: |String|) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_variations_for_family(family_name: &str, callback: |String|) {
|
||||
pub fn get_variations_for_family<F>(family_name: &str, mut callback: F) where F: FnMut(String) {
|
||||
debug!("Looking for faces of family: {}", family_name);
|
||||
|
||||
let family_collection =
|
||||
|
|
|
@ -18,6 +18,9 @@ pub struct FontTemplateData {
|
|||
pub identifier: String,
|
||||
}
|
||||
|
||||
unsafe impl Send for FontTemplateData {}
|
||||
unsafe impl Sync for FontTemplateData {}
|
||||
|
||||
impl FontTemplateData {
|
||||
pub fn new(identifier: &str, font_data: Option<Vec<u8>>) -> FontTemplateData {
|
||||
let ctfont = match font_data {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue