Skip to content

Support svg `white-space:pre`/`pre-wrap` wrapping with the text tool

Add alternative text wrapping modes to the text tool to support:

  • Not using dy for line breaks and line height adjustments, and also keep consecutive whitespaces in text.
  • Support automatic wrapping with inline-size.

I have accepted that the way the rich text editor works means:

  • It is impossible to make it handle line height like SVG does, and
  • Old text shapes that use the dy method cannot be seamlessly converted to use SVG line-height.

To allow the text tool to utilize SVG text wrapping in a limited manner, the text tool now has three modes:

  • Legacy Hard Wrap - the existing behaviour that uses QTextLayout to get metrics for setting dy on each line.
  • SVG Hard Wrap - emulates the existing behaviour (no auto word wrap) but with white-space:pre instead of explicit dy offsets.
  • SVG Auto Wrap with Fixed Width - uses white-space:pre-wrap and inline-size to support auto word wrap.

In addition, line height now has an additional value named "Default", which is used to set line-height:normal to enable the default line height (ascender-descender). This is required because line-height with a numeric value behaves wildly different from the legacy behaviour (see !1850 (closed)), and so we cannot use "100%" line height as the default.

Depends on !1850 (closed), keeping as draft until that is merged.

CCBUG:411475 CCBUG:420471 CCBUG:391796

Edited by Alvin Wong

Merge request reports