mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Remove unused FontShapingOptions field from Shaper
This commit is contained in:
parent
3c1b8e10c4
commit
7bf6a41553
2 changed files with 12 additions and 35 deletions
|
@ -172,7 +172,7 @@ struct ShapeCacheEntry {
|
||||||
|
|
||||||
impl Font {
|
impl Font {
|
||||||
pub fn shape_text(&mut self, text: &str, options: &ShapingOptions) -> Arc<GlyphStore> {
|
pub fn shape_text(&mut self, text: &str, options: &ShapingOptions) -> Arc<GlyphStore> {
|
||||||
self.make_shaper(options);
|
self.make_shaper();
|
||||||
|
|
||||||
//FIXME: find the equivalent of Equiv and the old ShapeCacheEntryRef
|
//FIXME: find the equivalent of Equiv and the old ShapeCacheEntryRef
|
||||||
let shaper = &self.shaper;
|
let shaper = &self.shaper;
|
||||||
|
@ -198,16 +198,10 @@ impl Font {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_shaper<'a>(&'a mut self, options: &ShapingOptions) -> &'a Shaper {
|
fn make_shaper(&mut self) {
|
||||||
// fast path: already created a shaper
|
if self.shaper.is_none() {
|
||||||
if let Some(ref mut shaper) = self.shaper {
|
self.shaper = Some(Shaper::new(self));
|
||||||
shaper.set_options(options);
|
|
||||||
return shaper
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let shaper = Shaper::new(self, options);
|
|
||||||
self.shaper = Some(shaper);
|
|
||||||
self.shaper.as_ref().unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
|
pub fn table_for_tag(&self, tag: FontTableTag) -> Option<FontTable> {
|
||||||
|
|
|
@ -126,17 +126,11 @@ impl ShapedGlyphData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct FontAndShapingOptions {
|
|
||||||
font: *mut Font,
|
|
||||||
options: ShapingOptions,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Shaper {
|
pub struct Shaper {
|
||||||
hb_face: *mut hb_face_t,
|
hb_face: *mut hb_face_t,
|
||||||
hb_font: *mut hb_font_t,
|
hb_font: *mut hb_font_t,
|
||||||
font_and_shaping_options: Box<FontAndShapingOptions>,
|
font: *mut Font,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Shaper {
|
impl Drop for Shaper {
|
||||||
|
@ -152,15 +146,11 @@ impl Drop for Shaper {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Shaper {
|
impl Shaper {
|
||||||
pub fn new(font: &mut Font, options: &ShapingOptions) -> Shaper {
|
pub fn new(font: &mut Font) -> Shaper {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut font_and_shaping_options = box FontAndShapingOptions {
|
|
||||||
font: font,
|
|
||||||
options: *options,
|
|
||||||
};
|
|
||||||
let hb_face: *mut hb_face_t =
|
let hb_face: *mut hb_face_t =
|
||||||
hb_face_create_for_tables(Some(font_table_func),
|
hb_face_create_for_tables(Some(font_table_func),
|
||||||
&mut *font_and_shaping_options as *mut _ as *mut c_void,
|
font as *mut _ as *mut c_void,
|
||||||
None);
|
None);
|
||||||
let hb_font: *mut hb_font_t = hb_font_create(hb_face);
|
let hb_font: *mut hb_font_t = hb_font_create(hb_face);
|
||||||
|
|
||||||
|
@ -179,15 +169,11 @@ impl Shaper {
|
||||||
Shaper {
|
Shaper {
|
||||||
hb_face: hb_face,
|
hb_face: hb_face,
|
||||||
hb_font: hb_font,
|
hb_font: hb_font,
|
||||||
font_and_shaping_options: font_and_shaping_options,
|
font: font,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_options(&mut self, options: &ShapingOptions) {
|
|
||||||
self.font_and_shaping_options.options = *options
|
|
||||||
}
|
|
||||||
|
|
||||||
fn float_to_fixed(f: f64) -> i32 {
|
fn float_to_fixed(f: f64) -> i32 {
|
||||||
float_to_fixed(16, f)
|
float_to_fixed(16, f)
|
||||||
}
|
}
|
||||||
|
@ -409,8 +395,7 @@ impl Shaper {
|
||||||
//
|
//
|
||||||
// TODO: Proper tab stops.
|
// TODO: Proper tab stops.
|
||||||
const TAB_COLS: i32 = 8;
|
const TAB_COLS: i32 = 8;
|
||||||
let font = self.font_and_shaping_options.font;
|
let (space_glyph_id, space_advance) = glyph_space_advance(self.font);
|
||||||
let (space_glyph_id, space_advance) = glyph_space_advance(font);
|
|
||||||
let advance = Au::from_f64_px(space_advance) * TAB_COLS;
|
let advance = Au::from_f64_px(space_advance) * TAB_COLS;
|
||||||
let data = GlyphData::new(space_glyph_id,
|
let data = GlyphData::new(space_glyph_id,
|
||||||
advance,
|
advance,
|
||||||
|
@ -557,13 +542,11 @@ extern fn font_table_func(_: *mut hb_face_t,
|
||||||
-> *mut hb_blob_t {
|
-> *mut hb_blob_t {
|
||||||
unsafe {
|
unsafe {
|
||||||
// NB: These asserts have security implications.
|
// NB: These asserts have security implications.
|
||||||
let font_and_shaping_options: *const FontAndShapingOptions =
|
let font = user_data as *const Font;
|
||||||
user_data as *const FontAndShapingOptions;
|
assert!(!font.is_null());
|
||||||
assert!(!font_and_shaping_options.is_null());
|
|
||||||
assert!(!(*font_and_shaping_options).font.is_null());
|
|
||||||
|
|
||||||
// TODO(Issue #197): reuse font table data, which will change the unsound trickery here.
|
// TODO(Issue #197): reuse font table data, which will change the unsound trickery here.
|
||||||
match (*(*font_and_shaping_options).font).table_for_tag(tag as FontTableTag) {
|
match (*font).table_for_tag(tag as FontTableTag) {
|
||||||
None => ptr::null_mut(),
|
None => ptr::null_mut(),
|
||||||
Some(font_table) => {
|
Some(font_table) => {
|
||||||
// `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer
|
// `Box::into_raw` intentionally leaks the FontTable so we don't destroy the buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue