musescore / musescore/MuseScore

Text option to balance line lengths in paragraphs

Open
#25,832 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
C++
Stars
15.1k
Forks
3.3k
Avg merge
2d 2h
Merged PRs (30d)
91

Description

Your idea

Add a new text formatting option with these values (e.g. in a dropdown, toggle buttons, or a radio list):

Balance line lengths Rendering
Off Default. As many words as possible are fit onto each line of text, while remaining within the current frame or page margins. The final line in each paragraph may be much shorter than the other lines.
Approximate Lines are automatically broken in the optimum places to ensure all lines within each paragraph are approximately equal in length, including the final line. Lines in one paragraph may be different in length to lines in another paragraph. The same total number of lines is used as with the Off setting.
Exact Same as Approximate except letter spacing and word spacing is automatically adjusted to make line lengths exactly equal. This is similar to full text justification, except lines don't have to occupy the full width between margins.

Here, line length refers to the visual width of a line, not the number of characters it contains.

Obviously, this option is useless without:

  • #23013
Problem to be solved

When text is justified or center-aligned, it looks unbalanced if the length of the final line is very different to the other lines.

This can be avoided by adding manual line breaks as was done in the opening pages of this score:

image

image

image

However, these manual line breaks are only valid for this particular combination of:

  • Font
  • Font size
  • Page size
  • Page margins

If any of these settings are subsequently changed (e.g. when loading a large print accessibility style), the lines may no longer fit between the margins. If that happens (and #23013 is fixed) then automatic breaks would be created in addition to these manual breaks, which could look terrible!

Prior art

LaTeX has a \parfillskip tag that provides similar functionality.

Microsoft Word has options to control whether the final line of a paragraph gets justified along with the other lines. However, it simply stretches the final line to fill the space. It's not clever enough to try moving the linebreaks around.

Additional context

For the MVP, lines would always be broken at word boundaries, but in the future we could allow hypenation (and potentially add another setting to control how aggressively hypenation is applied).

The Balance line lengths setting can be used in conjunction with the alignment setting (Left, Center, Right) to create lines that are approximately equal in length and aligned with one margin or the center of the page.

In future, if we add a Justify alignment option, the effect of length balancing would be to make all lines, including the final line, equal in length and occupy the full width of the page, but with a clever algorithm than Microsoft Word. In this case there would be no difference between Approximate and Exact balancing, but setting it to Off would remove justification of the final line.

Checklist
  • This request follows the guidelines for reporting issues
  • I have verified that this feature request has not been logged before, by searching the issue tracker for similar requests

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 by reviewing the requested Balance line lengths behavior and its dependency on #23013. The work is done when Off, Approximate, and Exact settings produce the described paragraph line balancing while respecting word-boundary breaks and alignment.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
design, desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.