Skip to content

Commit

Permalink
Merge 3163: Adjust the mid-word-break heuristic limit to 4em for Emoj…
Browse files Browse the repository at this point in the history
…i ZWJ sequence

Mid-word-break algorithm kicks in when CSS properties such as
'word-wrap: break-word' is used. Logically speaking, we should layout
as normal, and break words if overflow occurs.

However, Blink has 2em heuristic limit because of the performance
problem in certain cases. This means Blink measures characters that go
beyond the right edge only up to 2em before it starts mid-word-break.
See the previous CL[1] for more details.

This patch adjusts it to 4em. The longest common ligature is Emoji ZWJ
sequence, and its v5.0[2] can ligate 4 Emoji into 1 at maximum. To
handle this, 3em overflow is needed, and 1em for a rainy day fund.

[1] r403830, https://codereview.chromium.org/2077313002
[2] http://unicode.org/emoji/charts/emoji-zwj-sequences.html

[email protected]

(cherry picked from commit 14ec221)

Bug: 746222
Change-Id: Ic58b58716502f4ae9a06c1e91d2f5de944bc7978
Reviewed-on: https://chromium-review.googlesource.com/581249
Reviewed-by: Dominik Röttsches <[email protected]>
Commit-Queue: Koji Ishii <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#488813}
Reviewed-on: https://chromium-review.googlesource.com/587705
Reviewed-by: Koji Ishii <[email protected]>
Cr-Commit-Position: refs/branch-heads/3163@{#74}
Cr-Branched-From: ff259ba-refs/heads/master@{#488528}
  • Loading branch information
kojiishi committed Jul 27, 2017
1 parent e87856f commit d2c58dc
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,11 @@ ALWAYS_INLINE bool BreakingContext::ShouldMidWordBreak(
// However, doing so can hit the performance when a "word" is really long,
// such as minimized JS, because the next line will re-shape the rest of the
// word in the current architecture.
// This function is a heuristic optimization to stop at 2em overflow.
float overflow_allowance = 2 * font.GetFontDescription().ComputedSize();
// This function is a heuristic optimization to stop at 4em overflow.
// The longest common ligature is Emoji ZWJ sequence, which ligates 4 Emoji
// into 1 at maximum as of v5.0. This sequence requires 3em overflow, and 1em
// for a rainy day fund.
float overflow_allowance = 4 * font.GetFontDescription().ComputedSize();

width_from_last_breaking_opportunity += char_width;
bool mid_word_break_is_before_surrogate_pair =
Expand Down

0 comments on commit d2c58dc

Please sign in to comment.