microsoft / microsoft/WindowsAppSDK

DWriteCore inconsistent/wrong/non-fractional line spacing

Open
#5,022 1 comment 1 reaction 0 assignees View on GitHub
area-DWriteCore
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

The line spacing between new lines in a DWriteCore text layout are not consistent or fractional. On smaller font sizes this becomes a noticable issue. Since it is a bit harder to show due to the small sizes in the TextRendering sample, I use my own application. This is at a point size of 72, and then scaled down to fit on the screen. The lines here seem mostly even.

![Image](https://github.com/user-attachments/assets/e0d4602e-e9a1-4383-9613-c903e0c452b0)

However, if I use a point size of 3, you can start seeing the difference in line spacing:

![Image](https://github.com/user-attachments/assets/646f5b0a-d500-443f-8676-5c45494bc102)

and even more extreme, point size 0.5:

![Image](https://github.com/user-attachments/assets/fa13c29f-2417-4dc8-b3c2-fc7075a3c132)

some new lines do not even give a different value compared to the previous line's `baselineOriginY` in `IDWriteTextRenderer1::DrawGlyphRun`.

This is most likely due to the fact that the difference in `baselineOriginY` do not properly scale with font size, as can be seen in the attached videos.

### Steps to reproduce the bug

1. create a text layout with multi-line text, I just used some from the main page of https://www.lipsum.com/.
2. make the text layout have a maximum width, so it wraps the words, without needing explicit new-lines.
3. set the font size at quite small, so the non-fractional `baselineOriginY` becomes an issue.
4. set the font size even smaller to where multiple lines sometimes have the same `baselineOriginY`.

### Expected behavior

The difference in `baselineOriginY` is more consitently scaled with the font size used. And never has the same value as the previous any of the previous lines.

### Screenshots

Non-fractional `baselineOriginY` (I printed them all and they were always integers)

https://github.com/user-attachments/assets/c8b09461-05ac-4982-abbd-4b7b387b0837

And some lines do not even get a different `baselineOriginY`:

https://github.com/user-attachments/assets/98c89300-be70-4509-9655-97753f171853

### NuGet package version

None

### Packaging type

Unpackaged

### Windows version

Windows 11 version 22H2 (22621, 2022 Update)

### IDE

Visual Studio 2022

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the TextRendering sample and the IDWriteTextRenderer1::DrawGlyphRun callback, where baselineOriginY is observed. Reproduce the issue with wrapped multiline text at very small font sizes and inspect whether line spacing remains fractional and distinct between lines. Done means baselineOriginY differences scale consistently with font size and do not repeat for adjacent lines.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.