Skip to content

Commit

Permalink
[LayoutNG] Enable cache for NextSafeToBreakOffset
Browse files Browse the repository at this point in the history
Fix safe to break computation for LTR in ShapeResult ComputePositionData
and use the PositionData implementation for NextSafeToBreakOffset calls.

Bug: 636993

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I0b6345d7f095a1da4369537a1839a9b27a00377a
Reviewed-on: https://chromium-review.googlesource.com/1125700
Commit-Queue: Emil A Eklund <[email protected]>
Reviewed-by: Koji Ishii <[email protected]>
Cr-Commit-Position: refs/heads/master@{#572694}
  • Loading branch information
eaenet authored and Commit Bot committed Jul 5, 2018
1 parent 8dfcfd9 commit 1c6a421
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions third_party/blink/renderer/platform/fonts/shaping/shape_result.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1176,10 +1176,14 @@ void ShapeResult::ComputePositionData() const {
if (rtl && next_character_index + 1 == character_index)
continue;

// For glyphs with the same character index the first one wins in LTR so
// no need to do anything special.
// For glyphs with the same character index in LTR take the advance from
// the last one but the safe to break flag from the first.
DCHECK_LT(character_index, num_characters_);
data[character_index] = {total_advance, glyph_data.safe_to_break_before};
bool safe_to_break =
next_character_index > character_index
? data[next_character_index - 1].safe_to_break_before
: glyph_data.safe_to_break_before;
data[character_index] = {total_advance, safe_to_break};

total_advance += glyph_data.advance;
next_character_index = character_index + (!rtl ? 1 : -1);
Expand Down Expand Up @@ -1226,8 +1230,9 @@ float ShapeResult::CachedPositionForOffset(unsigned offset) const {
}

unsigned ShapeResult::CachedNextSafeToBreakOffset(unsigned offset) const {
// TODO(layout-dev): Use character_position_->NextSafeToBreakOffset(index)
// once fully implemented. Fails fast/text/trailing_whitespace_wrapping.html
// TODO(layout-dev): Use character_position_ for RTL once supported.
if (!Rtl())
return character_position_->NextSafeToBreakOffset(offset);
return NextSafeToBreakOffset(offset);
}

Expand Down Expand Up @@ -1290,9 +1295,9 @@ unsigned ShapeResult::CharacterPositionData::NextSafeToBreakOffset(
if (adjusted_offset == 0)
return start_offset_;

unsigned length = data_.size() - 1;
unsigned length = data_.size();
for (unsigned i = adjusted_offset; i < length; i++) {
if (data_[i + 1].safe_to_break_before)
if (data_[i].safe_to_break_before)
return start_offset_ + i;
}

Expand Down

0 comments on commit 1c6a421

Please sign in to comment.