mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
Don't pass around a managed font buffer since it's not shared, and not used by font table code at all. Fixes #176.
This commit is contained in:
parent
ad353c3161
commit
23c35c4c88
4 changed files with 20 additions and 24 deletions
|
@ -42,13 +42,13 @@ pub trait FontHandleMethods {
|
|||
|
||||
impl FontHandle {
|
||||
#[cfg(target_os = "macos")]
|
||||
static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
||||
quartz::font::QuartzFontHandle::new_from_buffer(fctx, buf, style)
|
||||
static pub fn new(fctx: &native::FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
||||
quartz::font::QuartzFontHandle::new_from_buffer(fctx, move buf, style)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
static pub fn new(fctx: &native::FontContextHandle, buf: @~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
||||
freetype::font::FreeTypeFontHandle::new(fctx, buf, style)
|
||||
static pub fn new(fctx: &native::FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) -> Result<FontHandle, ()> {
|
||||
freetype::font::FreeTypeFontHandle::new(fctx, move buf, style)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,6 @@ A font instance. Layout can use this to calculate glyph metrics
|
|||
and the renderer can use it to render text.
|
||||
*/
|
||||
pub struct Font {
|
||||
priv mut fontbuf: Option<@~[u8]>,
|
||||
priv handle: FontHandle,
|
||||
priv mut azure_font: Option<AzScaledFontRef>,
|
||||
priv mut shaper: Option<@Shaper>,
|
||||
|
@ -253,10 +252,10 @@ pub struct Font {
|
|||
}
|
||||
|
||||
impl Font {
|
||||
static fn new_from_buffer(ctx: &FontContext, buffer: @~[u8],
|
||||
static fn new_from_buffer(ctx: &FontContext, buffer: ~[u8],
|
||||
style: &SpecifiedFontStyle, backend: BackendType) -> Result<@Font, ()> {
|
||||
|
||||
let handle = FontHandle::new(&ctx.handle, buffer, style);
|
||||
let handle = FontHandle::new(&ctx.handle, move buffer, style);
|
||||
let handle = if handle.is_ok() {
|
||||
result::unwrap(move handle)
|
||||
} else {
|
||||
|
@ -267,7 +266,6 @@ impl Font {
|
|||
// TODO(Issue #179): convert between specified and used font style here?
|
||||
|
||||
return Ok(@Font {
|
||||
fontbuf : Some(buffer),
|
||||
handle : move handle,
|
||||
azure_font: None,
|
||||
shaper: None,
|
||||
|
@ -287,7 +285,6 @@ impl Font {
|
|||
};
|
||||
|
||||
return Ok(@Font {
|
||||
fontbuf : None,
|
||||
handle : move styled_handle,
|
||||
azure_font: None,
|
||||
shaper: None,
|
||||
|
@ -353,7 +350,6 @@ pub trait FontMethods {
|
|||
fn shape_text(@self, &str) -> GlyphStore;
|
||||
fn get_descriptor() -> FontDescriptor;
|
||||
|
||||
fn buf(&self) -> @~[u8];
|
||||
// these are used to get glyphs and advances in the case that the
|
||||
// shaper can't figure it out.
|
||||
fn glyph_index(char) -> Option<GlyphIndex>;
|
||||
|
@ -461,10 +457,6 @@ pub impl Font : FontMethods {
|
|||
FontDescriptor::new(&font_context::dummy_style(), &SelectorStubDummy)
|
||||
}
|
||||
|
||||
fn buf(&self) -> @~[u8] {
|
||||
option::expect(self.fontbuf, ~"This font has no buffer")
|
||||
}
|
||||
|
||||
fn glyph_index(codepoint: char) -> Option<GlyphIndex> {
|
||||
self.handle.glyph_index(codepoint)
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ pub impl FontContext {
|
|||
priv fn create_font_instance(desc: &FontDescriptor) -> Result<@Font, ()> {
|
||||
return match desc.selector {
|
||||
SelectorStubDummy => {
|
||||
Font::new_from_buffer(&self, @test_font_bin(), &desc.style, self.backend)
|
||||
Font::new_from_buffer(&self, test_font_bin(), &desc.style, self.backend)
|
||||
},
|
||||
// TODO(Issue #174): implement by-platform-name font selectors.
|
||||
SelectorPlatformName(_) => { fail ~"FontContext::create_font_instance() can't yet handle SelectorPlatformName." }
|
||||
|
|
|
@ -31,8 +31,10 @@ fn fixed_to_float_ft(f: i32) -> float {
|
|||
}
|
||||
|
||||
pub struct FreeTypeFontHandle {
|
||||
/// The font binary. This must stay valid for the lifetime of the font
|
||||
buf: @~[u8],
|
||||
// The font binary. This must stay valid for the lifetime of the font,
|
||||
// if the font is created using FT_Memory_Face.
|
||||
// TODO: support both FT_Memory_Face (from memory) and FT_Face (from file)
|
||||
buf: ~[u8],
|
||||
face: FT_Face,
|
||||
|
||||
drop {
|
||||
|
@ -45,11 +47,10 @@ pub struct FreeTypeFontHandle {
|
|||
|
||||
pub impl FreeTypeFontHandle {
|
||||
static pub fn new(fctx: &FreeTypeFontContext,
|
||||
buf: @~[u8], pt_size: float) -> Result<FreeTypeFontHandle, ()> {
|
||||
buf: ~[u8], pt_size: float) -> Result<FreeTypeFontHandle, ()> {
|
||||
let ft_ctx = fctx.ctx;
|
||||
assert ft_ctx.is_not_null();
|
||||
let face: FT_Face = null();
|
||||
return vec_as_buf(*buf, |cbuf, _len| {
|
||||
let face_result: Result<FT_Face,()> = vec_as_buf(buf, |cbuf, _len| {
|
||||
if FT_New_Memory_Face(ft_ctx, cbuf, (*buf).len() as FT_Long,
|
||||
0 as FT_Long, addr_of(&face)).succeeded() {
|
||||
let res = FT_Set_Char_Size(face, // the face
|
||||
|
@ -58,11 +59,14 @@ pub impl FreeTypeFontHandle {
|
|||
72, // horiz. DPI
|
||||
72); // vert. DPI
|
||||
if !res.succeeded() { fail ~"unable to set font char size" }
|
||||
Ok(FreeTypeFontHandle { face: face, buf: buf })
|
||||
Ok(face)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
})
|
||||
});
|
||||
return do result::chain(face_result) |face| {
|
||||
Ok(FreeTypeFontHandle { face: face, buf: move buf })
|
||||
};
|
||||
}
|
||||
|
||||
pub fn glyph_index(codepoint: char) -> Option<GlyphIndex> {
|
||||
|
|
|
@ -56,9 +56,9 @@ pub struct QuartzFontHandle {
|
|||
}
|
||||
|
||||
pub impl QuartzFontHandle {
|
||||
static fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: @~[u8],
|
||||
static fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: ~[u8],
|
||||
style: &SpecifiedFontStyle) -> Result<QuartzFontHandle, ()> {
|
||||
let fontprov = vec::as_imm_buf(*buf, |cbuf, len| {
|
||||
let fontprov = vec::as_imm_buf(buf, |cbuf, len| {
|
||||
CGDataProvider::new_from_buffer(cbuf, len)
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue