mirror of
https://github.com/wez/wezterm.git
synced 2024-11-28 01:06:37 +03:00
fonts: readjust the glyph scaling code
As mentioned in f204ad9a82
, this has
gone back and forth a few times.
This version avoids some artifacts by avoiding scaling in most cases.
The test scenario for this is to tab complete a directory name in
zsh; that causes a bold `/` glyph to be rendered which selects a
typeface with different metrics and would render a horizontal line
at either the top of bottom of the glyph.
Similarly, a `/` in italics (eg: comments in vim) would select a
third different font and have different artifact properties.
Now both of those artifacts are eliminated.
This commit is contained in:
parent
52dfce6c4e
commit
a465378dc4
@ -131,9 +131,15 @@ impl<T: Texture2d> GlyphCache<T> {
|
|||||||
let (cell_width, cell_height) = (metrics.cell_width, metrics.cell_height);
|
let (cell_width, cell_height) = (metrics.cell_width, metrics.cell_height);
|
||||||
let nominal_width = cell_width.get() * info.num_cells as f64;
|
let nominal_width = cell_width.get() * info.num_cells as f64;
|
||||||
|
|
||||||
let scale = if glyph.width as f64 > nominal_width {
|
let scale = if glyph.width as f64 > nominal_width * 1.5 {
|
||||||
|
// This is for the case where the glyph is a big bitmap that hasn't
|
||||||
|
// yet been scaled
|
||||||
nominal_width / glyph.width as f64
|
nominal_width / glyph.width as f64
|
||||||
} else if PixelLength::new(glyph.height as f64) > cell_height {
|
} else if (info.x_advance.get() / f64::from(info.num_cells)).floor() > cell_width.get() {
|
||||||
|
// This is to handle double-width replacements such as ligatures
|
||||||
|
nominal_width / info.x_advance.get() as f64
|
||||||
|
} else if PixelLength::new(glyph.height as f64) > cell_height * 1.5 {
|
||||||
|
// This is another way to detect overside glyph images
|
||||||
cell_height.get() / glyph.height as f64
|
cell_height.get() / glyph.height as f64
|
||||||
} else {
|
} else {
|
||||||
1.0f64
|
1.0f64
|
||||||
@ -163,6 +169,15 @@ impl<T: Texture2d> GlyphCache<T> {
|
|||||||
let y_offset = info.y_offset * scale;
|
let y_offset = info.y_offset * scale;
|
||||||
|
|
||||||
let (scale, raw_im) = if scale != 1.0 {
|
let (scale, raw_im) = if scale != 1.0 {
|
||||||
|
log::trace!(
|
||||||
|
"physically scaling {:?} by {} bcos {}x{} > {}x{}",
|
||||||
|
info,
|
||||||
|
scale,
|
||||||
|
glyph.width,
|
||||||
|
glyph.height,
|
||||||
|
cell_width,
|
||||||
|
cell_height
|
||||||
|
);
|
||||||
(1.0, raw_im.scale_by(scale))
|
(1.0, raw_im.scale_by(scale))
|
||||||
} else {
|
} else {
|
||||||
(scale, raw_im)
|
(scale, raw_im)
|
||||||
|
Loading…
Reference in New Issue
Block a user