mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Simplify FontTableMethods::with_buffer
This commit is contained in:
parent
2d5dc8fa6d
commit
1eab6fbb2e
4 changed files with 9 additions and 11 deletions
|
@ -68,7 +68,7 @@ impl FontTableTagConversions for FontTableTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FontTableMethods {
|
pub trait FontTableMethods {
|
||||||
fn with_buffer<F>(&self, F) where F: FnOnce(*const u8, usize);
|
fn buffer(&self) -> &[u8];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|
|
@ -40,8 +40,8 @@ pub struct FontTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontTableMethods for FontTable {
|
impl FontTableMethods for FontTable {
|
||||||
fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, usize) {
|
fn buffer(&self) -> &[u8] {
|
||||||
blk(self.buffer.as_ptr(), self.buffer.len())
|
&self.buffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ impl FontTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FontTableMethods for FontTable {
|
impl FontTableMethods for FontTable {
|
||||||
fn with_buffer<F>(&self, blk: F) where F: FnOnce(*const u8, usize) {
|
fn buffer(&self) -> &[u8] {
|
||||||
blk(self.data.bytes().as_ptr(), self.data.len() as usize);
|
self.data.bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -529,15 +529,13 @@ extern fn font_table_func(_: *mut hb_face_t,
|
||||||
// this raw pointer back to `destroy_blob_func` which will deallocate the Box.
|
// this raw pointer back to `destroy_blob_func` which will deallocate the Box.
|
||||||
let font_table_ptr = Box::into_raw(font_table);
|
let font_table_ptr = Box::into_raw(font_table);
|
||||||
|
|
||||||
let mut blob: *mut hb_blob_t = ptr::null_mut();
|
let buf = (*font_table_ptr).buffer();
|
||||||
(*font_table_ptr).with_buffer(|buf: *const u8, len: usize| {
|
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed.
|
||||||
// HarfBuzz calls `destroy_blob_func` when the buffer is no longer needed.
|
let blob = hb_blob_create(buf.as_ptr() as *const c_char,
|
||||||
blob = hb_blob_create(buf as *const c_char,
|
buf.len() as c_uint,
|
||||||
len as c_uint,
|
|
||||||
HB_MEMORY_MODE_READONLY,
|
HB_MEMORY_MODE_READONLY,
|
||||||
font_table_ptr as *mut c_void,
|
font_table_ptr as *mut c_void,
|
||||||
Some(destroy_blob_func));
|
Some(destroy_blob_func));
|
||||||
});
|
|
||||||
|
|
||||||
assert!(!blob.is_null());
|
assert!(!blob.is_null());
|
||||||
blob
|
blob
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue