p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

feat(typography): add PRETTY/BALANCE textWrap modes with DP-based balanced wrapping

Open Vansh0204 opened this issue 1 month ago • 16 comments

PR2

  • Adds textWrap(PRETTY) and textWrap(BALANCE) to improve line-breaking aesthetics.
  • Uses dynamic programming to minimize raggedness; last line has zero penalty.
  • Integrates with existing text flow in 2D; works with all alignments, including JUSTIFIED .
  • Lint/build pass locally.

Addresses and resloved #7712

Vansh0204 avatar Nov 26 '25 06:11 Vansh0204

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors! 🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure! 🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

welcome[bot] avatar Nov 26 '25 06:11 welcome[bot]

Hello @osteele @andrewn @zeke @reidab sir can u please review my PR.

Vansh0204 avatar Nov 27 '25 18:11 Vansh0204

@Vansh0204 have you created tests for this feature?

dhowe avatar Nov 27 '25 18:11 dhowe

Thanks for reviewing, sir! I haven't added tests yet – I'll add comprehensive unit tests for the PRETTY/BALANCE textWrap modes covering the main functionality and edge cases. I'll push them shortly.

Vansh0204 avatar Nov 28 '25 06:11 Vansh0204

a good place to start would be the alignment tests in https://github.com/processing/p5.js/blob/dev-2.0/test/manual-test-examples/type/index.html

image

eventually we will also need pixel-based tests like those here: https://github.com/processing/p5.js/blob/dev-2.0/test/unit/visual/cases/typography.js

dhowe avatar Nov 28 '25 18:11 dhowe

Hi @dhowe, sir! I've updated the PRs to include the necessary tests. Screenshot 2025-12-01 at 12 05 08 AM

Vansh0204 avatar Nov 30 '25 19:11 Vansh0204

Sorry, did you make this PR against the dev-2.0 branch ?

dhowe avatar Nov 30 '25 20:11 dhowe

Yes sir, the PR is currently targeting dev-2.0. Should I change the base branch to main instead, or would you prefer I rebase my changes on top of dev-2.0? Let me know which branch you'd like me to target, and I'll update accordingly.

Vansh0204 avatar Dec 01 '25 08:12 Vansh0204

Yes sir, the PR is currently targeting dev-2.0. Should I change the base branch to main instead, or would you prefer I rebase my changes on top of dev-2.0? Let me know which branch you'd like me to target, and I'll update accordingly.

I'm seeing main as the target for this pr: image

dhowe avatar Dec 01 '25 13:12 dhowe

Yes @dhowe sir, that's correct! The PR is targeting main. I can see it shows "base: main" at the top of the PR. Let me know if there's anything else you'd like me to address!

Vansh0204 avatar Dec 01 '25 14:12 Vansh0204

both of these PR's need to target dev-2.0 as we're not adding features to v1.x (which his still main) at this point

dhowe avatar Dec 01 '25 14:12 dhowe

@dhowe sir, I have to work on it.

Vansh0204 avatar Dec 01 '25 15:12 Vansh0204

Hi @osteele and @dhowe, sir, I have raised new PRs can you please review them. Should I close these two PRs?

Vansh0204 avatar Dec 01 '25 18:12 Vansh0204

Hi @osteele and @dhowe, sir, I have raised new PRs can you please review them. Should I close these two PRs?

yes please

and thanks for your work!

dhowe avatar Dec 01 '25 18:12 dhowe

Thank you, @dhowe sir for your guidance.

Vansh0204 avatar Dec 01 '25 19:12 Vansh0204

@dhowe Sir, one last request, can you please review my new PRs?

Vansh0204 avatar Dec 01 '25 19:12 Vansh0204