[vim/vim] respect lpDx advance widths in DirectX rendering (PR #19254)

0 views
Skip to first unread message

mattn

unread,
Jan 25, 2026, 11:42:35 AM (15 hours ago) Jan 25
to vim/vim, Subscribed

Problem

When using DirectX rendering (set renderoptions=type:directx), character positions can become misaligned with what Vim expects.

image.png (view on web)

Cause

The Win32 GUI computes advance widths for each character as the lpDx array and passes it to DWriteContext::DrawText(). These values represent the "correct" character positions as determined by Vim, based on wcwidth() and gui.char_width.

However, lpDx was not passed through TextRendererContext to AdjustedGlyphRun. As a result, the DirectX side ignored lpDx and computed advance widths independently using adjustToCell() based on font metrics.

In short: "lpDx was passed but never used."

This caused a mismatch: Vim manages cursor positions and redraw regions based on lpDx, but DirectX rendered characters based on font metrics. For fonts where glyph widths differ from Vim's cell width (e.g., UbuntuMono), characters would progressively drift out of alignment.

Solution

Pass lpDx through TextRendererContext to AdjustedGlyphRun, and use the advance widths provided by Vim instead of computing them from font metrics.

image.png (view on web)

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19254

Commit Summary

  • 0db7958 respect lpDx advance widths in DirectX rendering

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254@github.com>

mattn

unread,
Jan 25, 2026, 7:38:00 PM (7 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 1 commit.

  • 76d680c remove negative lfHeight handling


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/0db7958bf659db85d396b5d487b5c6566e35f39b/after/76d680c539d0a525d3e5810173547971ce7a495d@github.com>

mattn

unread,
Jan 25, 2026, 7:38:31 PM (7 hours ago) Jan 25
to vim/vim, Subscribed
mattn left a comment (vim/vim#19254)

I found one another issue about DirectX. When using DirectX rendering (renderoptions=directx), multi-byte characters appeared larger than expected, and scrolling left artifacts (ghosting) at the top or bottom edges of characters.

The original code had two different paths for handling lfHeight:

  • Negative lfHeight: Simply used the absolute value as font size (representing em units)
  • Positive lfHeight: Converted cell height to em units using font metrics

https://github.com/vim/vim/blob/17bba758fa626ab5b07faefbada0938a4ceeca4d/src/gui_dwrite.cpp#L779-L801

When negative lfHeight was used, the code skipped the proper cell height conversion, resulting in an oversized font. Characters rendered larger than the cell height, causing parts of glyphs to extend beyond their allocated space. During scrolling, these overflow regions weren't properly cleared, leaving visible artifacts.

So removed the conditional logic and always calculate font size based on font metrics (ascent + descent). This ensures consistent, accurate sizing regardless of lfHeight sign, keeping characters within their designated cell boundaries.

Characters now render at the correct size, fitting properly within cell height, eliminating scrolling artifacts for multi-byte characters.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/c3797481391@github.com>

mattn

unread,
Jan 25, 2026, 8:00:56 PM (7 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 0 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/76d680c539d0a525d3e5810173547971ce7a495d/after/0db7958bf659db85d396b5d487b5c6566e35f39b@github.com>

mattn

unread,
Jan 25, 2026, 9:51:33 PM (5 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 1 commit.

  • 07b548e Fix DirectX font size calculation with proper DPI conversion

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/0db7958bf659db85d396b5d487b5c6566e35f39b/after/07b548e1a3942aa5e5ca8effbde1b30fdd3d7d9d@github.com>

mattn

unread,
Jan 25, 2026, 10:03:55 PM (5 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 1 commit.

  • 8c1b4bd Fix DirectX font size to match GDI rendering using ascent ratio

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/07b548e1a3942aa5e5ca8effbde1b30fdd3d7d9d/after/8c1b4bdf48c812c5d9dd53329259fd231ab0acef@github.com>

mattn

unread,
Jan 25, 2026, 10:07:49 PM (5 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 1 commit.

  • 71749b3 Fix DirectX font size to match GDI rendering using ascent ratio with ceiling

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/8c1b4bdf48c812c5d9dd53329259fd231ab0acef/after/71749b32ed991d13dac0d8dcc63f79d2dd72e812@github.com>

mattn

unread,
Jan 25, 2026, 10:32:56 PM (4 hours ago) Jan 25
to vim/vim, Push

@mattn pushed 1 commit.

  • 9ffa5bb Fix DirectX font size to match GDI rendering using ascent ratio

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19254/before/71749b32ed991d13dac0d8dcc63f79d2dd72e812/after/9ffa5bb6f3c9a8130cb7e1f8d182f358c9958e17@github.com>

Reply all
Reply to author
Forward
0 new messages