mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 22:01:47 +03:00
fonts: synthesize dim when a light weight font is unavailable
This commit is contained in:
parent
cb4da18021
commit
717a2157f6
@ -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: 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)!
|
||||
* 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
|
||||
* 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)
|
||||
|
@ -123,6 +123,20 @@ impl LoadedFont {
|
||||
.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(
|
||||
&self,
|
||||
glyph_pos: u32,
|
||||
|
@ -23,6 +23,7 @@ pub struct ParsedFont {
|
||||
coverage: Mutex<RangeSet<u32>>,
|
||||
pub synthesize_italic: bool,
|
||||
pub synthesize_bold: bool,
|
||||
pub synthesize_dim: bool,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ParsedFont {
|
||||
@ -47,6 +48,7 @@ impl Clone for ParsedFont {
|
||||
italic: self.italic,
|
||||
synthesize_italic: self.synthesize_italic,
|
||||
synthesize_bold: self.synthesize_bold,
|
||||
synthesize_dim: self.synthesize_dim,
|
||||
handle: self.handle.clone(),
|
||||
cap_height: self.cap_height.clone(),
|
||||
coverage: Mutex::new(self.coverage.lock().unwrap().clone()),
|
||||
@ -139,6 +141,8 @@ impl ParsedFont {
|
||||
}
|
||||
if p.synthesize_bold {
|
||||
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 {
|
||||
@ -176,6 +180,7 @@ impl ParsedFont {
|
||||
italic,
|
||||
synthesize_italic: false,
|
||||
synthesize_bold: false,
|
||||
synthesize_dim: false,
|
||||
handle,
|
||||
coverage: Mutex::new(RangeSet::new()),
|
||||
cap_height,
|
||||
@ -384,6 +389,9 @@ impl ParsedFont {
|
||||
self.synthesize_bold = attr.weight > FontWeight::Regular
|
||||
&& attr.weight > self.weight
|
||||
&& self.weight <= FontWeight::Regular;
|
||||
self.synthesize_dim = attr.weight < FontWeight::Regular
|
||||
&& attr.weight < self.weight
|
||||
&& self.weight >= FontWeight::Regular;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +99,7 @@ impl<'a> std::hash::Hash for (dyn GlyphKeyTrait + 'a) {
|
||||
/// The image data may be None for whitespace glyphs.
|
||||
pub struct CachedGlyph<T: Texture2d> {
|
||||
pub has_color: bool,
|
||||
pub brightness_adjust: f32,
|
||||
pub x_offset: PixelLength,
|
||||
pub y_offset: PixelLength,
|
||||
pub bearing_x: PixelLength,
|
||||
@ -431,6 +432,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
style
|
||||
);
|
||||
Rc::new(CachedGlyph {
|
||||
brightness_adjust: 1.0,
|
||||
has_color: false,
|
||||
texture: None,
|
||||
x_offset: PixelLength::zero(),
|
||||
@ -455,6 +457,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
) -> anyhow::Result<Rc<CachedGlyph<T>>> {
|
||||
let base_metrics;
|
||||
let idx_metrics;
|
||||
let brightness_adjust;
|
||||
let glyph;
|
||||
|
||||
{
|
||||
@ -463,6 +466,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
glyph = font.rasterize_glyph(info.glyph_pos, 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();
|
||||
@ -558,6 +562,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
let glyph = if glyph.width == 0 || glyph.height == 0 {
|
||||
// a whitespace glyph
|
||||
CachedGlyph {
|
||||
brightness_adjust: 1.0,
|
||||
has_color: glyph.has_color,
|
||||
texture: None,
|
||||
x_offset: info.x_offset * scale,
|
||||
@ -598,6 +603,7 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
let tex = self.atlas.allocate(&raw_im)?;
|
||||
|
||||
let g = CachedGlyph {
|
||||
brightness_adjust,
|
||||
has_color: glyph.has_color,
|
||||
texture: Some(tex),
|
||||
x_offset,
|
||||
|
@ -13,8 +13,7 @@ use ::window::glium::uniforms::{
|
||||
use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface};
|
||||
use ::window::WindowOps;
|
||||
use anyhow::anyhow;
|
||||
use config::ConfigHandle;
|
||||
use config::TextStyle;
|
||||
use config::{ConfigHandle, HsbTransform, TextStyle};
|
||||
use mux::pane::Pane;
|
||||
use mux::renderable::{RenderableDimensions, StableCursorPosition};
|
||||
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection};
|
||||
@ -1002,7 +1001,15 @@ impl super::TermWindow {
|
||||
quad.set_texture_adjust(left, top, right, bottom);
|
||||
quad.set_underline(underline_tex_rect);
|
||||
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_cursor(
|
||||
gl_state
|
||||
|
Loading…
Reference in New Issue
Block a user