Bug 167648 - Add letter spacing for paragraph justification
Summary: Add letter spacing for paragraph justification
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: László Németh
URL:
Whiteboard: target:26.2.0
Keywords:
Depends on:
Blocks: 38159 Paragraph-Alignment
  Show dependency treegraph
 
Reported: 2025-07-23 11:51 UTC by László Németh
Modified: 2025-08-06 09:03 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
test document: paragraphs with 0%, 5%, 25% and 100% custom letter spacing (39.36 KB, application/vnd.oasis.opendocument.text-flat-xml)
2025-07-31 12:12 UTC, László Németh
Details
PDF export of the test document in the development version of LibreOffice (20.05 KB, application/pdf)
2025-07-31 12:14 UTC, László Németh
Details
letter_spacing_demo.odt: demo with different letter spacing settings (70.49 KB, application/vnd.oasis.opendocument.text)
2025-07-31 19:56 UTC, László Németh
Details
PDF export of the previous document (Note: the demo document needs Linux Libertine G font) (44.21 KB, application/pdf)
2025-07-31 19:57 UTC, László Németh
Details
letter_spacing_demo.odt: demo with different letter spacing settings (70.30 KB, application/vnd.oasis.opendocument.text)
2025-08-01 06:23 UTC, László Németh
Details
PDF export of the previous document (Note: the demo document needs Linux Libertine G font) (44.61 KB, application/pdf)
2025-08-01 06:27 UTC, László Németh
Details
test document: paragraphs with 0%, 5%, 25% and 100% custom letter spacing (39.69 KB, application/vnd.oasis.opendocument.text-flat-xml)
2025-08-01 22:03 UTC, László Németh
Details
letter_spacing.gif: animation about changing maximum letter spacing (214.57 KB, image/gif)
2025-08-06 08:46 UTC, László Németh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description László Németh 2025-07-23 11:51:52 UTC
Description:
Letter spacing of justified lines minimizes too big word spacing, rivers etc., allowing to typeset narrow columns, like DTP software do.

Steps to Reproduce:
Create a narrow column with justified text.

Actual Results:
Too big word spacing, often rivers (overlapping word spacing of consecutive lines).

Expected Results:
Closer to the desired word spacing, no rivers.


Reproducible: Always


User Profile Reset: No

Additional Info:
This is not Character setting→Position→Spacing-→Character spacing, but an useful optimization of justified lines. Minor, invisible changes in letter spacing, e.g. -3%/+3% can result in a much better typography: desired word spacing, less or no rivers.
Comment 1 László Németh 2025-07-31 12:12:39 UTC
Created attachment 202096 [details]
test document: paragraphs with 0%, 5%, 25% and 100% custom letter spacing

Narrow columns without hyphenation to show different custom spacing settings vs extreme word spacing.
Comment 2 László Németh 2025-07-31 12:14:21 UTC
Created attachment 202097 [details]
PDF export of the test document in the development version of LibreOffice
Comment 3 László Németh 2025-07-31 19:56:28 UTC
Created attachment 202105 [details]
letter_spacing_demo.odt: demo with different letter spacing settings
Comment 4 László Németh 2025-07-31 19:57:33 UTC
Created attachment 202106 [details]
PDF export of the previous document (Note: the demo document needs Linux Libertine G font)
Comment 5 László Németh 2025-08-01 06:23:55 UTC
Created attachment 202118 [details]
letter_spacing_demo.odt: demo with different letter spacing settings

(corrected version)
Comment 6 László Németh 2025-08-01 06:27:43 UTC
Created attachment 202119 [details]
PDF export of the previous document (Note: the demo document needs Linux Libertine G font)
Comment 7 László Németh 2025-08-01 09:00:29 UTC
See also inter-character/distribute of CSS (mostly for Asian languages, and without custom control, only enlarging letter spacing on the available extra word spacing): 

https://www.w3.org/TR/css-text-3/#text-justify
Comment 8 László Németh 2025-08-01 09:04:48 UTC
See also “Letter Spacing” in Text composition page of Adobe InDesign’s Help:

https://helpx.adobe.com/indesign/using/text-composition.html
Comment 9 Commit Notification 2025-08-01 09:52:03 UTC
László Németh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/f83a04c51056445bbf947a31c8c1866a5c30bef1

tdf#167648 cui offapi xmloff sw: add DTP-feature maximum letter spacing

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 10 László Németh 2025-08-01 10:00:36 UTC
Commit description:

tdf#167648 cui offapi xmloff sw: add DTP-feature maximum letter spacing

Add new paragraph justification option "Maximum letter spacing"
to distribute letters on (part of) the available blank area of the
justified line instead of overstretching word spacing, like DTP
software do.

This improves typography a lot, allowing typesetting visually better
i.e. more readable paragraphs, minimizing or removing rivers and
too big word spacing (which was common in columns or text without
hyphenation).

* Add spin box to Alignment in paragraph formatting dialog window,
  (also add spin boxes for future Minimum and the alternative
  percent-based Desired letter spacing, see CharKerning);

  For example (only ASCII visualization!), 100% maximum letter
  spacing adds a space character-width blank space between the
  characters, including the original space:

  0%:

  Lorem          ipsum
  pellentesque dolores
  vitae.

  100%:

  L o r e m  i p s u m
  pellentesque dolores
  vitae.

  Normal value: 3%-5% (or more for very narrow columns), which means
  e.g. 1-2 twips (twip = 1/20 pt) letter spacing in a ~12 pt text.

  Note: resolution of the custom letter spacing is only 1 twip yet.

* Store properties in paragraph model:

  css::style::ParagraphProperties::ParaPropLetterSpacingMaximum

  css::style::ParagraphProperties::ParaPropLetterSpacingMinimum

  Note: desired letter spacing is already supported by ODF/UNO,
  see css::style::CharacterProperties::CharKerning.

* Implement visual layout of maximum letter spacing.

  Note: after the last character of the line, there is an
  unwanted letter-spacing, yet (which is visible only with
  big letter-spacing values).

* Add ODF import/export (loext:letter-spacing-maximum and
  loext:letter-spacing-minimum)

* Add ODF unit test.

Note: hyphenated lines and lines with multiple portions do not
yet use custom letter spacing, yet.
Comment 11 Adolfo Jayme Barrientos 2025-08-01 13:14:39 UTC
Another great feature!
Comment 12 László Németh 2025-08-01 22:03:03 UTC
Created attachment 202143 [details]
test document: paragraphs with 0%, 5%, 25% and 100% custom letter spacing

(fixed version, now with 100% letter spacing instead of 0% in the last paragraph)
Comment 13 László Németh 2025-08-06 08:45:06 UTC
(In reply to Adolfo Jayme Barrientos from comment #11)
> Another great feature!

@Adolfo: thanks for your kind feedback! This feature needs a lot of work, yet (minimum word spacing, adding them on the lines with hyphenation and text portions), but the fist result is really impressive. I'm going to attach a gif animation to show that.
Comment 14 László Németh 2025-08-06 08:46:23 UTC
Created attachment 202207 [details]
letter_spacing.gif: animation about changing maximum letter spacing
Comment 15 Eyal Rozenberg 2025-08-06 09:03:32 UTC
First, thanks Laszlo for putting in the work on this. It's another step in the long path laid out in bug 38159...

I was wondering how this would relate to the extra character spacing we can now set. Is the percentage you mention relative to the font size (which is the x-height)? Is it relative to fundamental unit of inter-character horizontal space, that we can't control? Is it relative to fundamental hspace + extr space together?

Also, I was wondering if it makes sense for the extra spacing we have now to be defined in absolute rather than relative terms, but perhaps that's a matter for another bug.

Another question is about squeezing space rather than adding it. Do you support that, to possibly avoid losing a word on the line?

Finally, and this the less-enthusiastic part - let's remember that this should not be overused. Like Laszlo notes - beyond a few percentage points of increase/decrease, the spacing change becomes noticeable and jarring, and itself hurts readability. The really big step would be paragraph-level breaking logic I'm afraid :-(