Skip to content

fix - Some glyph are not visually centered when patching monospaced variation#1998

Draft
OzelotVanilla wants to merge 1 commit intoryanoasis:masterfrom
OzelotVanilla:fix/glyph-not-centered-for-mono-option
Draft

fix - Some glyph are not visually centered when patching monospaced variation#1998
OzelotVanilla wants to merge 1 commit intoryanoasis:masterfrom
OzelotVanilla:fix/glyph-not-centered-for-mono-option

Conversation

@OzelotVanilla
Copy link
Copy Markdown

@OzelotVanilla OzelotVanilla commented Apr 5, 2026

Description

See issue #1997 for detail.

Some glyph in font Noto, has some double width glyph with the bounding box width around single width.

Some debug code is preserved, and would be deleted once the PR is ready to be merged.

If this PR could be merged, it will:
fixes #1997

Requirements / Checklist

What does this Pull Request (PR) do?

This PR fixes that by re-centering glyph that could be visually centered while creating monospaced variation.

A variable glyph_centering_threshold (currently set to 20) is used to decide whether a glyph will go into the "visually center" process or not. When the glyph's bounding box is less than single glyph width plus threshold, it will be considered able to be visually centered.

Notice: This threshold is currently empirical, and may need to be derived from font metrics, weight, or be exposed as a parameter and then defined in config.

How should this be manually tested?

Use fontforge to compare the previous font and newly patched font, the new one would have a correct bearing for glyph listed in #1997 (affected_chars at the bottom of issue, not bottom of discussion).

Any background context you can provide?

When I am using jj-vcs, I found the "◆" (U+25C6) for immutable commit in jj log, is not horizontally centered with the verticle bar in the line above/below.

I pasted the char into Google Fonts and saw the tofu, so I misunderstood and thinking about this is caused by copy_glyph when I read the source code.

However, when I see the file in the unpatched font (src/unpatched-fonts/Noto/Sans-Mono/NotoSansMono-Regular.ttf) by fontforge, I found they were having a width of 1200 (double width), and the RBearing becomes negative after font_patcher.set_glyph_width_mono.

I checked all the glyph in the unpatched font, and found some glyphs having a bounding box width less or around 600, but all having a negative RBearing (affected_chars).
So I tried to visually center those glyph that:

  • Having negative RBearing after glyph.width was set.
  • Having a bounding box width around 600 or less than 600.

Of course, there are also some glyph that should not be vertically centered into monospace width, such as:

should_keep_original_chars = [
    "▭",        # U+25AD, width:  600, LBearing:  100, RBearing: -500, bbox_width: 1000
    "▰",        # U+25B0, width:  600, LBearing:  103, RBearing: -497, bbox_width:  994
    "▱",        # U+25B1, width:  600, LBearing:  103, RBearing: -497, bbox_width:  994
    "▻",        # U+25BB, width:  600, LBearing:  284, RBearing: -316, bbox_width:  632
    "◅",        # U+25C5, width:  600, LBearing:  285, RBearing: -316, bbox_width:  631
    "◍",        # U+25CD, width:  600, LBearing:  149, RBearing: -452, bbox_width:  903
    "◯",        # U+25EF, width:  600, LBearing:  230, RBearing: -370, bbox_width:  740
]

In order to not introduce compability changes, those kind of glyph is kept their original metrics in this PR.

What are the relevant tickets (if any)?

Screenshots (if appropriate or helpful)

This image, taken from fontforge metrics window, shows the result of patched font, L/R Bearing fixed by this PR.

image

See also #1997 for more screenshots explaning why this bug exists and how it could be solved.

@OzelotVanilla OzelotVanilla marked this pull request as draft April 5, 2026 07:35
@OzelotVanilla
Copy link
Copy Markdown
Author

This PR is made as drafted until the discussion is done in #1997.

…ariation

See issue ryanoasis#1997 for detail.

Some glyph in font `Noto`, has some double width glyph with the bounding box width around single width.

This commit fixes that by re-centering glyph that could be visually centered while creating monospaced variation.

Some debug code is preserved, and would be deleted once the PR is ready to be merged.
@OzelotVanilla OzelotVanilla force-pushed the fix/glyph-not-centered-for-mono-option branch from 99f1beb to 2f9b563 Compare April 5, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--mono turns NotoSansMono U+25C6 into a broken single-width glyph with negative RBearing

1 participant