1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 13:52:55 +03:00

remove rusttype

This commit is contained in:
Wez Furlong 2019-03-23 13:45:26 -07:00
parent 40844962f3
commit 10b3460c49
4 changed files with 1 additions and 236 deletions

View File

@ -17,7 +17,6 @@ serde_derive = "~1.0"
toml = "~0.4"
unicode-width = "~0.1"
dirs = "~1.0"
rusttype = "0.7"
clipboard = "0.5"
unicode-normalization = "~0.1"
freetype = { path = "deps/freetype" }
@ -101,7 +100,6 @@ core-foundation = "0.6"
[features]
debug-escape-sequences = ["term/debug-escape-sequences"]
force-glutin = []
force-rusttype = []
force-fontconfig = ["fontconfig"]
[patch.crates-io]

View File

@ -1,98 +0,0 @@
//! Systems using rust native loader and rasterizer
use crate::config::{Config, TextStyle};
use crate::font::fontloader;
use crate::font::rtype::RustTypeFontImpl;
use crate::font::{FallbackIdx, Font, FontSystem, GlyphInfo, NamedFont};
use failure::Error;
use rusttype::{point, Codepoint, ScaledGlyph};
struct NamedFontImpl<'a> {
fonts: Vec<RustTypeFontImpl<'a>>,
}
pub type FontSystemImpl = RustTypeFonts;
pub struct RustTypeFonts {}
impl RustTypeFonts {
pub fn new() -> Self {
Self {}
}
}
impl FontSystem for RustTypeFonts {
fn load_font(
&self,
config: &Config,
style: &TextStyle,
font_scale: f64,
) -> Result<Box<NamedFont>, Error> {
let mut fonts = Vec::new();
for (data, idx) in fontloader::load_system_fonts(config, style)? {
eprintln!("want idx {} in bytes of len {}", idx, data.len());
fonts.push(RustTypeFontImpl::from_bytes(
data,
idx,
font_scale as f32 * config.font_size as f32 * config.dpi as f32 / 72.0,
)?);
}
Ok(Box::new(NamedFontImpl { fonts }))
}
}
impl<'a> NamedFontImpl<'a> {
pub fn glyph(&mut self, c: char) -> Result<(ScaledGlyph, usize), Error> {
let codepoint = Codepoint(c as u32);
for (idx, font) in self.fonts.iter().enumerate() {
let g = font.font.glyph(codepoint);
if g.id().0 == 0 {
// notdef; continue looking in the fallbacks
continue;
}
return Ok((g.scaled(font.scale), idx));
}
if c != '?' {
return match self.glyph('?') {
Ok((g, idx)) => Ok((g, idx)),
Err(_) => bail!("unable to resolve glyph for char={} or the fallback ?", c),
};
}
bail!("unable to resolve glyph for ?");
}
}
impl<'a> NamedFont for NamedFontImpl<'a> {
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&Font, Error> {
self.fonts
.get(idx)
.map(|f| {
let f: &Font = f;
f
})
.ok_or_else(|| format_err!("no fallback fonts available (idx={})", idx))
}
fn shape(&mut self, s: &str) -> Result<Vec<GlyphInfo>, Error> {
let mut shaped = Vec::new();
let mut cluster = 0;
for c in s.chars() {
let (glyph, font_idx) = self.glyph(c)?;
let hmetrics = glyph.h_metrics();
let glyph = glyph.positioned(point(0.0, 0.0));
shaped.push(GlyphInfo {
#[cfg(debug_assertions)]
text: c.to_string(),
cluster: cluster as u32,
num_cells: 1,
font_idx,
glyph_pos: glyph.id().0,
x_advance: hmetrics.advance_width.into(),
x_offset: (-hmetrics.left_side_bearing).into(),
y_advance: 0.0,
y_offset: 0.0, //(-bounds.max.y).into(),
// vmetrics.descent.into(),
});
cluster += c.len_utf8();
}
Ok(shaped)
}
}

View File

@ -26,9 +26,6 @@ pub mod coretext;
pub mod fontloader;
#[cfg(any(target_os = "macos", windows))]
pub mod fontloader_and_freetype;
#[cfg(any(target_os = "macos", windows))]
pub mod fontloader_and_rusttype;
pub mod rtype;
use super::config::{Config, TextStyle};
use term::CellAttributes;
@ -49,20 +46,13 @@ pub struct FontConfiguration {
pub enum FontSystemSelection {
FontConfigAndFreeType,
FontLoaderAndFreeType,
FontLoaderAndRustType,
CoreText,
}
impl Default for FontSystemSelection {
fn default() -> Self {
if cfg!(all(
unix,
not(target_os = "macos"),
not(feature = "force-rusttype")
)) {
if cfg!(all(unix, not(target_os = "macos"),)) {
FontSystemSelection::FontConfigAndFreeType
} else if cfg!(feature = "force-rusttype") {
FontSystemSelection::FontLoaderAndRustType
/*
} else if cfg!(target_os = "macos") {
FontSystemSelection::CoreText
@ -95,12 +85,6 @@ impl FontSystemSelection {
#[cfg(not(any(target_os = "macos", windows)))]
panic!("font-loader not compiled in");
}
FontSystemSelection::FontLoaderAndRustType => {
#[cfg(any(target_os = "macos", windows))]
return Rc::new(fontloader_and_rusttype::FontSystemImpl::new());
#[cfg(not(any(target_os = "macos", windows)))]
panic!("font-loader not compiled in");
}
FontSystemSelection::CoreText => {
#[cfg(target_os = "macos")]
return Rc::new(coretext::FontSystemImpl::new());
@ -135,7 +119,6 @@ impl std::str::FromStr for FontSystemSelection {
match s.to_lowercase().as_ref() {
"fontconfigandfreetype" => Ok(FontSystemSelection::FontConfigAndFreeType),
"fontloaderandfreetype" => Ok(FontSystemSelection::FontLoaderAndFreeType),
"fontloaderandrusttype" => Ok(FontSystemSelection::FontLoaderAndRustType),
"coretext" => Ok(FontSystemSelection::CoreText),
_ => Err(format_err!(
"{} is not a valid FontSystemSelection variant, possible values are {:?}",

View File

@ -1,118 +0,0 @@
//! Systems using rust native rasterizer
use super::hbwrap as harfbuzz;
use crate::font::{Font, FontMetrics, RasterizedGlyph};
use failure::Error;
use rusttype::{
point, Codepoint, Font as RTFont, FontCollection, PositionedGlyph, Rect, Scale, VMetrics,
};
pub struct RustTypeFontImpl<'a> {
_collection: FontCollection<'a>,
pub(crate) font: RTFont<'a>,
pub(crate) scale: Scale,
vmetrics: VMetrics,
cell_height: f64,
}
impl<'a> RustTypeFontImpl<'a> {
pub fn from_bytes(data: Vec<u8>, idx: i32, size: f32) -> Result<Self, Error> {
let collection = FontCollection::from_bytes(data)?;
// Most likely problem is that we matched an OpenType font and rusttype can't
// load it today.
let font = collection.font_at(idx as usize).map_err(|e| {
format_err!(
"{} (Note that rusttype only supports TrueType font files!)",
e
)
})?;
let scale = Scale::uniform(size);
let vmetrics = font.v_metrics(scale);
eprintln!("vmetrics {:?}", vmetrics);
let cell_height = f64::from(vmetrics.ascent - vmetrics.descent + vmetrics.line_gap);
Ok(RustTypeFontImpl {
_collection: collection,
cell_height,
font,
scale,
vmetrics,
})
}
}
fn bounds(g: &PositionedGlyph) -> Rect<f64> {
match g.pixel_bounding_box() {
Some(bounds) => rusttype::Rect {
min: point(bounds.min.x as f64, bounds.min.y as f64),
max: point(bounds.max.x as f64, bounds.max.y as f64),
},
None => rusttype::Rect {
min: point(0.0, 0.0),
max: point(0.0, 0.0),
},
}
}
impl<'a> Font for RustTypeFontImpl<'a> {
fn harfbuzz_shape(
&self,
_buf: &mut harfbuzz::Buffer,
_features: Option<&[harfbuzz::hb_feature_t]>,
) {
unimplemented!();
}
fn has_color(&self) -> bool {
false
}
fn metrics(&self) -> FontMetrics {
let hmetrics = self
.font
.glyph(Codepoint(33))
.scaled(self.scale)
.h_metrics();
FontMetrics {
cell_height: self.cell_height,
cell_width: hmetrics.advance_width.into(),
descender: self.vmetrics.descent as f64 / 64.0,
}
}
fn rasterize_glyph(&self, glyph_pos: u32) -> Result<RasterizedGlyph, Error> {
let g = self
.font
.glyph(rusttype::GlyphId(glyph_pos))
.scaled(self.scale)
.positioned(point(0.0, 0.0));
let bounds = bounds(&g);
let width = bounds.width() as usize;
let height = bounds.height() as usize;
let mut data = Vec::with_capacity(width * height * 4);
g.draw(|_x, _y, value| {
let v = (value * 255.0) as u8;
data.push(v); // alpha
data.push(v); // red
data.push(v); // green
data.push(v); // blue
});
/*
eprintln!(
"rasterize_glyph {} {}x{} {} bounds {:?}",
glyph_pos, width, height, self.cell_height, bounds
);
*/
// FIXME: there's something funky about either the bearing
// calculation here or the y_offset calculation in the
// shape function that causes the baseline to vary and
// the text look crazy.
Ok(RasterizedGlyph {
data,
height,
width,
bearing_x: bounds.min.x,
bearing_y: -bounds.min.y,
})
}
}