1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 22:33:52 +03:00

fonts: synthesize dim when a light weight font is unavailable

This commit is contained in:
Wez Furlong 2021-05-30 20:52:10 -07:00
parent cb4da18021
commit 717a2157f6
5 changed files with 39 additions and 4 deletions

View File

@ -25,7 +25,7 @@ As features stabilize some brief notes about them will accumulate here.
* Fixed: errors loading custom color schemes are now logged to the error log [#794](https://github.com/wez/wezterm/issues/794) * Fixed: errors loading custom color schemes are now logged to the error log [#794](https://github.com/wez/wezterm/issues/794)
* Fixed: OSC 7 (current working directory) now works with paths that contain spaces and other special characters. Thanks to [@Arvedui](https://github.com/Arvedui)! [#799](https://github.com/wez/wezterm/pull/799) * Fixed: OSC 7 (current working directory) now works with paths that contain spaces and other special characters. Thanks to [@Arvedui](https://github.com/Arvedui)! [#799](https://github.com/wez/wezterm/pull/799)
* Changed: the homebrew tap is now a Cask that installs to the /Applications directory on macOS. Thanks to [@laggardkernel](https://github.com/laggardkernel)! * Changed: the homebrew tap is now a Cask that installs to the /Applications directory on macOS. Thanks to [@laggardkernel](https://github.com/laggardkernel)!
* New: bold and/or italics are now synthesized for fonts when the matching font is not actually italic or doesn't match the requested weight. [#815](https://github.com/wez/wezterm/issues/815) * New: bold/dim and/or italics are now synthesized for fonts when the matching font is not actually italic or doesn't match the requested weight. [#815](https://github.com/wez/wezterm/issues/815)
* Updated: conpty.dll to v1.9.1445.0; fixes color bar artifacts when resizing window and allows win32 console applications to use mouse events * Updated: conpty.dll to v1.9.1445.0; fixes color bar artifacts when resizing window and allows win32 console applications to use mouse events
* Fixed: Windows: pane could linger after the process has died, closing only when a new pane/tab event occurs * Fixed: Windows: pane could linger after the process has died, closing only when a new pane/tab event occurs
* Fixed: Windows: first character after `wezterm ssh` keyboard authention was swallowed [#771](https://github.com/wez/wezterm/issues/771) * Fixed: Windows: first character after `wezterm ssh` keyboard authention was swallowed [#771](https://github.com/wez/wezterm/issues/771)

View File

@ -123,6 +123,20 @@ impl LoadedFont {
.metrics_for_idx(font_idx, self.font_size, self.dpi) .metrics_for_idx(font_idx, self.font_size, self.dpi)
} }
pub fn brightness_adjust(&self, font_idx: usize) -> f32 {
let synthesize_dim = self
.handles
.borrow()
.get(font_idx)
.map(|p| p.synthesize_dim)
.unwrap_or(false);
if synthesize_dim {
0.5
} else {
1.0
}
}
pub fn rasterize_glyph( pub fn rasterize_glyph(
&self, &self,
glyph_pos: u32, glyph_pos: u32,

View File

@ -23,6 +23,7 @@ pub struct ParsedFont {
coverage: Mutex<RangeSet<u32>>, coverage: Mutex<RangeSet<u32>>,
pub synthesize_italic: bool, pub synthesize_italic: bool,
pub synthesize_bold: bool, pub synthesize_bold: bool,
pub synthesize_dim: bool,
} }
impl std::fmt::Debug for ParsedFont { impl std::fmt::Debug for ParsedFont {
@ -47,6 +48,7 @@ impl Clone for ParsedFont {
italic: self.italic, italic: self.italic,
synthesize_italic: self.synthesize_italic, synthesize_italic: self.synthesize_italic,
synthesize_bold: self.synthesize_bold, synthesize_bold: self.synthesize_bold,
synthesize_dim: self.synthesize_dim,
handle: self.handle.clone(), handle: self.handle.clone(),
cap_height: self.cap_height.clone(), cap_height: self.cap_height.clone(),
coverage: Mutex::new(self.coverage.lock().unwrap().clone()), coverage: Mutex::new(self.coverage.lock().unwrap().clone()),
@ -139,6 +141,8 @@ impl ParsedFont {
} }
if p.synthesize_bold { if p.synthesize_bold {
code.push_str(" -- Will synthesize bold\n"); code.push_str(" -- Will synthesize bold\n");
} else if p.synthesize_dim {
code.push_str(" -- Will synthesize dim\n");
} }
if p.weight == FontWeight::Regular && p.stretch == FontStretch::Normal && !p.italic { if p.weight == FontWeight::Regular && p.stretch == FontStretch::Normal && !p.italic {
@ -176,6 +180,7 @@ impl ParsedFont {
italic, italic,
synthesize_italic: false, synthesize_italic: false,
synthesize_bold: false, synthesize_bold: false,
synthesize_dim: false,
handle, handle,
coverage: Mutex::new(RangeSet::new()), coverage: Mutex::new(RangeSet::new()),
cap_height, cap_height,
@ -384,6 +389,9 @@ impl ParsedFont {
self.synthesize_bold = attr.weight > FontWeight::Regular self.synthesize_bold = attr.weight > FontWeight::Regular
&& attr.weight > self.weight && attr.weight > self.weight
&& self.weight <= FontWeight::Regular; && self.weight <= FontWeight::Regular;
self.synthesize_dim = attr.weight < FontWeight::Regular
&& attr.weight < self.weight
&& self.weight >= FontWeight::Regular;
self self
} }
} }

View File

@ -99,6 +99,7 @@ impl<'a> std::hash::Hash for (dyn GlyphKeyTrait + 'a) {
/// The image data may be None for whitespace glyphs. /// The image data may be None for whitespace glyphs.
pub struct CachedGlyph<T: Texture2d> { pub struct CachedGlyph<T: Texture2d> {
pub has_color: bool, pub has_color: bool,
pub brightness_adjust: f32,
pub x_offset: PixelLength, pub x_offset: PixelLength,
pub y_offset: PixelLength, pub y_offset: PixelLength,
pub bearing_x: PixelLength, pub bearing_x: PixelLength,
@ -431,6 +432,7 @@ impl<T: Texture2d> GlyphCache<T> {
style style
); );
Rc::new(CachedGlyph { Rc::new(CachedGlyph {
brightness_adjust: 1.0,
has_color: false, has_color: false,
texture: None, texture: None,
x_offset: PixelLength::zero(), x_offset: PixelLength::zero(),
@ -455,6 +457,7 @@ impl<T: Texture2d> GlyphCache<T> {
) -> anyhow::Result<Rc<CachedGlyph<T>>> { ) -> anyhow::Result<Rc<CachedGlyph<T>>> {
let base_metrics; let base_metrics;
let idx_metrics; let idx_metrics;
let brightness_adjust;
let glyph; let glyph;
{ {
@ -463,6 +466,7 @@ impl<T: Texture2d> GlyphCache<T> {
glyph = font.rasterize_glyph(info.glyph_pos, info.font_idx)?; glyph = font.rasterize_glyph(info.glyph_pos, info.font_idx)?;
idx_metrics = font.metrics_for_idx(info.font_idx)?; idx_metrics = font.metrics_for_idx(info.font_idx)?;
brightness_adjust = font.brightness_adjust(info.font_idx);
} }
let aspect = (idx_metrics.cell_width / idx_metrics.cell_height).get(); let aspect = (idx_metrics.cell_width / idx_metrics.cell_height).get();
@ -558,6 +562,7 @@ impl<T: Texture2d> GlyphCache<T> {
let glyph = if glyph.width == 0 || glyph.height == 0 { let glyph = if glyph.width == 0 || glyph.height == 0 {
// a whitespace glyph // a whitespace glyph
CachedGlyph { CachedGlyph {
brightness_adjust: 1.0,
has_color: glyph.has_color, has_color: glyph.has_color,
texture: None, texture: None,
x_offset: info.x_offset * scale, x_offset: info.x_offset * scale,
@ -598,6 +603,7 @@ impl<T: Texture2d> GlyphCache<T> {
let tex = self.atlas.allocate(&raw_im)?; let tex = self.atlas.allocate(&raw_im)?;
let g = CachedGlyph { let g = CachedGlyph {
brightness_adjust,
has_color: glyph.has_color, has_color: glyph.has_color,
texture: Some(tex), texture: Some(tex),
x_offset, x_offset,

View File

@ -13,8 +13,7 @@ use ::window::glium::uniforms::{
use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface}; use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface};
use ::window::WindowOps; use ::window::WindowOps;
use anyhow::anyhow; use anyhow::anyhow;
use config::ConfigHandle; use config::{ConfigHandle, HsbTransform, TextStyle};
use config::TextStyle;
use mux::pane::Pane; use mux::pane::Pane;
use mux::renderable::{RenderableDimensions, StableCursorPosition}; use mux::renderable::{RenderableDimensions, StableCursorPosition};
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection}; use mux::tab::{PositionedPane, PositionedSplit, SplitDirection};
@ -1002,7 +1001,15 @@ impl super::TermWindow {
quad.set_texture_adjust(left, top, right, bottom); quad.set_texture_adjust(left, top, right, bottom);
quad.set_underline(underline_tex_rect); quad.set_underline(underline_tex_rect);
quad.set_underline_color(underline_color); quad.set_underline_color(underline_color);
quad.set_hsv(hsv); quad.set_hsv(if glyph.brightness_adjust != 1.0 {
let hsv = hsv.unwrap_or_else(|| HsbTransform::default());
Some(HsbTransform {
brightness: hsv.brightness * glyph.brightness_adjust,
..hsv
})
} else {
hsv
});
quad.set_has_color(glyph.has_color); quad.set_has_color(glyph.has_color);
quad.set_cursor( quad.set_cursor(
gl_state gl_state