mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 13:21:38 +03:00
start integrating rusttype and font_loader for windows
This commit is contained in:
parent
434c1a1664
commit
a4e1bd827e
@ -28,6 +28,10 @@ path = "term"
|
||||
[dependencies.termwiz]
|
||||
path = "termwiz"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
font-loader = "0.8"
|
||||
rusttype = "0.7"
|
||||
|
||||
[target.'cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))'.dependencies]
|
||||
freetype = "~0.4"
|
||||
servo-fontconfig = "~0.4"
|
||||
|
@ -25,9 +25,9 @@ pub mod coretext;
|
||||
use self::coretext::FontSystemImpl;
|
||||
|
||||
#[cfg(windows)]
|
||||
pub mod windows;
|
||||
pub mod rtype;
|
||||
#[cfg(windows)]
|
||||
use self::windows::FontSystemImpl;
|
||||
use self::rtype::FontSystemImpl;
|
||||
|
||||
use super::config::{Config, TextStyle};
|
||||
use term::CellAttributes;
|
||||
|
87
src/font/rtype.rs
Normal file
87
src/font/rtype.rs
Normal file
@ -0,0 +1,87 @@
|
||||
//! Systems using rust native rasterizer
|
||||
|
||||
use super::hbwrap as harfbuzz;
|
||||
use config::{Config, TextStyle};
|
||||
use failure::{self, Error};
|
||||
use font::{
|
||||
shape_with_harfbuzz, FallbackIdx, Font, FontMetrics, FontSystem, GlyphInfo, NamedFont,
|
||||
RasterizedGlyph,
|
||||
};
|
||||
use font_loader::system_fonts;
|
||||
use rusttype::{Font as RTFont, FontCollection, Scale};
|
||||
|
||||
struct NamedFontImpl<'a> {
|
||||
collection: FontCollection<'a>,
|
||||
font: RTFont<'a>,
|
||||
scale: Scale,
|
||||
}
|
||||
|
||||
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) -> Result<Box<NamedFont>, Error> {
|
||||
let font_props = system_fonts::FontPropertyBuilder::new()
|
||||
.family(&style.fontconfig_pattern)
|
||||
.monospace()
|
||||
.build();
|
||||
let (data, idx) = system_fonts::get(&font_props)
|
||||
.ok_or_else(|| format_err!("no font matching {:?}", style))?;
|
||||
let collection = FontCollection::from_bytes(data)?;
|
||||
let font = collection.font_at(idx as usize)?;
|
||||
eprintln!("made a font for {:?}", style);
|
||||
let scale = Scale::uniform(config.font_size as f32 * 96.0 / 72.0);
|
||||
Ok(Box::new(NamedFontImpl {
|
||||
collection,
|
||||
font,
|
||||
scale,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> NamedFont for NamedFontImpl<'a> {
|
||||
fn get_fallback(&mut self, idx: FallbackIdx) -> Result<&Font, Error> {
|
||||
ensure!(idx == 0, "no fallback fonts available");
|
||||
Ok(self)
|
||||
}
|
||||
fn shape(&mut self, s: &str) -> Result<Vec<GlyphInfo>, Error> {
|
||||
shape_with_harfbuzz(self, 0, s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Font for NamedFontImpl<'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 vmetrics = self.font.v_metrics(self.scale);
|
||||
let hmetrics = self
|
||||
.font
|
||||
.glyph(rusttype::Codepoint(33))
|
||||
.scaled(self.scale)
|
||||
.h_metrics();
|
||||
FontMetrics {
|
||||
cell_height: f64::from(vmetrics.ascent - vmetrics.descent + vmetrics.line_gap),
|
||||
cell_width: hmetrics.advance_width.into(),
|
||||
descender: vmetrics.descent as i16,
|
||||
}
|
||||
}
|
||||
|
||||
fn rasterize_glyph(&self, glyph_pos: u32) -> Result<RasterizedGlyph, Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
use config::{Config, TextStyle};
|
||||
use failure::{self, Error};
|
||||
use font::{
|
||||
shape_with_harfbuzz, FallbackIdx, Font, FontMetrics, FontSystem, GlyphInfo, NamedFont,
|
||||
RasterizedGlyph,
|
||||
};
|
||||
|
||||
pub type FontSystemImpl = WindowsFonts;
|
||||
pub struct WindowsFonts {}
|
||||
impl WindowsFonts {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl FontSystem for WindowsFonts {
|
||||
fn load_font(&self, config: &Config, style: &TextStyle) -> Result<Box<NamedFont>, Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
@ -27,6 +27,12 @@ extern crate term;
|
||||
extern crate termwiz;
|
||||
extern crate toml;
|
||||
extern crate unicode_width;
|
||||
|
||||
#[cfg(windows)]
|
||||
extern crate font_loader;
|
||||
#[cfg(windows)]
|
||||
extern crate rusttype;
|
||||
|
||||
#[macro_use]
|
||||
pub mod log;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user