microsoft / microsoft/WindowsAppSDK

DWriteCore returns shifted glyph indices in a glyph run

Open
#5,024 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-DWriteCore
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

I have noticed that some fonts (not all) just give wrong glyph indices when passed to `DrawGlyphRun` in the `DWRITE_GLYPH_RUN`. For example when i use FreeType to check the index for space in the [AppleStorm](https://www.dafont.com/applestorm.font) font I get the glyph index `1`. When i check on [FontDrop](https://fontdrop.info) I also get the index as `1` as shown in the screenshot.

![Image](https://github.com/user-attachments/assets/aaa819ad-7e26-4eeb-b56d-b75a520b82f6)

Even when I ask DWriteCore itself to give me the glyph indices using `GetGlyphIndices`, it tells me space is glyph index `1`. But when layed out it gives me `3`. This results in situations like this, where with Open Sans it gives the correct result:

![Image](https://github.com/user-attachments/assets/1427b4da-179c-45af-b61e-129974ba12db)

but when I switch to the offending font, it shifts it `2` indices to the right:

![Image](https://github.com/user-attachments/assets/e5501d5b-e855-469e-9901-6c4eafc86c6d)

### Steps to reproduce the bug

1. Since i cannot attach font files, 1 font that definitely does not work is the [AppleStorm](https://www.dafont.com/applestorm.font) font.
2. Use that file to the retrieve some glyph indices using `GetGlyphIndices`, like space with codepoint `32`.
3. See that it returns glyph index `1` for space.
4. Then layout text and see that the glyph index it has given (in this font) is `3`.

### Expected behavior

DWriteCore returns the correct glyph indices for the given codepoints. The same it also returns in `GetGlyphIndices`.

### Screenshots

_No response_

### 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the mismatch with the AppleStorm font, comparing GetGlyphIndices with the glyph indices produced during layout and passed to DrawGlyphRun in DWRITE_GLYPH_RUN. Trace the DWriteCore text-layout and glyph-index handling from those entry points; done means the layout returns the same indices as GetGlyphIndices for the affected font without shifting glyphs.

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.