layout: Fix line breaking opportunities for Chinese and Japanese - #43744
Conversation
|
🔨 Triggering try run (#23704025326) for Linux (WPT) |
Loirooriol
left a comment
There was a problem hiding this comment.
The testcase from #43677 doesn't seem to use japanese/chinese at all?
|
Test results for linux-wpt from try job (#23704025326): Flaky unexpected result (17)
Stable unexpected results that are known to be intermittent (19)
Stable unexpected results (23)
|
|
|
|
I've totally refactored this to ditch the character sniffing, now it just checks for lang="ja" or lang="zh" using the computed _x_lang attribute. |
6fa759c to
80334ab
Compare
|
🔨 Triggering try run (#23715380684) for Linux (WPT) |
|
Test results for linux-wpt from try job (#23715380684): Flaky unexpected result (29)
Stable unexpected results that are known to be intermittent (14)
Stable unexpected results (12)
|
|
|
|
Test results look good. You can automatically update expectations by running the following command: |
|
Are you sure this fixes #43677? I don't see how that is related to CJK. Btw the new unit test doesn't look very helpful to me, as it's just testing the |
80334ab to
f5c70a1
Compare
|
The TPAC page uses |
If this is not fixing #43677, drop |
| // has a Japanese or Chinese language set. | ||
| options.ja_zh = { | ||
| let lang_str = lang.0.as_ref(); | ||
| lang_str.starts_with("zh") || lang_str.starts_with("ja") |
There was a problem hiding this comment.
Should this check that there is an hyphen after zh or ja? Even if no other language code starts with these letters, I guess an invalid one could be provided?
Or https://github.com/unicode-org/icu4x/blob/030624fc705b92bc2b8c32f68d1cc2a78cbb2fce/components/segmenter/src/line.rs#L241-L243 just checks for equality 🤔
There was a problem hiding this comment.
Ah, no, icu4x 2 checks the .language.
So maybe LanguageIdentifier::from_str(lang_str).is_ok_and(|lang_id| lang_id.language, language!("ja") | language!("zh"))?
With the idea of just using LanguageIdentifier::from_str(lang_str) once we update to icu4x 2.
f5c70a1 to
f41df98
Compare
|
|
| use icu_locid::LanguageIdentifier; | ||
| let lang_str = lang.0.as_ref(); | ||
| LanguageIdentifier::from_str(lang_str).is_ok_and(|lang_id| { | ||
| let lang = lang_id.language.as_str(); |
There was a problem hiding this comment.
Better use the language!() macro instead of serializing and comparing as a string
Loirooriol
left a comment
There was a problem hiding this comment.
You need to sign off your commits: https://github.com/servo/servo/pull/43744/checks?check_run_id=69730605068
| let lang = lang_id.language.as_str(); | ||
| lang == "ja" || lang == "zh" | ||
| }) | ||
| use icu_locid::subtags_language as language; |
There was a problem hiding this comment.
Can you move the import to the start of the file? Also, I think this should work:
use icu_locid::subtags::language;| lang.0 | ||
| .as_ref() | ||
| .parse::<icu_locid::LanguageIdentifier>() |
There was a problem hiding this comment.
Nit: this was a bit shorter as LanguageIdentifier::from_str(lang_str). str::parse just uses FromStr::from_str(self).
You can also import LanguageIdentifier at the start of the file.
490e815 to
7596ee3
Compare
Signed-off-by: SharanRP <z8903830@gmail.com>
Signed-off-by: SharanRP <z8903830@gmail.com>
Signed-off-by: SharanRP <z8903830@gmail.com>
7596ee3 to
95b394d
Compare
Signed-off-by: SharanRP <z8903830@gmail.com>
95b394d to
f35ad25
Compare
| use icu_locid::LanguageIdentifier; | ||
| use icu_locid::subtags::language; | ||
|
|
||
| lang.0.as_ref().parse::<LanguageIdentifier>().is_ok_and(|lang_id| { |
There was a problem hiding this comment.
./mach fmt doesn't like this.
| lang.0.as_ref().parse::<LanguageIdentifier>().is_ok_and(|lang_id| { | |
| lang.0.parse::<LanguageIdentifier>().is_ok_and(|lang_id| { |
| use icu_locid::LanguageIdentifier; | ||
| use icu_locid::subtags::language; |
There was a problem hiding this comment.
Move to the top of the file.
| use icu_locid::subtags::language; | ||
|
|
||
| lang.0.as_ref().parse::<LanguageIdentifier>().is_ok_and(|lang_id| { | ||
| lang_id.language == language!("ja") || lang_id.language == language!("zh") |
There was a problem hiding this comment.
Can use matches!():
| lang_id.language == language!("ja") || lang_id.language == language!("zh") | |
| const JA: Language = language!("ja"); | |
| const ZH: Language = language!("zh"); | |
| matches!(lang_id.language, JA | ZH) |
Signed-off-by: SharanRP <z8903830@gmail.com>
72e760b to
6a42521
Compare
I don't see such thing, editing out |
Enable
CJK-awareline breaking in inline layout so Chinese/Japanese text gets proper wrap opportunities instead of overflowing containers.Testing: some WPT are now passing