Repository navigation
Commit 0dc5b19
Support soft hyphen (U+00AD) rendering with a Hyphens API (flutter#185152)
## Summary
Adds visible soft hyphen (U+00AD) rendering at line breaks, with a new
`Hyphens` API to opt out. Fixes flutter#18443 on native
platforms; web rendering is tracked in flutter#193506.
A line break that falls on a soft hyphen now renders a visible `-` by
default. A new `Hyphens { manual, hidden }` enum controls this:
- `Hyphens.manual` (default): render a hyphen at the break.
- `Hyphens.hidden`: don't render the hyphen. The soft hyphen is still a
break opportunity.
`hyphens` is a parameter on `Text` / `RichText`, `TextPainter`,
`RenderParagraph`, `TextStyle.getParagraphStyle` and `dart:ui`'s
`ParagraphStyle`, following `textAlign` / `maxLines`. It is not a
`TextStyle` field. Customizing the hyphen string is deferred to flutter#189617.
Design doc:
[flutter.dev/go/soft-hyphens](https://flutter.dev/go/soft-hyphens)
(tracking issue flutter#185154).
## Background
Flutter already breaks lines at U+00AD but never draws the hyphen, so it
behaves like a zero-width space. This change doesn't add any new break
opportunities or change where lines break, but the rendered hyphen makes
its line wider, so it can change `Paragraph.longestLine` and the size of
text laid out with `TextWidthBasis.longestLine`.
The Skia side landed in
[`98daf58d`](google/skia@98daf58d4c) (Skia CL
[1208837](https://skia-review.googlesource.com/c/skia/+/1208837)),
behind `ParagraphStyle::setRenderSoftHyphens(bool)`, which defaults to
`false` for other Skia clients.
## Changes
**Engine**
- `txt::ParagraphStyle` gains a `render_soft_hyphens` flag (default
`true`), which `ParagraphBuilderSkia::TxtToSkia` forwards to
`setRenderSoftHyphens`. The Impeller interop toolkit builds
`txt::ParagraphStyle` too, so it also gets the new default.
- `paragraph_builder.cc` decodes `ParagraphStyle.hyphens` from the FFI
buffer (mask bit 13, slot 7).
- `dart:ui` adds the public `Hyphens` enum and `ParagraphStyle.hyphens`.
The web `dart:ui` accepts and stores the value; web rendering is
flutter#193506.
**Framework**
- `Hyphens` is re-exported from `dart:ui` via
`painting/basic_types.dart`.
- `hyphens` is threaded through `TextStyle.getParagraphStyle` →
`TextPainter` → `RenderParagraph` → `RichText` → `Text` / `Text.rich`,
including the selectable-text path.
## Breaking change
- **API:** adding `hyphens` to `TextStyle.getParagraphStyle` breaks
classes that override it. In practice that's test doubles like the
`_TextStyleProxy` in `test/material/theme_test.dart`, updated here;
material_ui's copy was removed in flutter/packages#12728. The fix is to
add `Hyphens? hyphens` to the override. Migration guide:
flutter/website#13945.
- **Rendering:** text containing U+00AD now shows a hyphen at
soft-hyphen line breaks by default. `Hyphens.hidden` restores the old
look.
## Known limitations
- The hyphen is appended after line breaking, so a line can exceed
`maxWidth` by the hyphen's advance.
- The rendered hyphen isn't included in selection highlight rects
(flutter#189234).
- `EditableText` (and so `TextField`) and `SelectableText` don't take a
`hyphens` parameter yet, so they always render the hyphen.
- Skia also draws the hyphen when a line ends in U+00AD without breaking
there (text ending in U+00AD, or U+00AD right before a space or
newline). The Skia fix is in review ([CL
1378356](https://skia-review.googlesource.com/c/skia/+/1378356)) and
will come in with a Skia roll once it lands.
## Test plan
- [ ] `paragraph_builder_skia_tests.cc::RenderSoftHyphensEnabled`:
`render_soft_hyphens` maps onto Skia in both states
- [ ] `testing/dart/text_test.dart`: `ParagraphStyle.hyphens` encodes
and round-trips in `toString`
- [ ] `testing/dart/paragraph_test.dart`: `ParagraphStyle.hyphens`
reaches the text layout (a line that breaks at a soft hyphen is wider
with `manual` than with `hidden`, and unset matches `manual`), which
covers decoding the setting in the engine
- [ ] `test/widgets/rich_text_test.dart`: `RichText` exposes `hyphens`
via `debugFillProperties`
- [ ] `test/widgets/text_test.dart`: `Text` forwards `hyphens` to
`RenderParagraph` (incl. selectable path); default resolves to
`Hyphens.manual`
- [ ] `test/rendering/paragraph_test.dart`: `RenderParagraph.hyphens`
setter triggers relayout
- [ ] `test/painting/text_painter_test.dart`: `TextPainter.hyphens`
setter; the same width check through `TextPainter`, and changing
`hyphens` after layout changes the width
- [ ] Google internal testing
- [ ] Manual smoke: `Text('inter\u00ADnational')` in a narrow container
shows `inter-` / `national`1 parent b1424df commit 0dc5b19
28 files changed
Lines changed: 337 additions & 18 deletions
File tree
- engine/src/flutter
- lib
- ui
- text
- web_ui
- lib
- src/engine
- canvaskit
- skwasm
- skwasm_impl
- skwasm_stub
- web_paragraph
- test/ui
- testing/dart
- txt
- src
- skia
- txt
- tests
- packages/flutter
- lib/src
- painting
- rendering
- widgets
- test
- material
- painting
- rendering
- widgets
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1327 | 1327 | | |
1328 | 1328 | | |
1329 | 1329 | | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
1330 | 1344 | | |
1331 | 1345 | | |
1332 | 1346 | | |
| |||
1937 | 1951 | | |
1938 | 1952 | | |
1939 | 1953 | | |
| 1954 | + | |
| 1955 | + | |
1940 | 1956 | | |
1941 | 1957 | | |
1942 | 1958 | | |
| |||
1950 | 1966 | | |
1951 | 1967 | | |
1952 | 1968 | | |
| 1969 | + | |
1953 | 1970 | | |
1954 | | - | |
| 1971 | + | |
1955 | 1972 | | |
1956 | 1973 | | |
1957 | 1974 | | |
| |||
2002 | 2019 | | |
2003 | 2020 | | |
2004 | 2021 | | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
2005 | 2026 | | |
2006 | 2027 | | |
2007 | 2028 | | |
| |||
2068 | 2089 | | |
2069 | 2090 | | |
2070 | 2091 | | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
2071 | 2095 | | |
2072 | 2096 | | |
2073 | 2097 | | |
| |||
2081 | 2105 | | |
2082 | 2106 | | |
2083 | 2107 | | |
| 2108 | + | |
2084 | 2109 | | |
2085 | 2110 | | |
2086 | 2111 | | |
| |||
2094 | 2119 | | |
2095 | 2120 | | |
2096 | 2121 | | |
| 2122 | + | |
2097 | 2123 | | |
2098 | 2124 | | |
2099 | 2125 | | |
| |||
2157 | 2183 | | |
2158 | 2184 | | |
2159 | 2185 | | |
2160 | | - | |
| 2186 | + | |
| 2187 | + | |
2161 | 2188 | | |
2162 | 2189 | | |
2163 | 2190 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
| |||
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
| 111 | + | |
106 | 112 | | |
107 | 113 | | |
108 | 114 | | |
| |||
273 | 279 | | |
274 | 280 | | |
275 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
276 | 288 | | |
277 | 289 | | |
278 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
| 415 | + | |
415 | 416 | | |
416 | 417 | | |
417 | 418 | | |
| |||
426 | 427 | | |
427 | 428 | | |
428 | 429 | | |
| 430 | + | |
429 | 431 | | |
430 | 432 | | |
431 | 433 | | |
| |||
440 | 442 | | |
441 | 443 | | |
442 | 444 | | |
| 445 | + | |
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
79 | 89 | | |
80 | 90 | | |
81 | 91 | | |
| |||
263 | 273 | | |
264 | 274 | | |
265 | 275 | | |
266 | | - | |
| 276 | + | |
| 277 | + | |
267 | 278 | | |
268 | 279 | | |
269 | 280 | | |
| |||
282 | 293 | | |
283 | 294 | | |
284 | 295 | | |
| 296 | + | |
285 | 297 | | |
286 | 298 | | |
287 | 299 | | |
| |||
304 | 316 | | |
305 | 317 | | |
306 | 318 | | |
307 | | - | |
| 319 | + | |
| 320 | + | |
308 | 321 | | |
309 | 322 | | |
310 | 323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| 392 | + | |
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
746 | 746 | | |
747 | 747 | | |
748 | 748 | | |
| 749 | + | |
749 | 750 | | |
750 | 751 | | |
751 | 752 | | |
| |||
757 | 758 | | |
758 | 759 | | |
759 | 760 | | |
760 | | - | |
| 761 | + | |
| 762 | + | |
761 | 763 | | |
762 | 764 | | |
763 | 765 | | |
| |||
855 | 857 | | |
856 | 858 | | |
857 | 859 | | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
858 | 868 | | |
859 | 869 | | |
860 | 870 | | |
| |||
876 | 886 | | |
877 | 887 | | |
878 | 888 | | |
879 | | - | |
| 889 | + | |
| 890 | + | |
880 | 891 | | |
881 | 892 | | |
882 | 893 | | |
| |||
894 | 905 | | |
895 | 906 | | |
896 | 907 | | |
| 908 | + | |
897 | 909 | | |
898 | 910 | | |
899 | 911 | | |
| |||
916 | 928 | | |
917 | 929 | | |
918 | 930 | | |
919 | | - | |
| 931 | + | |
| 932 | + | |
920 | 933 | | |
921 | 934 | | |
922 | 935 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
| 195 | + | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
165 | 166 | | |
166 | 167 | | |
167 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
| |||
91 | 98 | | |
92 | 99 | | |
93 | 100 | | |
| 101 | + | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
| |||
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
| 116 | + | |
108 | 117 | | |
109 | 118 | | |
110 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
381 | 381 | | |
382 | 382 | | |
383 | 383 | | |
| 384 | + | |
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
| |||
394 | 395 | | |
395 | 396 | | |
396 | 397 | | |
| 398 | + | |
397 | 399 | | |
398 | 400 | | |
399 | 401 | | |
| |||
459 | 461 | | |
460 | 462 | | |
461 | 463 | | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| |||
0 commit comments