feat: use pixel-width-based word wrapping#4863
feat: use pixel-width-based word wrapping#4863hyperfinitism wants to merge 2 commits intoanuraghazra:masterfrom
Conversation
|
@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>
075a625 to
6525f65
Compare
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
ba7d184 to
1a4ed98
Compare
|
Hi @hyperfinitism, thanks a lot for this well-written PR! Work on this project has moved to stats-organization/github-stats-extended. I have adapted your changes and created stats-organization#189 over there. As you described in #4862, even with your improvement in place there are still reflow problems. I think we should start using Would you be willing to work on the introduction of |
|
Yes. I have implemented the |
|
I created a pull request to the -extended repository based on |
Summary
Uses pixel-width-based word wrapping using the existing
measureText()function instead of character count (59 chars).File changes
src/common/fmt.js:wrapTextMultiline()gains an optionalfontSizeparameter. When provided,widthis treated as a pixel budget and words are measured usingmeasureText()against the raw text (not HTML-encoded), so entities like—(em dash) are measured as single glyphs, not 7 characters.src/cards/repo.js:DESCRIPTION_LINE_WIDTHchanged from59[chars] to360[px] (== card 400 - x offset 25 - right margin 15). PassesDESCRIPTION_FONT_SIZE = 13to enable pixel wrapping.src/cards/gist.js: Same change: pixel-width wrapping at 360px / 13px font.src/common/render.js: fixmeasureTextwidth array using the actual widths of Segoe UI characters.tests/renderRepoCard.test.jsandtests/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
Before fix
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
measureTextaccording to the font or useforeignObject.