1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00

fonts: remove some dead code

This commit is contained in:
Wez Furlong 2021-04-27 22:24:43 -07:00
parent d6c8eb1e3b
commit a2b068d59f
2 changed files with 3 additions and 75 deletions

View File

@ -1,5 +1,4 @@
//! Higher level harfbuzz bindings //! Higher level harfbuzz bindings
#![allow(dead_code)]
use freetype; use freetype;
pub use harfbuzz::*; pub use harfbuzz::*;
@ -7,7 +6,6 @@ pub use harfbuzz::*;
use anyhow::{ensure, Error}; use anyhow::{ensure, Error};
use std::mem; use std::mem;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::ptr;
use std::slice; use std::slice;
extern "C" { extern "C" {
@ -50,58 +48,6 @@ impl Drop for Font {
} }
} }
struct Blob {
blob: *mut hb_blob_t,
}
impl Drop for Blob {
fn drop(&mut self) {
unsafe {
hb_blob_destroy(self.blob);
}
}
}
impl Blob {
fn from_slice(data: &[u8]) -> Result<Self, Error> {
let blob = unsafe {
hb_blob_create(
data.as_ptr() as *const c_char,
data.len() as u32,
hb_memory_mode_t::HB_MEMORY_MODE_READONLY,
ptr::null_mut(),
None,
)
};
ensure!(!blob.is_null(), "failed to create harfbuzz blob for slice");
Ok(Self { blob })
}
}
struct Face {
face: *mut hb_face_t,
}
impl Drop for Face {
fn drop(&mut self) {
unsafe {
hb_face_destroy(self.face);
}
}
}
impl Face {
fn from_blob(blob: &Blob, idx: u32) -> Result<Face, Error> {
let face = unsafe { hb_face_create(blob.blob, idx) };
ensure!(
!face.is_null(),
"failed to create face from blob data at idx {}",
idx
);
Ok(Self { face })
}
}
impl Font { impl Font {
/// Create a harfbuzz face from a freetype font /// Create a harfbuzz face from a freetype font
pub fn new(face: freetype::FT_Face) -> Font { pub fn new(face: freetype::FT_Face) -> Font {
@ -114,18 +60,6 @@ impl Font {
} }
} }
/// Create a font from raw data
/// Harfbuzz doesn't know how to interpret this without registering
/// some callbacks
/// FIXME: need to specialize this for rusttype
pub fn new_from_slice(data: &[u8], idx: u32) -> Result<Font, Error> {
let blob = Blob::from_slice(data)?;
let face = Face::from_blob(&blob, idx)?;
let font = unsafe { hb_font_create(face.face) };
ensure!(!font.is_null(), "failed to convert face to font");
Ok(Self { font })
}
pub fn set_load_flags(&mut self, load_flags: freetype::FT_Int32) { pub fn set_load_flags(&mut self, load_flags: freetype::FT_Int32) {
unsafe { unsafe {
hb_ft_font_set_load_flags(self.font, load_flags); hb_ft_font_set_load_flags(self.font, load_flags);
@ -134,14 +68,8 @@ impl Font {
/// Perform shaping. On entry, Buffer holds the text to shape. /// Perform shaping. On entry, Buffer holds the text to shape.
/// Once done, Buffer holds the output glyph and position info /// Once done, Buffer holds the output glyph and position info
pub fn shape(&mut self, buf: &mut Buffer, features: Option<&[hb_feature_t]>) { pub fn shape(&mut self, buf: &mut Buffer, features: &[hb_feature_t]) {
unsafe { unsafe { hb_shape(self.font, buf.buf, features.as_ptr(), features.len() as u32) }
if let Some(features) = features {
hb_shape(self.font, buf.buf, features.as_ptr(), features.len() as u32)
} else {
hb_shape(self.font, buf.buf, ptr::null(), 0)
}
}
} }
} }

View File

@ -181,7 +181,7 @@ impl HarfbuzzShaper {
let (width, _height) = pair.face.set_font_size(font_size, dpi)?; let (width, _height) = pair.face.set_font_size(font_size, dpi)?;
cell_width = width; cell_width = width;
shaped_any = pair.shaped_any; shaped_any = pair.shaped_any;
pair.font.shape(&mut buf, Some(self.features.as_slice())); pair.font.shape(&mut buf, self.features.as_slice());
} }
None => { None => {
// Note: since we added a last resort font, this case // Note: since we added a last resort font, this case