layout: Add initial support for bidirectional text (BiDi) (#33148)

This adds supports for right-to-left text assigning bidi levels to all
line items when necessary. This includes support for the `dir` attribute
as well as corresponding CSS properties like `unicode-bidi`. It only
implements right-to-left rendering for inline layout at the moment and
doesn't include support for `dir=auto`. Because of missing features,
this causes quite a few tests to start failing, as references become
incorrect due to right-to-left rendering being active in some cases,
but not others (before it didn't exist at all).

Analysis of most of the new failures:

```
- /css/css-flexbox/gap-001-rtl.html
  /css/css-flexbox/gap-004-rtl.html
 - Require implementing BiDi in Flexbox, because the start and
   end inline margins are opposite the order of items.

- /css/CSS2/bidi-text/direction-applies-to-*.xht
  /css/CSS2/bidi-text/direction-applies-to-002.xht
  /css/CSS2/bidi-text/direction-applies-to-003.xht
  /css/CSS2/bidi-text/direction-applies-to-004.xht
  - Broken due to a bug in tables, not allocating the
    right amount of width for a column.

- /css/css-lists/inline-list.html
  - This fails because we wrongly insert a soft wrap opportunity between the
    start of an inline box and its first content.

- /css/css-text/bidi/bidi-lines-001.html
  /css/css-text/bidi/bidi-lines-002.html
  /css/CSS2/text/bidi-flag-emoji.html
  - We do not fully support unicode-bidi: plaintext

- /css/css-text/text-align/text-align-end-010.html
  /css/css-text/text-align/text-align-justify-006.html
  /css/css-text/text-align/text-align-start-010.html
  /html/dom/elements/global-attributes/*
  - We do not support dir=auto yet.

- /css/css-text/white-space/tab-bidi-001.html
  - Servo doesn't support tab stops

- /css/CSS2/positioning/abspos-block-level-001.html
  /css/css-text/word-break/word-break-normal-ar-000.html
  - Do not yet support RTL layout in block

- /css/css-text/white-space/pre-wrap-018.html
  - Even in RTL contexts, spaces at the end of the line must hang and
    not be reordered

- /css/css-text/white-space/trailing-space-and-text-alignment-rtl-002.html
  - We are letting spaces hang with white-space: pre, but they shouldn't
    hang.
```

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
This commit is contained in:
Martin Robinson 2024-08-21 07:28:54 -07:00 committed by GitHub
parent 65bd5a3b99
commit 56280c6242
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
189 changed files with 547 additions and 762 deletions

29
Cargo.lock generated
View file

@ -1287,7 +1287,7 @@ dependencies = [
[[package]]
name = "derive_common"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"darling",
"proc-macro2",
@ -1476,7 +1476,7 @@ dependencies = [
[[package]]
name = "dom"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"bitflags 2.6.0",
]
@ -3737,6 +3737,7 @@ dependencies = [
"servo_url",
"style",
"style_traits",
"unicode-bidi",
"unicode-script",
"unicode-segmentation",
"url",
@ -4082,7 +4083,7 @@ dependencies = [
[[package]]
name = "malloc_size_of"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"accountable-refcell",
"app_units",
@ -5761,7 +5762,7 @@ checksum = "0495e4577c672de8254beb68d01a9b62d0e8a13c099edecdbedccce3223cd29f"
[[package]]
name = "selectors"
version = "0.24.0"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"bitflags 2.6.0",
"cssparser",
@ -6075,7 +6076,7 @@ dependencies = [
[[package]]
name = "servo_arc"
version = "0.2.0"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"serde",
"stable_deref_trait",
@ -6084,7 +6085,7 @@ dependencies = [
[[package]]
name = "servo_atoms"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"string_cache",
"string_cache_codegen",
@ -6282,7 +6283,7 @@ checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "size_of_test"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"static_assertions",
]
@ -6423,7 +6424,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_prefs"
version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
[[package]]
name = "strck"
@ -6476,7 +6477,7 @@ dependencies = [
[[package]]
name = "style"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"app_units",
"arrayvec",
@ -6535,7 +6536,7 @@ dependencies = [
[[package]]
name = "style_config"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"lazy_static",
]
@ -6543,7 +6544,7 @@ dependencies = [
[[package]]
name = "style_derive"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"darling",
"derive_common",
@ -6574,7 +6575,7 @@ dependencies = [
[[package]]
name = "style_traits"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"app_units",
"bitflags 2.6.0",
@ -6923,7 +6924,7 @@ dependencies = [
[[package]]
name = "to_shmem"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"cssparser",
"servo_arc",
@ -6936,7 +6937,7 @@ dependencies = [
[[package]]
name = "to_shmem_derive"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#947990669824c192736f63f982e38b7e62150688"
source = "git+https://github.com/servo/stylo?branch=2024-07-16#c3a84ea8c97b0af542fbb47eee8f6f182b357128"
dependencies = [
"darling",
"derive_common",