2020-11-26 06:15:08 +03:00
|
|
|
use crate::db::FontDatabase;
|
2020-11-08 21:19:45 +03:00
|
|
|
use crate::locator::{new_locator, FontDataHandle, FontLocator, FontLocatorSelection};
|
|
|
|
use crate::rasterizer::{new_rasterizer, FontRasterizer};
|
|
|
|
use crate::shaper::{new_shaper, FontShaper, FontShaperSelection};
|
2020-11-26 01:53:42 +03:00
|
|
|
use anyhow::Error;
|
2020-11-08 21:19:45 +03:00
|
|
|
use config::{configuration, ConfigHandle, FontRasterizerSelection, TextStyle};
|
2018-02-07 20:23:24 +03:00
|
|
|
use std::cell::RefCell;
|
2020-10-12 02:51:55 +03:00
|
|
|
use std::collections::{HashMap, HashSet};
|
2020-11-25 05:03:32 +03:00
|
|
|
use std::rc::{Rc, Weak};
|
2020-11-08 21:19:45 +03:00
|
|
|
use wezterm_term::CellAttributes;
|
|
|
|
|
|
|
|
mod hbwrap;
|
2018-02-21 07:20:37 +03:00
|
|
|
|
2020-11-26 06:15:08 +03:00
|
|
|
pub mod db;
|
2019-12-10 00:56:34 +03:00
|
|
|
pub mod ftwrap;
|
2019-12-10 07:06:12 +03:00
|
|
|
pub mod locator;
|
2019-12-10 05:08:02 +03:00
|
|
|
pub mod parser;
|
2019-12-09 10:27:10 +03:00
|
|
|
pub mod rasterizer;
|
2019-12-09 11:06:47 +03:00
|
|
|
pub mod shaper;
|
2019-12-10 20:01:55 +03:00
|
|
|
pub mod units;
|
2019-12-09 09:48:47 +03:00
|
|
|
|
2019-12-10 07:26:58 +03:00
|
|
|
#[cfg(all(unix, not(target_os = "macos")))]
|
2018-02-21 07:55:03 +03:00
|
|
|
pub mod fcwrap;
|
2018-01-17 10:32:23 +03:00
|
|
|
|
2020-10-25 02:40:15 +03:00
|
|
|
pub use crate::rasterizer::RasterizedGlyph;
|
|
|
|
pub use crate::shaper::{FallbackIdx, FontMetrics, GlyphInfo};
|
2019-12-09 23:12:54 +03:00
|
|
|
|
|
|
|
pub struct LoadedFont {
|
2020-11-26 01:53:42 +03:00
|
|
|
rasterizers: RefCell<HashMap<FallbackIdx, Box<dyn FontRasterizer>>>,
|
2020-11-25 05:03:32 +03:00
|
|
|
handles: RefCell<Vec<FontDataHandle>>,
|
|
|
|
shaper: RefCell<Box<dyn FontShaper>>,
|
2019-12-10 00:17:40 +03:00
|
|
|
metrics: FontMetrics,
|
|
|
|
font_size: f64,
|
|
|
|
dpi: u32,
|
2020-11-25 05:03:32 +03:00
|
|
|
font_config: Weak<FontConfigInner>,
|
2019-12-10 00:17:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LoadedFont {
|
|
|
|
pub fn metrics(&self) -> FontMetrics {
|
|
|
|
self.metrics
|
|
|
|
}
|
|
|
|
|
2020-11-26 07:41:09 +03:00
|
|
|
fn insert_fallback_handles(&self, extra_handles: Vec<FontDataHandle>) -> anyhow::Result<bool> {
|
|
|
|
let mut loaded = false;
|
|
|
|
{
|
|
|
|
let mut handles = self.handles.borrow_mut();
|
|
|
|
for h in extra_handles {
|
|
|
|
if !handles.iter().any(|existing| *existing == h) {
|
|
|
|
match crate::parser::ParsedFont::from_locator(&h) {
|
|
|
|
Ok(_parsed) => {
|
|
|
|
let idx = handles.len() - 1;
|
|
|
|
handles.insert(idx, h);
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
log::error!("Failed to parse font from {:?}: {:?}", h, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if loaded {
|
|
|
|
*self.shaper.borrow_mut() =
|
|
|
|
new_shaper(FontShaperSelection::get_default(), &self.handles.borrow())?;
|
|
|
|
}
|
|
|
|
Ok(loaded)
|
|
|
|
}
|
|
|
|
|
2019-12-15 08:43:05 +03:00
|
|
|
pub fn shape(&self, text: &str) -> anyhow::Result<Vec<GlyphInfo>> {
|
2020-11-25 05:03:32 +03:00
|
|
|
let mut no_glyphs = vec![];
|
|
|
|
let result = self
|
|
|
|
.shaper
|
|
|
|
.borrow()
|
|
|
|
.shape(text, self.font_size, self.dpi, &mut no_glyphs);
|
|
|
|
|
|
|
|
if !no_glyphs.is_empty() {
|
|
|
|
no_glyphs.sort();
|
|
|
|
no_glyphs.dedup();
|
|
|
|
if let Some(font_config) = self.font_config.upgrade() {
|
2020-11-26 07:41:09 +03:00
|
|
|
let mut extra_handles = vec![];
|
|
|
|
let fallback_str = no_glyphs.iter().collect::<String>();
|
|
|
|
|
|
|
|
match font_config
|
|
|
|
.font_dirs
|
|
|
|
.borrow()
|
|
|
|
.locate_fallback_for_codepoints(&no_glyphs)
|
|
|
|
{
|
|
|
|
Ok(ref mut handles) => extra_handles.append(handles),
|
|
|
|
Err(err) => log::error!(
|
|
|
|
"Error: {} while resolving fallback for {} from font_dirs",
|
|
|
|
err,
|
|
|
|
fallback_str.escape_debug()
|
|
|
|
),
|
|
|
|
}
|
2020-11-25 05:03:32 +03:00
|
|
|
match font_config
|
|
|
|
.locator
|
|
|
|
.locate_fallback_for_codepoints(&no_glyphs)
|
|
|
|
{
|
2020-11-26 07:41:09 +03:00
|
|
|
Ok(ref mut handles) => extra_handles.append(handles),
|
2020-11-25 05:03:32 +03:00
|
|
|
Err(err) => log::error!(
|
2020-11-26 07:41:09 +03:00
|
|
|
"Error: {} while resolving fallback for {} from font-locator",
|
2020-11-25 05:03:32 +03:00
|
|
|
err,
|
2020-11-26 07:41:09 +03:00
|
|
|
fallback_str.escape_debug()
|
2020-11-25 05:03:32 +03:00
|
|
|
),
|
2020-11-26 07:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
match font_config
|
|
|
|
.built_in
|
|
|
|
.borrow()
|
|
|
|
.locate_fallback_for_codepoints(&no_glyphs)
|
|
|
|
{
|
|
|
|
Ok(ref mut handles) => extra_handles.append(handles),
|
|
|
|
Err(err) => log::error!(
|
|
|
|
"Error: {} while resolving fallback for {} for built-in fonts",
|
|
|
|
err,
|
|
|
|
fallback_str.escape_debug()
|
2020-11-26 01:53:42 +03:00
|
|
|
),
|
2020-11-26 07:41:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if extra_handles.is_empty() {
|
|
|
|
log::error!("No fonts have glyphs for {}", fallback_str.escape_debug());
|
|
|
|
} else {
|
|
|
|
let loaded = self.insert_fallback_handles(extra_handles)?;
|
|
|
|
if loaded {
|
|
|
|
log::trace!("handles is now: {:#?}", self.handles);
|
|
|
|
return self.shape(text);
|
|
|
|
} else {
|
|
|
|
log::error!(
|
|
|
|
"No fonts have glyphs for {}, even though fallback suggested some.",
|
|
|
|
fallback_str.escape_debug()
|
|
|
|
)
|
2020-11-25 05:03:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result
|
2019-12-10 00:17:40 +03:00
|
|
|
}
|
|
|
|
|
2020-11-24 03:59:30 +03:00
|
|
|
pub fn metrics_for_idx(&self, font_idx: usize) -> anyhow::Result<FontMetrics> {
|
|
|
|
self.shaper
|
2020-11-25 05:03:32 +03:00
|
|
|
.borrow()
|
2020-11-24 03:59:30 +03:00
|
|
|
.metrics_for_idx(font_idx, self.font_size, self.dpi)
|
|
|
|
}
|
|
|
|
|
2019-12-10 00:17:40 +03:00
|
|
|
pub fn rasterize_glyph(
|
|
|
|
&self,
|
|
|
|
glyph_pos: u32,
|
|
|
|
fallback: FallbackIdx,
|
2019-12-15 08:43:05 +03:00
|
|
|
) -> anyhow::Result<RasterizedGlyph> {
|
2020-11-26 01:53:42 +03:00
|
|
|
let mut rasterizers = self.rasterizers.borrow_mut();
|
|
|
|
if let Some(raster) = rasterizers.get(&fallback) {
|
|
|
|
raster.rasterize_glyph(glyph_pos, self.font_size, self.dpi)
|
|
|
|
} else {
|
2020-10-02 20:50:01 +03:00
|
|
|
let raster = new_rasterizer(
|
|
|
|
FontRasterizerSelection::get_default(),
|
2020-11-25 05:03:32 +03:00
|
|
|
&(self.handles.borrow())[fallback],
|
2020-10-02 20:50:01 +03:00
|
|
|
)?;
|
2020-11-26 01:53:42 +03:00
|
|
|
let result = raster.rasterize_glyph(glyph_pos, self.font_size, self.dpi);
|
|
|
|
rasterizers.insert(fallback, raster);
|
|
|
|
result
|
2019-12-15 02:36:50 +03:00
|
|
|
}
|
2019-12-10 00:17:40 +03:00
|
|
|
}
|
2019-12-09 23:12:54 +03:00
|
|
|
}
|
|
|
|
|
2020-11-25 05:03:32 +03:00
|
|
|
struct FontConfigInner {
|
2019-12-10 00:24:09 +03:00
|
|
|
fonts: RefCell<HashMap<TextStyle, Rc<LoadedFont>>>,
|
2019-02-23 00:34:48 +03:00
|
|
|
metrics: RefCell<Option<FontMetrics>>,
|
2019-02-23 01:52:35 +03:00
|
|
|
dpi_scale: RefCell<f64>,
|
|
|
|
font_scale: RefCell<f64>,
|
2019-11-24 21:01:23 +03:00
|
|
|
config_generation: RefCell<usize>,
|
2019-12-10 07:06:12 +03:00
|
|
|
locator: Box<dyn FontLocator>,
|
2020-11-26 06:21:51 +03:00
|
|
|
font_dirs: RefCell<FontDatabase>,
|
|
|
|
built_in: RefCell<FontDatabase>,
|
2019-02-19 09:02:31 +03:00
|
|
|
}
|
|
|
|
|
2020-11-25 05:03:32 +03:00
|
|
|
/// Matches and loads fonts for a given input style
|
|
|
|
pub struct FontConfiguration {
|
|
|
|
inner: Rc<FontConfigInner>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FontConfigInner {
|
2018-02-07 20:23:24 +03:00
|
|
|
/// Create a new empty configuration
|
2020-11-26 06:21:51 +03:00
|
|
|
pub fn new() -> anyhow::Result<Self> {
|
2020-10-02 20:50:01 +03:00
|
|
|
let locator = new_locator(FontLocatorSelection::get_default());
|
2020-11-26 06:21:51 +03:00
|
|
|
let config = configuration();
|
|
|
|
Ok(Self {
|
2018-02-07 20:23:24 +03:00
|
|
|
fonts: RefCell::new(HashMap::new()),
|
2019-12-10 07:06:12 +03:00
|
|
|
locator,
|
2019-02-23 00:34:48 +03:00
|
|
|
metrics: RefCell::new(None),
|
2019-02-23 01:52:35 +03:00
|
|
|
font_scale: RefCell::new(1.0),
|
|
|
|
dpi_scale: RefCell::new(1.0),
|
2020-11-26 06:21:51 +03:00
|
|
|
config_generation: RefCell::new(config.generation()),
|
|
|
|
font_dirs: RefCell::new(FontDatabase::with_font_dirs(&config)?),
|
|
|
|
built_in: RefCell::new(FontDatabase::with_built_in()?),
|
|
|
|
})
|
2018-02-07 20:23:24 +03:00
|
|
|
}
|
|
|
|
|
2019-12-10 00:24:09 +03:00
|
|
|
/// Given a text style, load (with caching) the font that best
|
|
|
|
/// matches according to the fontconfig pattern.
|
2020-11-25 05:03:32 +03:00
|
|
|
fn resolve_font(&self, myself: &Rc<Self>, style: &TextStyle) -> anyhow::Result<Rc<LoadedFont>> {
|
2019-12-10 00:24:09 +03:00
|
|
|
let mut fonts = self.fonts.borrow_mut();
|
|
|
|
|
|
|
|
let config = configuration();
|
|
|
|
let current_generation = config.generation();
|
|
|
|
if current_generation != *self.config_generation.borrow() {
|
|
|
|
// Config was reloaded, invalidate our caches
|
|
|
|
fonts.clear();
|
|
|
|
self.metrics.borrow_mut().take();
|
2020-11-26 06:21:51 +03:00
|
|
|
*self.font_dirs.borrow_mut() = FontDatabase::with_font_dirs(&config)?;
|
2019-12-10 00:24:09 +03:00
|
|
|
*self.config_generation.borrow_mut() = current_generation;
|
|
|
|
}
|
|
|
|
|
2019-12-09 23:46:58 +03:00
|
|
|
if let Some(entry) = fonts.get(style) {
|
|
|
|
return Ok(Rc::clone(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
let attributes = style.font_with_fallback();
|
2020-10-13 03:05:53 +03:00
|
|
|
let preferred_attributes = attributes
|
|
|
|
.iter()
|
|
|
|
.filter(|a| !a.is_fallback)
|
|
|
|
.map(|a| a.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let fallback_attributes = attributes
|
|
|
|
.iter()
|
|
|
|
.filter(|a| a.is_fallback)
|
|
|
|
.map(|a| a.clone())
|
|
|
|
.collect::<Vec<_>>();
|
2020-10-12 02:51:55 +03:00
|
|
|
let mut loaded = HashSet::new();
|
2020-10-13 03:05:53 +03:00
|
|
|
|
2020-11-26 06:15:08 +03:00
|
|
|
let mut handles = vec![];
|
|
|
|
for attrs in &[&preferred_attributes, &fallback_attributes] {
|
2020-11-26 06:21:51 +03:00
|
|
|
self.font_dirs
|
|
|
|
.borrow()
|
|
|
|
.resolve_multiple(attrs, &mut handles, &mut loaded);
|
2020-11-26 06:15:08 +03:00
|
|
|
handles.append(&mut self.locator.load_fonts(attrs, &mut loaded)?);
|
2020-11-26 06:21:51 +03:00
|
|
|
self.built_in
|
|
|
|
.borrow()
|
|
|
|
.resolve_multiple(attrs, &mut handles, &mut loaded);
|
2020-11-26 06:15:08 +03:00
|
|
|
}
|
2020-10-12 02:51:55 +03:00
|
|
|
|
|
|
|
for attr in &attributes {
|
|
|
|
if !attr.is_fallback && !loaded.contains(attr) {
|
2020-11-24 19:49:26 +03:00
|
|
|
let styled_extra = if attr.bold || attr.italic {
|
|
|
|
". A bold or italic variant of the font was requested; \
|
|
|
|
TrueType and OpenType fonts don't have an automatic way to \
|
|
|
|
produce these font variants, so a separate font file containing \
|
|
|
|
the bold or italic variant must be installed"
|
|
|
|
} else {
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
let is_primary = config.font.font.iter().any(|a| a == attr);
|
|
|
|
let derived_from_primary = config.font.font.iter().any(|a| a.family == attr.family);
|
|
|
|
|
|
|
|
let explanation = if is_primary {
|
|
|
|
// This is the primary font selection
|
|
|
|
format!(
|
|
|
|
"Unable to load a font specified by your font={} configuration",
|
|
|
|
attr
|
|
|
|
)
|
|
|
|
} else if derived_from_primary {
|
|
|
|
// it came from font_rules and may have been derived from
|
|
|
|
// their primary font (we can't know for sure)
|
|
|
|
format!(
|
|
|
|
"Unable to load a font matching one of your font_rules: {}. \
|
|
|
|
Note that wezterm will synthesize font_rules to select bold \
|
|
|
|
and italic fonts based on your primary font configuration",
|
|
|
|
attr
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"Unable to load a font matching one of your font_rules: {}",
|
|
|
|
attr
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2020-10-25 02:40:15 +03:00
|
|
|
mux::connui::show_configuration_error_message(&format!(
|
2020-11-24 19:49:26 +03:00
|
|
|
"{}. Fallback(s) are being used instead, and the terminal \
|
|
|
|
may not render as intended{}. See \
|
|
|
|
https://wezfurlong.org/wezterm/config/fonts.html for more information",
|
|
|
|
explanation, styled_extra
|
2020-10-12 02:51:55 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 20:50:01 +03:00
|
|
|
let shaper = new_shaper(FontShaperSelection::get_default(), &handles)?;
|
2019-12-09 23:46:58 +03:00
|
|
|
|
2019-12-10 00:17:40 +03:00
|
|
|
let config = configuration();
|
|
|
|
let font_size = config.font_size * *self.font_scale.borrow();
|
2020-12-10 00:09:18 +03:00
|
|
|
let dpi =
|
|
|
|
*self.dpi_scale.borrow() as u32 * config.dpi.unwrap_or(::window::DEFAULT_DPI) as u32;
|
2019-12-10 00:17:40 +03:00
|
|
|
let metrics = shaper.metrics(font_size, dpi)?;
|
|
|
|
|
2019-12-09 23:46:58 +03:00
|
|
|
let loaded = Rc::new(LoadedFont {
|
2020-11-26 01:53:42 +03:00
|
|
|
rasterizers: RefCell::new(HashMap::new()),
|
2020-11-25 05:03:32 +03:00
|
|
|
handles: RefCell::new(handles),
|
|
|
|
shaper: RefCell::new(shaper),
|
2019-12-10 00:17:40 +03:00
|
|
|
metrics,
|
|
|
|
font_size,
|
|
|
|
dpi,
|
2020-11-25 05:03:32 +03:00
|
|
|
font_config: Rc::downgrade(myself),
|
2019-12-09 23:46:58 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
fonts.insert(style.clone(), Rc::clone(&loaded));
|
|
|
|
|
|
|
|
Ok(loaded)
|
|
|
|
}
|
|
|
|
|
2019-02-23 01:52:35 +03:00
|
|
|
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) {
|
|
|
|
*self.dpi_scale.borrow_mut() = dpi_scale;
|
|
|
|
*self.font_scale.borrow_mut() = font_scale;
|
|
|
|
self.fonts.borrow_mut().clear();
|
|
|
|
self.metrics.borrow_mut().take();
|
|
|
|
}
|
|
|
|
|
2018-02-07 20:23:24 +03:00
|
|
|
/// Returns the baseline font specified in the configuration
|
2020-11-25 05:03:32 +03:00
|
|
|
pub fn default_font(&self, myself: &Rc<Self>) -> anyhow::Result<Rc<LoadedFont>> {
|
|
|
|
self.resolve_font(myself, &configuration().font)
|
2018-02-07 20:23:24 +03:00
|
|
|
}
|
|
|
|
|
2019-02-23 01:52:35 +03:00
|
|
|
pub fn get_font_scale(&self) -> f64 {
|
|
|
|
*self.font_scale.borrow()
|
|
|
|
}
|
|
|
|
|
2020-11-25 05:03:32 +03:00
|
|
|
pub fn default_font_metrics(&self, myself: &Rc<Self>) -> Result<FontMetrics, Error> {
|
2019-02-23 00:34:48 +03:00
|
|
|
{
|
|
|
|
let metrics = self.metrics.borrow();
|
|
|
|
if let Some(metrics) = metrics.as_ref() {
|
|
|
|
return Ok(*metrics);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 05:03:32 +03:00
|
|
|
let font = self.default_font(myself)?;
|
2019-12-10 00:24:09 +03:00
|
|
|
let metrics = font.metrics();
|
2019-02-23 00:34:48 +03:00
|
|
|
|
2019-02-24 21:33:21 +03:00
|
|
|
*self.metrics.borrow_mut() = Some(metrics);
|
2019-02-23 00:34:48 +03:00
|
|
|
|
|
|
|
Ok(metrics)
|
|
|
|
}
|
|
|
|
|
2018-02-07 20:23:24 +03:00
|
|
|
/// Apply the defined font_rules from the user configuration to
|
|
|
|
/// produce the text style that best matches the supplied input
|
|
|
|
/// cell attributes.
|
2019-11-24 19:55:55 +03:00
|
|
|
pub fn match_style<'a>(
|
|
|
|
&self,
|
2019-11-24 20:19:14 +03:00
|
|
|
config: &'a ConfigHandle,
|
2019-11-24 19:55:55 +03:00
|
|
|
attrs: &CellAttributes,
|
|
|
|
) -> &'a TextStyle {
|
2018-02-07 20:23:24 +03:00
|
|
|
// a little macro to avoid boilerplate for matching the rules.
|
|
|
|
// If the rule doesn't specify a value for an attribute then
|
|
|
|
// it will implicitly match. If it specifies an attribute
|
|
|
|
// then it has to have the same value as that in the input attrs.
|
|
|
|
macro_rules! attr_match {
|
|
|
|
($ident:ident, $rule:expr) => {
|
|
|
|
if let Some($ident) = $rule.$ident {
|
|
|
|
if $ident != attrs.$ident() {
|
|
|
|
// Does not match
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// matches so far...
|
2018-04-11 23:15:12 +03:00
|
|
|
};
|
2018-02-07 20:23:24 +03:00
|
|
|
};
|
|
|
|
|
2019-11-24 19:55:55 +03:00
|
|
|
for rule in &config.font_rules {
|
2018-02-07 20:23:24 +03:00
|
|
|
attr_match!(intensity, &rule);
|
|
|
|
attr_match!(underline, &rule);
|
|
|
|
attr_match!(italic, &rule);
|
|
|
|
attr_match!(blink, &rule);
|
|
|
|
attr_match!(reverse, &rule);
|
|
|
|
attr_match!(strikethrough, &rule);
|
|
|
|
attr_match!(invisible, &rule);
|
|
|
|
|
|
|
|
// If we get here, then none of the rules didn't match,
|
|
|
|
// so we therefore assume that it did match overall.
|
|
|
|
return &rule.font;
|
|
|
|
}
|
2019-11-24 19:55:55 +03:00
|
|
|
&config.font
|
2018-02-07 20:23:24 +03:00
|
|
|
}
|
|
|
|
}
|
2020-11-25 05:03:32 +03:00
|
|
|
|
|
|
|
impl FontConfiguration {
|
|
|
|
/// Create a new empty configuration
|
2020-11-26 06:21:51 +03:00
|
|
|
pub fn new() -> anyhow::Result<Self> {
|
|
|
|
let inner = Rc::new(FontConfigInner::new()?);
|
|
|
|
Ok(Self { inner })
|
2020-11-25 05:03:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a text style, load (with caching) the font that best
|
|
|
|
/// matches according to the fontconfig pattern.
|
|
|
|
pub fn resolve_font(&self, style: &TextStyle) -> anyhow::Result<Rc<LoadedFont>> {
|
|
|
|
self.inner.resolve_font(&self.inner, style)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn change_scaling(&self, font_scale: f64, dpi_scale: f64) {
|
|
|
|
self.inner.change_scaling(font_scale, dpi_scale)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the baseline font specified in the configuration
|
|
|
|
pub fn default_font(&self) -> anyhow::Result<Rc<LoadedFont>> {
|
|
|
|
self.inner.default_font(&self.inner)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_font_scale(&self) -> f64 {
|
|
|
|
self.inner.get_font_scale()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default_font_metrics(&self) -> Result<FontMetrics, Error> {
|
|
|
|
self.inner.default_font_metrics(&self.inner)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Apply the defined font_rules from the user configuration to
|
|
|
|
/// produce the text style that best matches the supplied input
|
|
|
|
/// cell attributes.
|
|
|
|
pub fn match_style<'a>(
|
|
|
|
&self,
|
|
|
|
config: &'a ConfigHandle,
|
|
|
|
attrs: &CellAttributes,
|
|
|
|
) -> &'a TextStyle {
|
|
|
|
self.inner.match_style(config, attrs)
|
|
|
|
}
|
|
|
|
}
|