Bug 234758

Summary: [LFC][IFC] Take grapheme clusters into account when keeping the first "character" on the line
Product: WebKit Reporter: zalan <zalan>
Component: Layout and RenderingAssignee: zalan <zalan>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, koivisto, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description zalan 2021-12-30 19:27:46 PST
in preparation for enabling complex font codepath for IFC.
Comment 1 zalan 2021-12-30 19:37:55 PST
Created attachment 448115 [details]
Patch
Comment 2 Antti Koivisto 2021-12-31 00:47:23 PST
Comment on attachment 448115 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=448115&action=review

> Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:296
> +    auto graphemeClustersIterator = NonSharedCharacterBreakIterator { textContent };
> +    auto nextPosition = ubrk_following(graphemeClustersIterator, inlineTextItem.start());
> +    if (nextPosition == UBRK_DONE)
> +        return inlineTextItem.length();
> +    return nextPosition - inlineTextItem.start();

Isn't it slow to make the iterator repeatedly? Maybe we should cache it or make it in the caller?
Comment 3 Antti Koivisto 2021-12-31 01:00:32 PST
Comment on attachment 448115 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=448115&action=review

>> Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:296
>> +    auto graphemeClustersIterator = NonSharedCharacterBreakIterator { textContent };
>> +    auto nextPosition = ubrk_following(graphemeClustersIterator, inlineTextItem.start());
>> +    if (nextPosition == UBRK_DONE)
>> +        return inlineTextItem.length();
>> +    return nextPosition - inlineTextItem.start();
> 
> Isn't it slow to make the iterator repeatedly? Maybe we should cache it or make it in the caller?

I suppose it is always initialized with a different StringView so there is nothing to cache.
Comment 4 zalan 2021-12-31 06:15:29 PST
(In reply to Antti Koivisto from comment #3)
> Comment on attachment 448115 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=448115&action=review
> 
> >> Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:296
> >> +    auto graphemeClustersIterator = NonSharedCharacterBreakIterator { textContent };
> >> +    auto nextPosition = ubrk_following(graphemeClustersIterator, inlineTextItem.start());
> >> +    if (nextPosition == UBRK_DONE)
> >> +        return inlineTextItem.length();
> >> +    return nextPosition - inlineTextItem.start();
> > 
> > Isn't it slow to make the iterator repeatedly? Maybe we should cache it or make it in the caller?
> 
> I suppose it is always initialized with a different StringView so there is
> nothing to cache.
Yes. This codepath may be triggered once per line at most. It is also not a highly common case as regular web pages let their inline content fit the container. However it is very much used for testing content breaking (width: 0px).
Comment 5 EWS 2021-12-31 06:22:08 PST
Committed r287493 (245628@main): <https://commits.webkit.org/245628@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 448115 [details].
Comment 6 Radar WebKit Bug Importer 2021-12-31 06:23:18 PST
<rdar://problem/87028287>