wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
18.12k stars 809 forks source link

Double Width Double Height Pixelated #5233

Open rhaskia opened 8 months ago

rhaskia commented 8 months ago

What Operating System(s) are you seeing this problem on?

Windows

Which Wayland compositor or X11 Window manager(s) are you using?

No response

WezTerm version

wezterm 20240316-074238-889f8a9c

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Double height/width text renders at the wrong font size, seemingly scaled up from normal size to fit two lines. I'm assuming this might be because of how the app caches glyphs, but I wouldn't be sure.

To Reproduce

On WSL, put in the command echo -e "\x1b#3large". In powershell, the command echo "`e#3large" works similarly.

Configuration

-- Pull in the wezterm API
local wezterm = require 'wezterm'

-- This table will hold the configuration.
local config = {}

-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
  config = wezterm.config_builder()
end

-- For example, changing the color scheme:
config.color_scheme = 'Gruvbox dark, hard (base16)'
config.use_fancy_tab_bar = false

config.font = wezterm.font_with_fallback {
  'MonaspiceNe Nerd Font',
  'Symbols Only',
}

config.harfbuzz_features = { 'calt=1', 'clig=1', 'liga=1', 'dlig=1', "ss01=1",
"ss02=1","ss03=1","ss04=1","ss05=1","ss06=1","ss07=1","ss08=1", }

config.font_size = 10.3
--config.window_background_opacity = 0.8
config.default_prog = { "pwsh.exe" }

-- and finally, return the configuration to wezterm
return config

Expected Behavior

For the outputted line's glyphs to be scaled correctly at double width/height, ideally double the font size of the config.

Logs

No response

Anything else?

image

rhaskia commented 8 months ago

I am willing to fix this myself, but I cannot find where this rendering happens inside the codebase.

tuckertwo commented 8 months ago

It seems that the code that is responsible for making double-width/height text is in the TermWindow.render_screen_line() function, starting at line 50 of wezterm-gui/src/termwindow/render/screen_line.rs, to wit:

        let width_scale = if !params.line.is_single_width() {
            2.0
        } else {
            1.0
        };

        let height_scale = if params.line.is_double_height_top() {
            2.0
        } else {
            1.0
        };

        let cell_width = params.render_metrics.cell_size.width as f32 * width_scale;
        let cell_height = params.render_metrics.cell_size.height as f32 * height_scale;

Basically, for double-width and double-height text, it doubles just the character cell width or both the character cell width and height, respectively. While I haven't yet had time to dig into where characters get rendered (and so am basing this mostly on speculation), I suspect the root of the problem lies here. I'd guess that scaling the character size like this results in each character getting rendered at 1× size and then scaled up to 2× normal size, resulting in the pixelation.

I'll have to look further into the rendering code to figure out where in the chain relative to render_screen_lines() the characters get rendered and how easy it would be to change the rendering code to double the font size for double-height/width text rather than scale up normal-size text.