mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Fix segfault in QuartzNativeFont.create; improve error handling slightly
This commit is contained in:
parent
2d8e764c9d
commit
1292fa2965
1 changed files with 10 additions and 8 deletions
|
@ -4,7 +4,6 @@ export QuartzNativeFont, with_test_native_font, create;
|
||||||
|
|
||||||
import libc::size_t;
|
import libc::size_t;
|
||||||
import ptr::null;
|
import ptr::null;
|
||||||
import unsafe::reinterpret_cast;
|
|
||||||
import glyph::GlyphIndex;
|
import glyph::GlyphIndex;
|
||||||
import cocoa::cg::{
|
import cocoa::cg::{
|
||||||
CGDataProviderRef,
|
CGDataProviderRef,
|
||||||
|
@ -16,6 +15,7 @@ import cocoa::cg::cg::{
|
||||||
CGFontCreateWithDataProvider,
|
CGFontCreateWithDataProvider,
|
||||||
CGFontRelease
|
CGFontRelease
|
||||||
};
|
};
|
||||||
|
use unsafe::transmute;
|
||||||
|
|
||||||
mod coretext {
|
mod coretext {
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ mod coretext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct QuartzNativeFont/& {
|
struct QuartzNativeFont {
|
||||||
fontprov: CGDataProviderRef,
|
fontprov: CGDataProviderRef,
|
||||||
cgfont: CGFontRef,
|
cgfont: CGFontRef,
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ impl QuartzNativeFont {
|
||||||
|
|
||||||
import coretext::{UniChar, CGGlyph, CFIndex};
|
import coretext::{UniChar, CGGlyph, CFIndex};
|
||||||
import coretext::coretext::{CFRelease, CTFontGetGlyphsForCharacters};
|
import coretext::coretext::{CFRelease, CTFontGetGlyphsForCharacters};
|
||||||
|
|
||||||
let ctfont = ctfont_from_cgfont(self.cgfont);
|
let ctfont = ctfont_from_cgfont(self.cgfont);
|
||||||
assert ctfont.is_not_null();
|
assert ctfont.is_not_null();
|
||||||
let characters: ~[UniChar] = ~[codepoint as UniChar];
|
let characters: ~[UniChar] = ~[codepoint as UniChar];
|
||||||
|
@ -119,7 +119,7 @@ impl QuartzNativeFont {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ctfont_from_cgfont(+cgfont: CGFontRef) -> coretext::CTFontRef unsafe {
|
fn ctfont_from_cgfont(cgfont: CGFontRef) -> coretext::CTFontRef {
|
||||||
import coretext::CGFloat;
|
import coretext::CGFloat;
|
||||||
import coretext::coretext::CTFontCreateWithGraphicsFont;
|
import coretext::coretext::CTFontCreateWithGraphicsFont;
|
||||||
|
|
||||||
|
@ -131,17 +131,19 @@ fn create(buf: &~[u8]) -> Result<QuartzNativeFont, ()> {
|
||||||
let fontprov = vec::as_buf(*buf, |cbuf, len| {
|
let fontprov = vec::as_buf(*buf, |cbuf, len| {
|
||||||
CGDataProviderCreateWithData(
|
CGDataProviderCreateWithData(
|
||||||
null(),
|
null(),
|
||||||
unsafe { reinterpret_cast(&cbuf) },
|
unsafe { transmute(&cbuf) },
|
||||||
len as size_t,
|
len as size_t,
|
||||||
null())
|
null())
|
||||||
});
|
});
|
||||||
// FIXME: Error handling
|
// FIXME: Error handling
|
||||||
assert fontprov.is_not_null();
|
assert fontprov.is_not_null();
|
||||||
let cgfont = CGFontCreateWithDataProvider(fontprov);
|
let cgfont = CGFontCreateWithDataProvider(fontprov);
|
||||||
// FIXME: Error handling
|
|
||||||
assert cgfont.is_not_null();
|
|
||||||
|
|
||||||
return Ok(QuartzNativeFont(fontprov, cgfont));
|
match cgfont.is_not_null() {
|
||||||
|
true => Ok(QuartzNativeFont(fontprov, cgfont)),
|
||||||
|
false => Err(())
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_test_native_font(f: fn@(nf: &NativeFont)) {
|
fn with_test_native_font(f: fn@(nf: &NativeFont)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue