mirror of
https://github.com/wez/wezterm.git
synced 2024-11-23 23:21:08 +03:00
wezterm: fix scaling of color emoji
If you have a primary font whose height is a bit more than double the width then a double-wide emoji would be scaled to a bit more than two cells in width. This commit adjust the glyph scaling to check both the x and y scaling to ensure that they glyph fits within the appropriate number of cells. This has the consequence of rendering eg: the heart emoji smaller than in previous versions; the heart glyph is typically square but the broadly used concept of width for the heart unicode character is a single cell. Previously we'd incorrectly render this double wide. I'm not sure of a way to do better than we are right now because freetype doesn't provide much help for scaling this kind of bitmap font AFAICS. refs: #320
This commit is contained in:
parent
25bbac4171
commit
bc1e12e0f5
@ -185,8 +185,19 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
let (cell_width, cell_height) = (metrics.cell_width, metrics.cell_height);
|
||||
|
||||
let scale = 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
|
||||
// This is another way to detect oversize glyph images.
|
||||
// Compute an aspect-preserving scale factor that makes the glyph
|
||||
// fit in the appropriate number of cells.
|
||||
// The GlyphInfo tells us how many horizontal cells the glyph occupies.
|
||||
let y_scale = cell_height.get() / glyph.height as f64;
|
||||
let x_scale = (cell_width.get() * info.num_cells as f64) / glyph.width as f64;
|
||||
|
||||
if PixelLength::new(y_scale * glyph.width as f64) > cell_width {
|
||||
// The y scale would overflow the width, so use the x-scale
|
||||
x_scale
|
||||
} else {
|
||||
y_scale
|
||||
}
|
||||
} else {
|
||||
1.0f64
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user