Hello,
This CL implements text-transform:full-width as defined in CSS Text level 3.
I have followed the Firefox example, which uses character tables gathered directly from the Unicode database.
The attached WPT test also passes on Firefox (but not on Safari, which uses a external library).
Some existing WPT tests still fail because whitespace conversion (as defined in the standard) is rather complex. I plan to fix those remaining corner cases in a separate CL.
Thank you so much for your review!
Best,
Felipe
Chromestatus:
https://chromestatus.com/feature/5185842163351552
Intent to Prototype:
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
static const UChar32 kKatakanaTable[] = {
Should be `auto kKatakanaTable = std::to_array<UChar32>(` to avoid `UNSAFE_BUFFERS` below.
return 0x3000;
Use `uchar::kIdeographicSpace`.
case 0x00A5: // Yen sign
Use `uchar::kYenSign`.
for (unsigned i = 0; i < text.length(); ++i) {
Let's use `CodePointerIterator` to simplify the code.
for (UChar32 code_point : StringView(text)) {
if (code_point == uchar::kSpace && !preserve_white_space || !U_IS_BMP(code_point)) {
result.Append(code_point);
if (code_point == 0x20 && !preserve_white_space) {
Use `uchar::kSpace`.
String transformed_string = result.ToString();
`ReleaseString()` is preferable.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
DCHECK(index >= 0 && index < std::size(kKatakanaTable));
Can this be `CHECK` instead of `DCHECK` since the failure can be out-of-bounds access?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
DCHECK(index >= 0 && index < std::size(kKatakanaTable));
Can this be `CHECK` instead of `DCHECK` since the failure can be out-of-bounds access?
Also `index >= 0 && ` isn't necessary as `size_t` is unsigned.
crbug.com/1219023 external/wpt/css/css-text/text-transform/text-transform-fullwidth-009.html [ Failure ]
Are you planning to fix them in future patches?
Thank you so much for your detailed feedback.
I have tried to address every point, please let me know if anything else is needed.
Best,
Felipe
Should be `auto kKatakanaTable = std::to_array<UChar32>(` to avoid `UNSAFE_BUFFERS` below.
Done
DCHECK(index >= 0 && index < std::size(kKatakanaTable));
Koji IshiiCan this be `CHECK` instead of `DCHECK` since the failure can be out-of-bounds access?
Also `index >= 0 && ` isn't necessary as `size_t` is unsigned.
Done
case 0x0020: // Space
Felipe EriasUse `uchar::kSpace`.
Done
return 0x3000;
Felipe EriasUse `uchar::kIdeographicSpace`.
Done
case 0x00A5: // Yen sign
Felipe EriasUse `uchar::kYenSign`.
Done
return 0x25A0;
Felipe EriasUse `uchar::kBlackSquare`.
Done
Let's use `CodePointerIterator` to simplify the code.
for (UChar32 code_point : StringView(text)) {
if (code_point == uchar::kSpace && !preserve_white_space || !U_IS_BMP(code_point)) {
result.Append(code_point);
Done
if (code_point == 0x20 && !preserve_white_space) {
Felipe EriasUse `uchar::kSpace`.
Done
String transformed_string = result.ToString();
Felipe Erias`ReleaseString()` is preferable.
Done
crbug.com/1219023 external/wpt/css/css-text/text-transform/text-transform-fullwidth-009.html [ Failure ]
Are you planning to fix them in future patches?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
LGTM.
CHECK(index < std::size(kKatakanaTable));
This check is unnecessary. std::array::operator[] contains a similar one.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
lgtm w/Kent's feedback applied.
crbug.com/1219023 external/wpt/css/css-text/text-transform/text-transform-fullwidth-009.html [ Failure ]
Felipe EriasAre you planning to fix them in future patches?
Yes, I plan to fix those tests after this CL lands.
Acknowledged
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Thank you, I have removed the unnecessary check.
I have kept the variable declaration in a separate line because IMHO it is a bit easier to read:
size_t index = code_point - 0xFF61;
return kKatakanaTable[index];
This check is unnecessary. std::array::operator[] contains a similar one.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
blink/css: Implement text-transform: full-width
Adds support for CSS text-transform: full-width specified in CSS Text
Level 3.
https://www.w3.org/TR/css-text-3/#text-transform-property
This value transforms all narrow characters that have a full-width
mapping in Unicode to their wide equivalents. This includes ASCII,
Japanese Katakana, Korean Hangul, and several special symbols.
The concrete list of character conversions follows the one used by
Firefox, which was compiled directly from the Unicode database. See:
https://bugzilla.mozilla.org/show_bug.cgi?id=774560
This CL includes a new WPT test:
/css/css-text/text-transform/text-transform-fullwidth-010.html
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
The WPT PR for this CL has been merged upstream! https://github.com/web-platform-tests/wpt/pull/54427
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |