1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-02 23:55:11 +03:00

extract fontloader loader from fontloader_and_rusttype

This commit is contained in:
Wez Furlong 2019-02-18 13:28:25 -08:00
parent 9de24a75ed
commit 1039e013c1
3 changed files with 32 additions and 19 deletions

29
src/font/fontloader.rs Normal file
View File

@ -0,0 +1,29 @@
use config::{Config, TextStyle};
use failure::Error;
use font_loader::system_fonts;
pub fn load_system_fonts(config: &Config, style: &TextStyle) -> Result<Vec<(Vec<u8>, i32)>, Error> {
let mut fonts = Vec::new();
for font_attr in &style.font {
let mut font_props = system_fonts::FontPropertyBuilder::new()
.family(&font_attr.family)
.monospace();
font_props = if *font_attr.bold.as_ref().unwrap_or(&false) {
font_props.bold()
} else {
font_props
};
font_props = if *font_attr.italic.as_ref().unwrap_or(&false) {
font_props.italic()
} else {
font_props
};
let font_props = font_props.build();
fonts.push(
system_fonts::get(&font_props)
.ok_or_else(|| format_err!("no font matching {:?}", font_attr))?,
);
}
Ok(fonts)
}

View File

@ -3,6 +3,7 @@
use super::hbwrap as harfbuzz;
use config::{Config, TextStyle};
use failure::Error;
use font::fontloader;
use font::rtype::RustTypeFontImpl;
use font::{FallbackIdx, Font, FontMetrics, FontSystem, GlyphInfo, NamedFont, RasterizedGlyph};
use font_loader::system_fonts;
@ -27,24 +28,7 @@ impl RustTypeFonts {
impl FontSystem for RustTypeFonts {
fn load_font(&self, config: &Config, style: &TextStyle) -> Result<Box<NamedFont>, Error> {
let mut fonts = Vec::new();
for font_attr in &style.font {
let mut font_props = system_fonts::FontPropertyBuilder::new()
.family(&font_attr.family)
.monospace();
font_props = if *font_attr.bold.as_ref().unwrap_or(&false) {
font_props.bold()
} else {
font_props
};
font_props = if *font_attr.italic.as_ref().unwrap_or(&false) {
font_props.italic()
} else {
font_props
};
let font_props = font_props.build();
let (data, idx) = system_fonts::get(&font_props)
.ok_or_else(|| format_err!("no font matching {:?}", font_attr))?;
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,

View File

@ -26,10 +26,10 @@ pub mod coretext;
#[cfg(all(target_os = "macos", not(feature = "force-rusttype")))]
use self::coretext::FontSystemImpl;
pub mod fontloader;
#[cfg(any(windows, feature = "force-rusttype"))]
pub mod fontloader_and_rusttype;
pub mod rtype;
#[cfg(any(windows, feature = "force-rusttype"))]
use self::fontloader_and_rusttype::FontSystemImpl;