mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Add glyph advance cache to enhance speed of layout
This commit is contained in:
parent
d6d2534b56
commit
46776e1974
5 changed files with 16 additions and 10 deletions
|
@ -49,7 +49,7 @@ pub trait FontHandleMethods {
|
||||||
fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
|
fn clone_with_style(&self, fctx: &FontContextHandle, style: &UsedFontStyle)
|
||||||
-> Result<FontHandle, ()>;
|
-> Result<FontHandle, ()>;
|
||||||
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>;
|
fn glyph_index(&self, codepoint: char) -> Option<GlyphIndex>;
|
||||||
fn glyph_h_advance(&self, GlyphIndex) -> Option<FractionalPixel>;
|
fn glyph_h_advance(&mut self, GlyphIndex) -> Option<FractionalPixel>;
|
||||||
fn get_metrics(&self) -> FontMetrics;
|
fn get_metrics(&self) -> FontMetrics;
|
||||||
fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>;
|
fn get_table_for_tag(&self, FontTableTag) -> Option<FontTable>;
|
||||||
}
|
}
|
||||||
|
@ -244,6 +244,7 @@ pub struct Font {
|
||||||
backend: BackendType,
|
backend: BackendType,
|
||||||
profiler_chan: ProfilerChan,
|
profiler_chan: ProfilerChan,
|
||||||
shape_cache: HashCache<~str, Arc<GlyphStore>>,
|
shape_cache: HashCache<~str, Arc<GlyphStore>>,
|
||||||
|
glyph_advance_cache: HashCache<u32, FractionalPixel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Font {
|
impl Font {
|
||||||
|
@ -272,6 +273,7 @@ impl Font {
|
||||||
backend: backend,
|
backend: backend,
|
||||||
profiler_chan: profiler_chan,
|
profiler_chan: profiler_chan,
|
||||||
shape_cache: HashCache::new(),
|
shape_cache: HashCache::new(),
|
||||||
|
glyph_advance_cache: HashCache::new(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +291,7 @@ impl Font {
|
||||||
backend: backend,
|
backend: backend,
|
||||||
profiler_chan: profiler_chan,
|
profiler_chan: profiler_chan,
|
||||||
shape_cache: HashCache::new(),
|
shape_cache: HashCache::new(),
|
||||||
|
glyph_advance_cache: HashCache::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,13 +477,15 @@ impl Font {
|
||||||
self.handle.glyph_index(codepoint)
|
self.handle.glyph_index(codepoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn glyph_h_advance(&self, glyph: GlyphIndex) -> FractionalPixel {
|
pub fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> FractionalPixel {
|
||||||
match self.handle.glyph_h_advance(glyph) {
|
do self.glyph_advance_cache.find_or_create(&glyph) |glyph| {
|
||||||
|
match self.handle.glyph_h_advance(*glyph) {
|
||||||
Some(adv) => adv,
|
Some(adv) => adv,
|
||||||
None => /* FIXME: Need fallback strategy */ 10f as FractionalPixel
|
None => /* FIXME: Need fallback strategy */ 10f as FractionalPixel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*fn should_destruct_on_fail_without_leaking() {
|
/*fn should_destruct_on_fail_without_leaking() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn glyph_h_advance(&self,
|
fn glyph_h_advance(&mut self,
|
||||||
glyph: GlyphIndex) -> Option<FractionalPixel> {
|
glyph: GlyphIndex) -> Option<FractionalPixel> {
|
||||||
assert!(self.face.is_not_null());
|
assert!(self.face.is_not_null());
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl FontHandleMethods for FontHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
fn glyph_h_advance(&self,
|
fn glyph_h_advance(&mut self,
|
||||||
glyph: GlyphIndex) -> Option<FractionalPixel> {
|
glyph: GlyphIndex) -> Option<FractionalPixel> {
|
||||||
assert!(self.face.is_not_null());
|
assert!(self.face.is_not_null());
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl FontHandleMethods for FontHandle {
|
||||||
return Some(glyphs[0] as GlyphIndex);
|
return Some(glyphs[0] as GlyphIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option<FractionalPixel> {
|
fn glyph_h_advance(&mut self, glyph: GlyphIndex) -> Option<FractionalPixel> {
|
||||||
let glyphs = [glyph as CGGlyph];
|
let glyphs = [glyph as CGGlyph];
|
||||||
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
|
let advance = self.ctfont.get_advances_for_glyphs(kCTFontDefaultOrientation,
|
||||||
&glyphs[0],
|
&glyphs[0],
|
||||||
|
|
|
@ -13,6 +13,7 @@ use servo_util::range::Range;
|
||||||
use text::util::{float_to_fixed, fixed_to_float, fixed_to_rounded_int};
|
use text::util::{float_to_fixed, fixed_to_float, fixed_to_rounded_int};
|
||||||
|
|
||||||
use std::cast::transmute;
|
use std::cast::transmute;
|
||||||
|
use std::cast;
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::libc::{c_uint, c_int, c_void, c_char};
|
use std::libc::{c_uint, c_int, c_void, c_char};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -509,7 +510,7 @@ extern fn glyph_h_advance_func(_: *hb_font_t,
|
||||||
glyph: hb_codepoint_t,
|
glyph: hb_codepoint_t,
|
||||||
_: *c_void)
|
_: *c_void)
|
||||||
-> hb_position_t {
|
-> hb_position_t {
|
||||||
let font: *Font = font_data as *Font;
|
let font: *mut Font = unsafe { cast::transmute(font_data as *Font) };
|
||||||
assert!(font.is_not_null());
|
assert!(font.is_not_null());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue