Skip to content

Wide characters get truncated #223

@Dreomite

Description

@Dreomite

The issue

ST divides rendered text to sequences of glyphs with same style and then sequentially draws them. This leads to a problem: if a wide glyph is followed by another glyph with different style (can be color, weight or anything), the excessive parts of the glyph will be overdrawn by the beginning of the next sequence.

Steps to reproduce

  1. If you have a double-width Nerd font installed, execute this in your terminal: echo '\uF03E\e[36mX \uF03EX '

You'll get the following picture:
image
Note how the first icon gets truncated due to style difference while the second one doesn't.

The reason

If you'll take a look at xdrawglyphfontspecs function, which is used for drawing sequences of glyphs with same style, you'll see that it calls 2 functions before drawing actual glyphs:

  • XftDrawRect - this one draws background of the current sequence basically overdrawing parts of previous sequence if they happen to cross current sequence boundary.
  • XftDrawSetClipRectangles - this one puts drawable glyphs in an invisible rectangle outside of which glyphs are not rendered. (Later followed by XftDrawSetClip to negate this.)

Proposed solution

  1. Use 2 passes for drawing lines: one for background, another one for foreground. So parts of wide glyphs do not get overdrawn.
  2. Git rid of rectangle clipping. It was introduced in this commit and is intended for removing overdrawing for some fonts. Was it worth introducing in the first place? I don't know. Such fonts are still going to look crippled and are not worth using in the first place.

I made a very dirty proof-of-concept fix here: Dreomite@e4355b5

With no fix:
image

With this fix:
image

Is this an acceptable solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions