Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Unified Diff: ui/gfx/render_text_pango.cc

Issue 543073002: Don't paint text outside display area (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Increase indentation on comment (from review). Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text_pango.cc
diff --git a/ui/gfx/render_text_pango.cc b/ui/gfx/render_text_pango.cc
index 07cbfb93cdf5c0e71d09261b618bd009028ba17c..27f00461093003ac75910ee677ca6271d60b70a1 100644
--- a/ui/gfx/render_text_pango.cc
+++ b/ui/gfx/render_text_pango.cc
@@ -410,9 +410,12 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
internal::StyleIterator style(colors(), styles());
for (GSList* it = current_line_->runs; it; it = it->next) {
+ // Skip painting runs outside the display area.
+ if (SkScalarTruncToInt(x) >= display_rect().right())
+ break;
+
PangoLayoutRun* run = reinterpret_cast<PangoLayoutRun*>(it->data);
int glyph_count = run->glyphs->num_glyphs;
- // TODO(msw): Skip painting runs outside the display rect area, like Win.
if (glyph_count == 0)
continue;
@@ -446,9 +449,13 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
x += pango_units_to_double(glyph.geometry.width);
++glyph_index;
+ // If this is the last glyph of the range or the last glyph inside the
+ // display area (which would cause early termination of the loop), paint
+ // the range.
const size_t glyph_text_index = (glyph_index == glyph_count) ?
style_range.end() : GetGlyphTextIndex(run, glyph_index);
- if (!IndexInRange(style_range, glyph_text_index)) {
+ if (!IndexInRange(style_range, glyph_text_index) ||
+ SkScalarTruncToInt(x) >= display_rect().right()) {
// TODO(asvitkine): For cases like "fi", where "fi" is a single glyph
// but can span multiple styles, Pango splits the
// styles evenly over the glyph. We can do this too by
@@ -470,7 +477,10 @@ void RenderTextPango::DrawVisualText(Canvas* canvas) {
style_start_glyph_index = glyph_index;
style_start_x = x;
}
- } while (glyph_index < glyph_count);
+ // Terminates loop when the end of the range has been reached or the next
+ // glyph falls outside the display area.
+ } while (glyph_index < glyph_count &&
+ SkScalarTruncToInt(x) < display_rect().right());
}
renderer.EndDiagonalStrike();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698