1

When I move to different places on a line in Visual Studio, I notice that the thickness of the cursor changes. I am not referring to going into Insert mode, or changing any settings of either the operating system or VS itself.

The same variable thickness of the cursor happens if the cursor is between two whitespace characters, between whitespace and non-whitespace characters, or between multiple non-whitespace characters (such as in the middle of a variable name).

With limited investigation, it seems as though the same location in a file has the same thickness, even if the file is closed and reopened or Visual Studio is restarted.

I am currently running 2022, Version 17.6.2, but I believe this behaviour is not unique to this version.

Below are two screenshots taken from the same line of code.

thin, sharp cursor thick, fuzzy cursor

This behaviour only seems to occur in the text editor. Places like the Output window, the search pane, the Immediate window, and the Command window all display a normal sharp cursor.

If I zoom in to 380% in the editor, the cursor still appears to my eye to be slightly inconsistent, but the degree of that inconsistency is lesser.

sharp zoomed in cursor slightly fuzzy zoomed in cursor

Jim Cullen
  • 113
  • 4
  • what kind of language file are you looking at? have you customized Tools > Options > Environment > Fonts and Colors? have you downloaded and imported any styles? – Frank Thomas May 31 '23 at 05:12
  • The screenshot above was a .cs file, but I have also replicated this with .js, .html, and .txt, among others. I have not made any changes to settings related to fonts to my knowledge, nor imported any styles. Tools > Theme is "Dark", but even changing to "Blue" or "Light", the same behaviour persists. – Jim Cullen May 31 '23 at 05:21
  • @DanielB operating system display Scale is 100%. So is the VS text editor. – Jim Cullen May 31 '23 at 05:24
  • Well all I can see is that the entire editor rendering does not match up with pixels. This is most evident with the blue dots representing spaces: Every one of them is slightly different. The cursor does just the same. – Daniel B May 31 '23 at 05:35
  • @DanielB "This is most evident with the blue dots representing spaces: Every one of them is slightly different" they are? To be honest they look pretty consistent to me. If I do zoom way in the blue dots remain (to my eye) consistent, and the cursor becomes *less* inconsistent, but still slightly off. Will edit in relevant screenshots. – Jim Cullen May 31 '23 at 05:42

1 Answers1

1

It appears that at some point, the text renderer in the Visual Studio editor view was changed. You can now toggle the rendering mode under OptionsText EditorAdvancedText formatting method:

visual studio options

By selecting “Display” (as visible in the screenshot) you can get pixel-adjusted rendering. The cursor will then be the same in every column (and the blue dots and characters and whatnot, too).

(These options correspond to the TextFormattingMode enum.)

Quoting from this old blog post about the difference:

Ideal – Ideal text metrics are the metrics which have been used to format text since the introduction of WPF. These metrics result in glyphs’ shapes maintaining high fidelity with their outlines from the font file. The glyphs’ final placement is not taken into account when creating glyph bitmaps or positioning the glyphs relative to each other.

Display – In this new formatting mode, WPF uses GDI compatible text metrics. This ensures that every glyph has a width of multiple whole pixels and is positioned on whole pixels. The use of GDI compatible text metrics also means that glyph sizes and line breaking is similar to GDI based frameworks. That said, glyph sizes are not the only input into the line breaking algorithm used by WPF. Even though we use the same metrics as GDI, our line breaking will not be exactly the same.

The most important part being: This ensures that every glyph has a width of multiple whole pixels and is positioned on whole pixels.


My personal opinion: Ideal rendering looks great at high PPI (think “Retina” displays). It sucks at 96 PPI.

Daniel B
  • 60,360
  • 9
  • 122
  • 163