Skip to content

Text: keep the top of a stroked label's outline under the "hanging" baseline on macOS - #1898

Merged
obiot merged 1 commit into
melonjs:masterfrom
Goldloli:fix/text-hanging-outline
Nov 19, 2026
Merged

obiot merged 1 commit into
melonjs:masterfrom
Goldloli:fix/text-hanging-outline

Conversation

@Goldloli

Copy link
Copy Markdown
Contributor

Description

A stroked, multi-line Text label with textBaseline: "hanging" can lose the top of its outline on macOS, where sans-serif resolves to Helvetica: the ink padding around the baked canvas comes out exactly as tall as the ink, so the outline is sheared at row 0 of the canvas texture (#1870).

The padding in TextMetrics#measureText is ceil(ascent + strokeReach) + INK_SLACK. The rasterizer paints the ink about a pixel past what actualBoundingBoxAscent reports, which INK_SLACK = 1 was meant to absorb — but when ascent + stroke lands close enough to a whole number, ceil() adds no headroom on top of that, and the slack is then exactly the spill. Measured in Chromium on macOS with Helvetica at 20px, "XX" under "hanging" reports an ascent of -0.05px, so ceil(-0.05 + 3) + 1 = 4 and the painted ink reaches exactly 4px above the alignment point — ink on the first row. Every other baseline passes because its fractional ascent leaves headroom in the ceil().

This raises INK_SLACK to 2, so the worst whole-number alignment is absorbed too, and documents the measurement in the comment. The failing engine test now passes on macOS, where it failed before.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

  • I have read the Contributing Guide
  • My code follows the existing code style (pnpm lint passes)
  • I have tested my changes locally (pnpm test passes)
  • I have added tests that cover my changes (if applicable) — covered by the existing engine test the issue names
  • The build succeeds (pnpm build)

Related issues

Fixes #1870

@obiot
obiot merged commit ec92e25 into melonjs:master Nov 19, 2026
3 checks passed
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.

Text: an outlined multi-line label with textBaseline "hanging" can lose the top of its outline on macOS

2 participants