Switch QuartzFontHandle to use RAII CGDataProvider bindings.

This commit is contained in:
Brian J. Burg 2012-11-08 17:57:56 -08:00
parent a76ae6b992
commit 4686731096
4 changed files with 11 additions and 20 deletions

@ -1 +1 @@
Subproject commit f971c917baeb3bc5e6dfb1442bfa35a10261b650 Subproject commit 9cb470e80897a854096bc07b88857e379945f421

@ -1 +1 @@
Subproject commit c1450887c2e21a4cddfa57c4d3fc4d4eb02da425 Subproject commit aa6fb82a7390f4ef1dd596b67cec130ab33519ff

View file

@ -34,7 +34,7 @@ pub type FontHandle/& = freetype::font::FreeTypeFontHandle;
impl FontHandle { impl FontHandle {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result<FontHandle, ()> { static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], pt_size: float) -> Result<FontHandle, ()> {
quartz::font::QuartzFontHandle::new(fctx, buf, pt_size) quartz::font::QuartzFontHandle::new_from_buffer(fctx, buf, pt_size)
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View file

@ -20,9 +20,7 @@ use cf::string::UniChar;
use cg = core_graphics; use cg = core_graphics;
use cg::base::{CGFloat, CGAffineTransform}; use cg::base::{CGFloat, CGAffineTransform};
use cg::data_provider::{ use cg::data_provider::{
CGDataProviderCreateWithData, CGDataProviderRef, CGDataProvider
CGDataProviderRef,
CGDataProviderRelease,
}; };
use cg::font::{ use cg::font::{
CGFontCreateWithDataProvider, CGFontCreateWithDataProvider,
@ -52,43 +50,36 @@ use ct::font_descriptor::{
}; };
pub struct QuartzFontHandle { pub struct QuartzFontHandle {
fontprov: CGDataProviderRef,
cgfont: CGFontRef, cgfont: CGFontRef,
ctfont: CTFontRef, ctfont: CTFontRef,
drop { drop {
assert self.ctfont.is_not_null(); assert self.ctfont.is_not_null();
assert self.cgfont.is_not_null(); assert self.cgfont.is_not_null();
assert self.fontprov.is_not_null();
CFRelease(self.ctfont as CFTypeRef); CFRelease(self.ctfont as CFTypeRef);
CGFontRelease(self.cgfont); CGFontRelease(self.cgfont);
CGDataProviderRelease(self.fontprov);
} }
} }
pub impl QuartzFontHandle { pub impl QuartzFontHandle {
static pub fn new(_fctx: &QuartzFontContextHandle, buf: @~[u8], pt_size: float) -> Result<QuartzFontHandle, ()> { static pub fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: @~[u8], pt_size: float) -> Result<QuartzFontHandle, ()> {
let fontprov = vec::as_imm_buf(*buf, |cbuf, len| { let fontprov = vec::as_imm_buf(*buf, |cbuf, len| {
CGDataProviderCreateWithData( CGDataProvider::new_from_buffer(cbuf, len)
ptr::null(),
unsafe { cast::transmute(copy cbuf) },
len as size_t,
ptr::null())
}); });
if fontprov.is_null() { return Err(()); }
let cgfont = CGFontCreateWithDataProvider(fontprov); let cgfont = CGFontCreateWithDataProvider(fontprov.get_ref());
if cgfont.is_null() { return Err(()); } if cgfont.is_null() { return Err(()); }
let ctfont = ctfont_from_cgfont(cgfont, pt_size); let ctfont = ctfont_from_cgfont(cgfont, pt_size);
if ctfont.is_null() { return Err(()); } if ctfont.is_null() { return Err(()); }
Ok(QuartzFontHandle { let result = Ok(QuartzFontHandle {
fontprov : fontprov,
cgfont : cgfont, cgfont : cgfont,
ctfont : ctfont, ctfont : ctfont,
}) });
return move result;
} }
fn glyph_index(codepoint: char) -> Option<GlyphIndex> { fn glyph_index(codepoint: char) -> Option<GlyphIndex> {