Skip to content

feat: use pixel-width-based word wrapping#4863

Open
hyperfinitism wants to merge 2 commits intoanuraghazra:masterfrom
hyperfinitism:fix/line-break
Open

feat: use pixel-width-based word wrapping#4863
hyperfinitism wants to merge 2 commits intoanuraghazra:masterfrom
hyperfinitism:fix/line-break

Conversation

@hyperfinitism
Copy link
Copy Markdown

@hyperfinitism hyperfinitism commented Apr 7, 2026

Summary

Uses pixel-width-based word wrapping using the existing measureText() function instead of character count (59 chars).

File changes

  1. src/common/fmt.js: wrapTextMultiline() gains an optional fontSize parameter. When provided, width is treated as a pixel budget and words are measured using measureText() against the raw text (not HTML-encoded), so entities like — (em dash) are measured as single glyphs, not 7 characters.
  2. src/cards/repo.js: DESCRIPTION_LINE_WIDTH changed from 59 [chars] to 360 [px] (== card 400 - x offset 25 - right margin 15). Passes DESCRIPTION_FONT_SIZE = 13 to enable pixel wrapping.
  3. src/cards/gist.js: Same change: pixel-width wrapping at 360px / 13px font.
  4. src/common/render.js: fix measureText width array using the actual widths of Segoe UI characters.
  5. tests/renderRepoCard.test.js and tests/renderGistCard.test.js — Updated the expected number of pixels and the expected line break position within the assertion to reflect the changes.

Examples

Sample repository description

iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii iiii OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOOO OOO

Before fix

hyperfinitism-sample-repo-before-fix

After fix

hyperfinitism-sample-repo-after-fix

Testing

All (but one) tests have been passed. One test fails because of the preexisting issue reported in #4732.

Related issue

#4862 — To resolve this issue completely, we need to adjust measureText according to the font or use foreignObject.

@hyperfinitism hyperfinitism requested a review from qwerty541 as a code owner April 7, 2026 14:34
@github-actions github-actions Bot added repo-card Issues related to the pin/repo card. dependencies Pull requests that update a dependency file gist-card labels Apr 7, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 7, 2026

@hyperfinitism is attempting to deploy a commit to the github readme stats Team on Vercel.

A member of the Team first needs to authorize it.

The repo/gist card description used character-count wrapping (59 chars),
which fit Segoe UI (Windows) but overflowed on macOS Chrome where
Helvetica Neue — with wider glyphs — is the CSS font fallback.

Switch wrapTextMultiline() to measure actual pixel widths via
measureText() when a fontSize is provided, and set a 360px budget
(card width minus padding) instead of a fixed character count.
Also measure raw text before HTML-encoding so entities like —
(em dash) count as single glyphs, not 7 characters.

Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
@hyperfinitism hyperfinitism force-pushed the fix/line-break branch 2 times, most recently from 075a625 to 6525f65 Compare April 7, 2026 14:41
@github-actions github-actions Bot removed the dependencies Pull requests that update a dependency file label Apr 7, 2026
@hyperfinitism hyperfinitism changed the title fix: use pixel-width word wrapping to prevent description overflow on macOS feat: use pixel-width-based word wrapping Apr 10, 2026
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
@github-actions github-actions Bot added the stats-card Feature, Enhancement, Fixes related to stats the stats card. label Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gist-card repo-card Issues related to the pin/repo card. stats-card Feature, Enhancement, Fixes related to stats the stats card.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant