mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Convert Font from a class to a resource + impl to avoid bugs
This commit is contained in:
parent
e0ddaf50df
commit
6154066619
1 changed files with 24 additions and 18 deletions
|
@ -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(© fontbuf);
|
fn Font(-fontbuf: [u8]) -> Font {
|
||||||
assert cairo_font.is_not_null();
|
let (cairo_font, font_dtor) = get_cairo_font(© 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> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue