Skip to content

Read the text-decoration longhands, text-align: start and end, and word-break and overflow-wrap #607

Open

Description

@jakejackson1

Part of #552 (step 28, missing support, medium priority).

Three groups of text properties that CSS resets and frameworks use are not read.

  • The text-decoration longhands:
    • text-decoration-line, -color, -style and -thickness
    • text-underline-offset and text-underline-position
    • the style, colour and thickness parts of the text-decoration shorthand
  • text-align: start and end, the logical values Bootstrap 5 uses (.text-start, .text-end), and match-parent.
  • word-break, overflow-wrap and word-wrap. Their values are ignored, and mPDF's own breaking applies.

Measured on gravitypdf at 60b82630, PHP 8.5.4, from the text handed to Cell() and the drawn lines.

Rule Browser mPDF
p { text-decoration-line: underline } underlined no line
p { text-decoration: underline wavy #f00 } a red wavy underline a straight underline in the text colour
div { width: 100mm; text-align: end } right-aligned in ltr left-aligned
div { width: 100mm; direction: rtl; text-align: end } left-aligned right-aligned, the rtl default
td { text-align: end } right-aligned left-aligned
div { width: 30mm; word-break: keep-all } with Supercalifragilisticexpialidocious the word overflows the box broken into three pieces
div { width: 30mm; overflow-wrap: normal }, the same word overflows broken
td { word-break: break-all } in a width: 30mm table, a 52-letter word broken inside the cell the table widens to hold the word, 105 mm of text on one line

Cause.

  • Decorations. setCSS() reads only TEXT-DECORATION, and matches underline, overline and line-through inside it by substring (src/Mpdf.php:19908 onwards). Each line takes the text colour at the time (:19921, :19932). _dounderline() (:11616) and the strike-through code draw a solid line.
  • Alignment. setCSS() maps left, center, right and justify for blocks (src/Mpdf.php:19406 onwards), and cells use Tag::ALIGN (src/Tag/Tag.php:74-85). start, end and match-parent match neither.
  • Word breaking. WriteFlowingBlock() (src/Mpdf.php:8702) tries its break opportunities in order: spaces, hyphenation, U+200B, hard and soft hyphens, CJK. With none left, it cuts the word at the edge. That is overflow-wrap: anywhere, whatever the style says. A cell's minimum width is its longest word, so the column widens instead.

Fix.

  • Decorations.
  • Alignment. Map start to left in ltr and right in rtl, end the other way, for blocks and cells. match-parent takes the parent's alignment with start/end resolved against the parent's direction.
  • Word breaking. Read word-break (normal, break-all, keep-all, break-word) and overflow-wrap (normal, break-word, anywhere), with word-wrap as an alias of overflow-wrap. Both inherit.
    • break-all and anywhere also lower a cell's minimum width to one character, so the column need not widen.
    • keep-all removes the CJK break opportunities.
    • Breaking a word at the edge of a block is the better default for paper; CSS's default is to overflow. Keep today's behaviour when neither property is set, and follow them when they are. Say so in the PR.

Tests. Each row above, text-decoration-color on a nested span, all five styles, text-underline-offset with a descender font, start/end in ltr and rtl blocks and cells, and a long URL under each word-break and overflow-wrap value, in a block and in a cell.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions