More line breaking penalties for parentheses?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
In shaping, we have line breaking penalties in place to avoid an opening parenthesis at the end of a line, and a closing parenthesis at the beginning of a line. These prevent the worst formatting possible for labels with parentheses, but perhaps we could add a few more penalties to further improve the display of these labels? E.g.:
// Encourage open parenthesis at beginning of line
if (nextCodePoint === 0x28 || nextCodePoint === 0xff08) {
penalty -= 50;
}
// Penalize character immediately after open parenthesis at end of line
if (previousCodePoint === 0x28 || previousCodePoint === 0xff08) {
penalty += 5;
}
// Penalize character immediately before close parenthesis at beginning of line
if (nextCodePoint === 0x29 || nextCodePoint === 0xff09) {
penalty += 5;
}
@ChrisLoer thoughts? I'm happy to create a test branch and try out options myself, if you think that would be the most efficient workflow.
/cc @ajashton
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/symbol/shaping.js around the existing line-breaking penalties at lines 169-177. Review how the current opening- and closing-parenthesis cases affect label layout, then try the proposed penalty options in a test branch. Done means agreeing on additional penalties that improve parenthesized labels without harming other line breaks, with validation for the resulting behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100