Skip to content

Fix computing winding in embolden - #135

Open
rhysd wants to merge 1 commit into
dfrg:mainfrom
rhysd:fix-empolden-winding
Open

Fix computing winding in embolden#135
rhysd wants to merge 1 commit into
dfrg:mainfrom
rhysd:fix-empolden-winding

Conversation

@rhysd

@rhysd rhysd commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fix #134

LayerMut::embolden computed the winding from all points in a layer as one polygon. With disconnected contours, this adds nonexistent edges between contours to the area calculation and can reverse the winding. As a result, synthetic bold could shrink some glyphs, such as Monaco's i reported in #134.

This change computes the area for each contour separately and sums the results before determining the winding. Then the resulting global winding is used for all contours preserving the correct behavior for inner counter contours.

I verified this change with Monaco text on my app as follows. The existing tests and doc tests pass.

  • Non-bold text
Image
  • Bold text before this fix
Image
  • Bold text after this fix
image

@sixdonkeys

Copy link
Copy Markdown

Ran into this independently (Monaco i looking thin under embolden) and ended up writing the same fix before finding this PR.

What we measured, as confirmation: the i is two separate loops — the stem and the dot. To know which way is "outward," the code adds up area as if all the points were one shape, so the imaginary edges between the loops get counted too. For Monaco's i the real loops measure -280 and -47, but those fake edges drag the total to +21 — opposite sign. So embolden squeezes the letter instead of thickening it: at 44px, embolden(0.27) takes the stem from 4.0px down to 3.45px.

Fourteen glyphs in Monaco and sixteen in JetBrains Mono fail the same way — every one is a letter with a detached piece, like dots and accents. Letters with holes are still fine when you sum the loops one at a time: o measures -970 outside and +446 for the hole, and the answer doesn't change.

We're carrying this patch vendored until it lands. Thanks for the fix.

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.

embolden fails at 'i' glyph of Monaco font

2 participants