mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Port gfx crate to new CF bindings.
This commit is contained in:
parent
a6e0157401
commit
4e1afca6bd
3 changed files with 15 additions and 16 deletions
|
@ -23,13 +23,13 @@ use core_foundation::string::UniChar;
|
|||
use core_graphics::data_provider::CGDataProvider;
|
||||
use core_graphics::font::{CGFont, CGGlyph};
|
||||
use core_graphics::geometry::CGRect;
|
||||
use core_graphics;
|
||||
use core_text::font::{CTFont, CTFontMethods, CTFontMethodsPrivate};
|
||||
use core_text::font::CTFont;
|
||||
use core_text::font_descriptor::{SymbolicTraitAccessors, TraitAccessors};
|
||||
use core_text::font_descriptor::{kCTFontDefaultOrientation};
|
||||
use core_text;
|
||||
|
||||
use std::ptr;
|
||||
use std::vec;
|
||||
|
||||
pub struct FontTable {
|
||||
data: CFData,
|
||||
|
@ -48,7 +48,7 @@ impl FontTable {
|
|||
|
||||
impl FontTableMethods for FontTable {
|
||||
fn with_buffer(&self, blk: &fn(*u8, uint)) {
|
||||
blk(self.data.bytes(), self.data.len());
|
||||
blk(vec::raw::to_ptr(self.data.bytes()), self.data.len() as uint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,11 +80,8 @@ impl FontHandle {
|
|||
impl FontHandleMethods for FontHandle {
|
||||
fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
|
||||
-> Result<FontHandle, ()> {
|
||||
let fontprov : CGDataProvider = do buf.as_imm_buf |cbuf, len| {
|
||||
core_graphics::data_provider::new_from_buffer(cbuf, len)
|
||||
};
|
||||
|
||||
let cgfont = core_graphics::font::create_with_data_provider(&fontprov);
|
||||
let fontprov = CGDataProvider::from_buffer(buf);
|
||||
let cgfont = CGFont::from_data_provider(fontprov);
|
||||
let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size);
|
||||
|
||||
let result = Ok(FontHandle {
|
||||
|
|
|
@ -8,12 +8,12 @@ use font_list::{FontEntry, FontFamily, FontFamilyMap};
|
|||
use platform::macos::font::FontHandle;
|
||||
use platform::macos::font_context::FontContextHandle;
|
||||
|
||||
use core_foundation::array::CFArray;
|
||||
use core_foundation::base::CFWrapper;
|
||||
use core_foundation::base::TCFType;
|
||||
use core_foundation::string::{CFString, CFStringRef};
|
||||
use core_text::font_collection::CTFontCollectionMethods;
|
||||
use core_text;
|
||||
use core_text::font_descriptor::{CTFontDescriptor, CTFontDescriptorRef};
|
||||
|
||||
use std::cast;
|
||||
use std::hashmap::HashMap;
|
||||
|
||||
pub struct FontListHandle {
|
||||
|
@ -28,10 +28,12 @@ impl FontListHandle {
|
|||
}
|
||||
|
||||
pub fn get_available_families(&self) -> FontFamilyMap {
|
||||
let family_names: CFArray<CFStringRef> = core_text::font_collection::get_family_names();
|
||||
let family_names = core_text::font_collection::get_family_names();
|
||||
let mut family_map: FontFamilyMap = HashMap::new();
|
||||
for strref in family_names.iter() {
|
||||
let family_name = CFString::wrap_shared(strref).to_str();
|
||||
let family_name_ref: CFStringRef = unsafe { cast::transmute(strref) };
|
||||
let family_name_cf: CFString = unsafe { TCFType::wrap_under_get_rule(family_name_ref) };
|
||||
let family_name = family_name_cf.to_str();
|
||||
debug!("Creating new FontFamily for family: {:s}", family_name);
|
||||
|
||||
let new_family = @mut FontFamily::new(family_name);
|
||||
|
@ -46,7 +48,8 @@ impl FontListHandle {
|
|||
let family_collection = core_text::font_collection::create_for_family(family.family_name);
|
||||
let family_descriptors = family_collection.get_descriptors();
|
||||
for descref in family_descriptors.iter() {
|
||||
let desc = CFWrapper::wrap_shared(descref);
|
||||
let descref: CTFontDescriptorRef = unsafe { cast::transmute(descref) };
|
||||
let desc: CTFontDescriptor = unsafe { TCFType::wrap_under_get_rule(descref) };
|
||||
let font = core_text::font::new_from_descriptor(&desc, 0.0);
|
||||
let handle = FontHandle::new_from_CTFont(&self.fctx, font).unwrap();
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
use platform::surface::NativeSurfaceAzureMethods;
|
||||
|
||||
use azure::AzSkiaGrGLSharedSurfaceRef;
|
||||
use core_foundation::base::CFWrapper;
|
||||
use io_surface::IOSurface;
|
||||
use layers::platform::surface::NativeSurface;
|
||||
use std::cast;
|
||||
|
@ -17,7 +16,7 @@ impl NativeSurfaceAzureMethods for NativeSurface {
|
|||
fn from_azure_surface(surface: AzSkiaGrGLSharedSurfaceRef) -> NativeSurface {
|
||||
unsafe {
|
||||
let io_surface = IOSurface {
|
||||
contents: CFWrapper::wrap_owned(cast::transmute(surface)),
|
||||
obj: cast::transmute(surface),
|
||||
};
|
||||
NativeSurface::from_io_surface(io_surface)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue