mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Shaper holds a reference to its font.
This commit is contained in:
parent
97b7b21452
commit
82faedf9fc
2 changed files with 12 additions and 12 deletions
|
@ -110,7 +110,7 @@ impl Font {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
priv fn get_shaper(&self) -> @Shaper {
|
priv fn get_shaper(@self) -> @Shaper {
|
||||||
// fast path: already created a shaper
|
// fast path: already created a shaper
|
||||||
match self.shaper {
|
match self.shaper {
|
||||||
Some(shaper) => { return shaper; },
|
Some(shaper) => { return shaper; },
|
||||||
|
@ -118,7 +118,7 @@ impl Font {
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX(Issue #163): wrong! use typedef (as commented out)
|
// XXX(Issue #163): wrong! use typedef (as commented out)
|
||||||
let shaper = @harfbuzz::shaper::HarfbuzzShaper::new();
|
let shaper = @harfbuzz::shaper::HarfbuzzShaper::new(self);
|
||||||
self.shaper = Some(shaper);
|
self.shaper = Some(shaper);
|
||||||
shaper
|
shaper
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ impl Font {
|
||||||
pub trait FontMethods {
|
pub trait FontMethods {
|
||||||
fn draw_text_into_context(rctx: &RenderContext, run: &TextRun, range: Range, baseline_origin: Point2D<Au>);
|
fn draw_text_into_context(rctx: &RenderContext, run: &TextRun, range: Range, baseline_origin: Point2D<Au>);
|
||||||
fn measure_text(&TextRun, Range) -> RunMetrics;
|
fn measure_text(&TextRun, Range) -> RunMetrics;
|
||||||
fn shape_text(&self, &str) -> GlyphStore;
|
fn shape_text(@self, &str) -> GlyphStore;
|
||||||
|
|
||||||
fn buf(&self) -> @~[u8];
|
fn buf(&self) -> @~[u8];
|
||||||
// these are used to get glyphs and advances in the case that the
|
// these are used to get glyphs and advances in the case that the
|
||||||
|
@ -318,10 +318,10 @@ pub impl Font : FontMethods {
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shape_text(&self, text: &str) -> GlyphStore {
|
fn shape_text(@self, text: &str) -> GlyphStore {
|
||||||
let store = GlyphStore(text.len());
|
let store = GlyphStore(text.len());
|
||||||
let shaper = self.get_shaper();
|
let shaper = self.get_shaper();
|
||||||
shaper.shape_text(text, self, &store);
|
shaper.shape_text(text, &store);
|
||||||
return move store;
|
return move store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,25 +46,25 @@ fn fixed_to_rounded_int_hb(f: hb_position_t) -> int {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HarfbuzzShaper {
|
pub struct HarfbuzzShaper {
|
||||||
dummy: int
|
font: @Font
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl HarfbuzzShaper {
|
pub impl HarfbuzzShaper {
|
||||||
static pub fn new() -> HarfbuzzShaper {
|
static pub fn new(font: @Font) -> HarfbuzzShaper {
|
||||||
HarfbuzzShaper { dummy: 42 }
|
HarfbuzzShaper { font: font }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Calculate the layout metrics associated with a some given text
|
Calculate the layout metrics associated with a some given text
|
||||||
when rendered in a specific font.
|
when rendered in a specific font.
|
||||||
*/
|
*/
|
||||||
pub fn shape_text(text: &str, font: &Font, glyphs: &GlyphStore) {
|
pub fn shape_text(text: &str, glyphs: &GlyphStore) {
|
||||||
debug!("shaping text '%s'", text);
|
debug!("shaping text '%s'", text);
|
||||||
|
|
||||||
// TODO(Issue #94): harfbuzz fonts and faces should be cached on the
|
// TODO(Issue #94): harfbuzz fonts and faces should be cached on the
|
||||||
// Shaper object, which is owned by the Font instance.
|
// Shaper object, which is owned by the Font instance.
|
||||||
// TODO(Issue #92): font tables should be stored in Font object and cached per-task
|
// TODO(Issue #92): font tables should be stored in Font object and cached per-task
|
||||||
let face_blob: *hb_blob_t = vec::as_imm_buf(*(font).fontbuf, |buf: *u8, len: uint| {
|
let face_blob: *hb_blob_t = vec::as_imm_buf(*(self.font).fontbuf, |buf: *u8, len: uint| {
|
||||||
hb_blob_create(buf as *c_char,
|
hb_blob_create(buf as *c_char,
|
||||||
len as c_uint,
|
len as c_uint,
|
||||||
HB_MEMORY_MODE_READONLY,
|
HB_MEMORY_MODE_READONLY,
|
||||||
|
@ -76,7 +76,7 @@ pub impl HarfbuzzShaper {
|
||||||
let hb_font: *hb_font_t = hb_font_create(hb_face);
|
let hb_font: *hb_font_t = hb_font_create(hb_face);
|
||||||
|
|
||||||
// Set points-per-em. if zero, performs no hinting in that direction.
|
// Set points-per-em. if zero, performs no hinting in that direction.
|
||||||
let pt_size = font.style.pt_size;
|
let pt_size = self.font.style.pt_size;
|
||||||
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
||||||
// Set scaling. Note that this takes 16.16 fixed point.
|
// Set scaling. Note that this takes 16.16 fixed point.
|
||||||
hb_font_set_scale(hb_font, float_to_fixed_hb(pt_size) as c_int, float_to_fixed_hb(pt_size) as c_int);
|
hb_font_set_scale(hb_font, float_to_fixed_hb(pt_size) as c_int, float_to_fixed_hb(pt_size) as c_int);
|
||||||
|
@ -86,7 +86,7 @@ pub impl HarfbuzzShaper {
|
||||||
hb_font_funcs_set_glyph_h_advance_func(funcs, glyph_h_advance_func, null(), null());
|
hb_font_funcs_set_glyph_h_advance_func(funcs, glyph_h_advance_func, null(), null());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let font_data: *c_void = core::ptr::addr_of(font) as *c_void;
|
let font_data: *c_void = core::ptr::addr_of(self.font) as *c_void;
|
||||||
hb_font_set_funcs(hb_font, funcs, font_data, null());
|
hb_font_set_funcs(hb_font, funcs, font_data, null());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue