Commit cf774c1c authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Add ShapeResult::SubRange

A small utility function that creates a ShapeResult and CopyRange.

Used in one place, and another coming in line breaker WIP.

Also changed |primary_font_| field to const to eliminate a const_cast.

Bug: 636993
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: I293bf245a360841ddc5ce87e805b60770b2ec553
Reviewed-on: https://chromium-review.googlesource.com/846603
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526447}
parent b660d519
......@@ -776,6 +776,19 @@ TEST_F(HarfBuzzShaperTest, ShapeResultCopyRangeSegmentGlyphBoundingBox) {
EXPECT_NEAR(result->Width(), result->Bounds().Width(), result->Width() * .1);
}
TEST_F(HarfBuzzShaperTest, SubRange) {
String string(u"Hello world");
TextDirection direction = TextDirection::kRtl;
HarfBuzzShaper shaper(string.Characters16(), string.length());
scoped_refptr<ShapeResult> result = shaper.Shape(&font, direction);
scoped_refptr<ShapeResult> sub_range = result->SubRange(4, 7);
DCHECK_EQ(4u, sub_range->StartIndexForResult());
DCHECK_EQ(7u, sub_range->EndIndexForResult());
DCHECK_EQ(3u, sub_range->NumCharacters());
DCHECK_EQ(result->Direction(), sub_range->Direction());
}
TEST_F(HarfBuzzShaperTest, SafeToBreakLatinCommonLigatures) {
FontDescription::VariantLigatures ligatures;
ligatures.common = FontDescription::kEnabledLigaturesState;
......
......@@ -195,16 +195,21 @@ void ShapeResult::RunInfo::SetGlyphAndPositions(unsigned index,
data.offset = FloatSize(offset_x, offset_y);
}
ShapeResult::ShapeResult(const Font* font,
ShapeResult::ShapeResult(const SimpleFontData* font_data,
unsigned num_characters,
TextDirection direction)
: width_(0),
primary_font_(const_cast<SimpleFontData*>(font->PrimaryFont())),
primary_font_(font_data),
num_characters_(num_characters),
num_glyphs_(0),
direction_(static_cast<unsigned>(direction)),
has_vertical_offsets_(0) {}
ShapeResult::ShapeResult(const Font* font,
unsigned num_characters,
TextDirection direction)
: ShapeResult(font->PrimaryFont(), num_characters, direction) {}
ShapeResult::ShapeResult(const ShapeResult& other)
: width_(other.width_),
glyph_bounding_box_(other.glyph_bounding_box_),
......@@ -814,6 +819,14 @@ void ShapeResult::CopyRange(unsigned start_offset,
#endif
}
scoped_refptr<ShapeResult> ShapeResult::SubRange(unsigned start_offset,
unsigned end_offset) const {
scoped_refptr<ShapeResult> sub_range =
Create(primary_font_.get(), 0, Direction());
CopyRange(start_offset, end_offset, sub_range.get());
return sub_range;
}
#if DCHECK_IS_ON()
void ShapeResult::CheckConsistency() const {
if (runs_.IsEmpty()) {
......
......@@ -124,6 +124,8 @@ class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> {
const TextRun&) const;
void CopyRange(unsigned start, unsigned end, ShapeResult*) const;
scoped_refptr<ShapeResult> SubRange(unsigned start_offset,
unsigned end_offset) const;
String ToString() const;
void ToString(StringBuilder*) const;
......@@ -138,10 +140,16 @@ class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> {
#endif
protected:
ShapeResult(const SimpleFontData*, unsigned num_characters, TextDirection);
ShapeResult(const Font*, unsigned num_characters, TextDirection);
ShapeResult(const ShapeResult&);
static scoped_refptr<ShapeResult> Create(const SimpleFontData* font_data,
unsigned num_characters,
TextDirection direction) {
return base::AdoptRef(
new ShapeResult(font_data, num_characters, direction));
}
static scoped_refptr<ShapeResult> Create(const ShapeResult& other) {
return base::AdoptRef(new ShapeResult(other));
}
......@@ -166,7 +174,7 @@ class PLATFORM_EXPORT ShapeResult : public RefCounted<ShapeResult> {
float width_;
FloatRect glyph_bounding_box_;
Vector<std::unique_ptr<RunInfo>> runs_;
scoped_refptr<SimpleFontData> primary_font_;
scoped_refptr<const SimpleFontData> primary_font_;
unsigned num_characters_;
unsigned num_glyphs_ : 30;
......
......@@ -387,8 +387,7 @@ scoped_refptr<ShapeResult> ShapingLineBreaker::ShapeToEnd(unsigned start,
TextDirection direction = result_->Direction();
if (first_safe == start) {
// If |start| is safe-to-break no reshape is needed.
line_result = ShapeResult::Create(font_, 0, direction);
result_->CopyRange(start, range_end, line_result.get());
line_result = result_->SubRange(start, range_end);
} else if (first_safe < range_end) {
// Otherwise reshape to |first_safe|, then copy the rest.
line_result = Shape(direction, start, first_safe);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment