Convert Font from a class to a resource + impl to avoid bugs

This commit is contained in:
Brian Anderson 2012-06-22 16:14:31 -07:00
parent e0ddaf50df
commit 6154066619

View file

@ -21,32 +21,38 @@ import azure::cairo::bindgen::{
cairo_status_to_string cairo_status_to_string
}; };
// FIXME (rust 2708): convert this to a class
type Font = FontDtor;
#[doc = " #[doc = "
A font handle. Layout can use this to calculate glyph metrics A font handle. Layout can use this to calculate glyph metrics
and the renderer can use it to render text. and the renderer can use it to render text.
"] "]
#[warn(no_non_implicitly_copyable_typarams)] resource FontDtor(state: FontState) {
class Font/& { state.font_dtor();
let fontbuf: [u8]; }
let cairo_font: *cairo_scaled_font_t;
let font_dtor: fn@();
new(-fontbuf: [u8]) { type FontState = {
fontbuf: @[u8],
cairo_font: *cairo_scaled_font_t,
font_dtor: fn@()
};
let (cairo_font, font_dtor) = get_cairo_font(&copy fontbuf); fn Font(-fontbuf: [u8]) -> Font {
assert cairo_font.is_not_null(); let (cairo_font, font_dtor) = get_cairo_font(&copy fontbuf);
assert cairo_font.is_not_null();
self.fontbuf <- fontbuf; ret FontDtor({
self.cairo_font = cairo_font; fontbuf: @fontbuf,
self.font_dtor = font_dtor; cairo_font: cairo_font,
} font_dtor: font_dtor
});
}
drop { impl Font for Font {
self.font_dtor(); fn buf() -> @[u8] {
} self.fontbuf
fn buf() -> &self.[u8] {
&self.fontbuf
} }
fn glyph_idx(codepoint: char) -> option<GlyphIndex> { fn glyph_idx(codepoint: char) -> option<GlyphIndex> {