mirror of
https://github.com/servo/servo.git
synced 2025-06-25 01:24:37 +01:00
Implement clone_with_style for FreeType
This commit is contained in:
parent
905ad4a88e
commit
ae6939bc1a
2 changed files with 22 additions and 11 deletions
|
@ -51,7 +51,7 @@ pub impl FontHandle {
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
static pub fn new_from_buffer(fctx: &native::FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
static pub fn new_from_buffer(fctx: &native::FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
||||||
freetype_impl::font::FreeTypeFontHandle::new_from_buffer(fctx, move buf, style)
|
freetype_impl::font::FreeTypeFontHandle::new_from_buffer(fctx, @move buf, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,15 @@ pub impl FreeTypeFontTable : FontTableMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum FontSource {
|
||||||
|
FontSourceMem(@~[u8]),
|
||||||
|
FontSourceFile(~str)
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FreeTypeFontHandle {
|
pub struct FreeTypeFontHandle {
|
||||||
// The font binary. This must stay valid for the lifetime of the font,
|
// The font binary. This must stay valid for the lifetime of the font,
|
||||||
// if the font is created using FT_Memory_Face.
|
// if the font is created using FT_Memory_Face.
|
||||||
// TODO: support both FT_Memory_Face (from memory) and FT_Face (from file)
|
source: FontSource,
|
||||||
buf: ~[u8],
|
|
||||||
face: FT_Face,
|
face: FT_Face,
|
||||||
|
|
||||||
drop {
|
drop {
|
||||||
|
@ -117,7 +121,7 @@ pub impl FreeTypeFontHandle {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
if FreeTypeFontHandle::set_char_size(face, style.pt_size).is_ok() {
|
if FreeTypeFontHandle::set_char_size(face, style.pt_size).is_ok() {
|
||||||
Ok(FreeTypeFontHandle { buf: ~[], face: face })
|
Ok(FreeTypeFontHandle { source: FontSourceFile(file), face: face })
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
|
@ -138,15 +142,15 @@ pub impl FreeTypeFontHandle {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(FreeTypeFontHandle { buf: ~[], face: face })
|
Ok(FreeTypeFontHandle { source: FontSourceFile(file), face: face })
|
||||||
}
|
}
|
||||||
|
|
||||||
static pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle,
|
static pub fn new_from_buffer(fctx: &FreeTypeFontContextHandle,
|
||||||
buf: ~[u8], style: &SpecifiedFontStyle) -> Result<FreeTypeFontHandle, ()> {
|
buf: @~[u8], style: &SpecifiedFontStyle) -> Result<FreeTypeFontHandle, ()> {
|
||||||
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
let ft_ctx: FT_Library = fctx.ctx.ctx;
|
||||||
if ft_ctx.is_null() { return Err(()); }
|
if ft_ctx.is_null() { return Err(()); }
|
||||||
|
|
||||||
let face_result = do vec::as_imm_buf(buf) |bytes: *u8, len: uint| {
|
let face_result = do vec::as_imm_buf(*buf) |bytes: *u8, len: uint| {
|
||||||
create_face_from_buffer(ft_ctx, bytes, len, style.pt_size)
|
create_face_from_buffer(ft_ctx, bytes, len, style.pt_size)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -154,7 +158,7 @@ pub impl FreeTypeFontHandle {
|
||||||
// and moving buf into the struct ctor, but cant' move out of
|
// and moving buf into the struct ctor, but cant' move out of
|
||||||
// captured binding.
|
// captured binding.
|
||||||
return match face_result {
|
return match face_result {
|
||||||
Ok(face) => Ok(FreeTypeFontHandle { face: face, buf: move buf }),
|
Ok(face) => Ok(FreeTypeFontHandle { face: face, source: FontSourceMem(buf) }),
|
||||||
Err(()) => Err(())
|
Err(()) => Err(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -223,9 +227,16 @@ pub impl FreeTypeFontHandle : FontHandleMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clone_with_style(_fctx: &native::FontContextHandle,
|
fn clone_with_style(fctx: &native::FontContextHandle,
|
||||||
_style: &UsedFontStyle) -> Result<FontHandle, ()> {
|
style: &UsedFontStyle) -> Result<FreeTypeFontHandle, ()> {
|
||||||
fail;
|
match self.source {
|
||||||
|
FontSourceMem(buf) => {
|
||||||
|
FreeTypeFontHandle::new_from_buffer(fctx, buf, style)
|
||||||
|
}
|
||||||
|
FontSourceFile(copy file) => {
|
||||||
|
FreeTypeFontHandle::new_from_file(fctx, file, style)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glyph_index(codepoint: char) -> Option<GlyphIndex> {
|
pub fn glyph_index(codepoint: char) -> Option<GlyphIndex> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue