Index: ui/gfx/render_text_harfbuzz.cc |
diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
index 0580abe3375e09bddae437c08a958ee6a7d16977..8af8c1f7ad41ee764bf5a8d91cd37686dd229595 100644 |
--- a/ui/gfx/render_text_harfbuzz.cc |
+++ b/ui/gfx/render_text_harfbuzz.cc |
@@ -233,6 +233,8 @@ class HarfBuzzLineBreaker { |
run_list_(run_list), |
text_x_(0), |
line_x_(0), |
+ max_top_(0), |
+ max_bottom_(0), |
max_descent_(0), |
max_ascent_(0) { |
DCHECK_EQ(multiline_, (words_ != nullptr)); |
@@ -256,10 +258,12 @@ class HarfBuzzLineBreaker { |
// Finishes line breaking and outputs the results. Can be called at most once. |
void Finalize(std::vector<internal::Line>* lines, SizeF* size) { |
DCHECK(!lines_.empty()); |
+ float trailing_height = std::max(0.f, max_bottom_ - max_descent_); |
// Add an empty line to finish the line size calculation and remove it. |
AdvanceLine(); |
lines_.pop_back(); |
*size = total_size_; |
+ size->Enlarge(0, trailing_height); |
lines->swap(lines_); |
} |
@@ -384,10 +388,18 @@ class HarfBuzzLineBreaker { |
line->size.set_height(std::max(min_height_, max_descent_ + max_ascent_)); |
line->baseline = |
std::max(min_baseline_, SkScalarRoundToInt(max_ascent_)); |
- line->preceding_heights = std::ceil(total_size_.height()); |
- total_size_.set_height(total_size_.height() + line->size.height()); |
+ if (line == &lines_.front()) { |
msw
2015/02/24 23:31:35
Why does only the first line add the extra height
Jun Mukai
2015/02/25 23:49:19
Comments added. Our code base seems to assume lin
|
+ line->preceding_heights = |
+ std::ceil(std::max(0.f, max_top_ - max_ascent_)); |
+ total_size_.set_height(line->preceding_heights + line->size.height()); |
+ } else { |
+ line->preceding_heights = std::ceil(total_size_.height()); |
+ total_size_.set_height(total_size_.height() + line->size.height()); |
+ } |
total_size_.set_width(std::max(total_size_.width(), line->size.width())); |
} |
+ max_top_ = 0; |
+ max_bottom_ = 0; |
max_descent_ = 0; |
max_ascent_ = 0; |
line_x_ = 0; |
@@ -422,8 +434,10 @@ class HarfBuzzLineBreaker { |
line->size.set_width(line->size.width() + width); |
max_descent_ = std::max(max_descent_, metrics.fDescent); |
- // fAscent is always negative. |
+ max_bottom_ = std::max(max_bottom_, metrics.fBottom); |
+ // fAscent and fTop are always negative. |
max_ascent_ = std::max(max_ascent_, -metrics.fAscent); |
+ max_top_ = std::max(max_top_, -metrics.fTop); |
if (run.is_rtl) { |
rtl_segments_.push_back( |
@@ -452,6 +466,8 @@ class HarfBuzzLineBreaker { |
SkScalar text_x_; |
SkScalar line_x_; |
+ float max_top_; |
+ float max_bottom_; |
float max_descent_; |
float max_ascent_; |