mapbox / mapbox/mapbox-gl-js

More line breaking penalties for parentheses?

Open
#5,556 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature :green_apple:
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.