diff options
author | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 21:21:11 +0000 |
---|---|---|
committer | asvitkine@chromium.org <asvitkine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-27 21:21:11 +0000 |
commit | dc309f0e7faa2b8e0a4558edf4976a23ba100cc7 (patch) | |
tree | 17b6d7a02d15e4b118f5a2238d831a87a68fad77 /ui | |
parent | d3765982212c3cfc9bf56f5c853edfdb051735b0 (diff) | |
download | chromium_src-dc309f0e7faa2b8e0a4558edf4976a23ba100cc7.zip chromium_src-dc309f0e7faa2b8e0a4558edf4976a23ba100cc7.tar.gz chromium_src-dc309f0e7faa2b8e0a4558edf4976a23ba100cc7.tar.bz2 |
Correct text y position calculation in RenderTextWin.
The previous calculation had a problem due to the following logic:
SkPoint point(SkPoint::Make(SkIntToScalar(offset.x()),
SkIntToScalar(display_rect().height() - offset.y())));
If display_rect().y() was large and height was the height for e.g. one line of text, then when the code subtracted offset.y() (which was based on display_rect().y()), the result was a negative y position (offscreen) for the text.
This CL changes the logic to correctly center the text vertically regardless of the y position, which I believe was the intention of the code.
BUG=none
TEST=Open Chrome with --use-pure-views. Type something into omnibox. Text should be centered in omnibox.
Review URL: http://codereview.chromium.org/8401032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/render_text_win.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index 5e0cab5..6ae45d9 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -589,8 +589,13 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) { Point offset(ToViewPoint(Point())); // TODO(msw): Establish a vertical baseline for strings of mixed font heights. size_t height = default_style().font.GetHeight(); + + float base_x = SkIntToScalar(offset.x()); + float base_y = SkIntToScalar(offset.y()); // Center the text vertically in the display area. - offset.Offset(0, (display_rect().height() - height) / 2); + base_y += (display_rect().height() - height) / 2; + // Offset by the font size to account for Skia expecting y to be the bottom. + base_y += default_style().font.GetFontSize(); SkPaint paint; paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); @@ -598,8 +603,7 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) { paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setLCDRenderText(true); - SkPoint point(SkPoint::Make(SkIntToScalar(offset.x()), - SkIntToScalar(display_rect().height() - offset.y()))); + scoped_array<SkPoint> pos; for (size_t i = 0; i < runs_.size(); ++i) { // Get the run specified by the visual-to-logical map. @@ -620,9 +624,9 @@ void RenderTextWin::DrawVisualText(Canvas* canvas) { // Based on WebCore::skiaDrawText. pos.reset(new SkPoint[run->glyph_count]); for (int glyph = 0; glyph < run->glyph_count; glyph++) { - pos[glyph].set(point.x() + run->offsets[glyph].du, - point.y() + run->offsets[glyph].dv); - point.offset(SkIntToScalar(run->advance_widths[glyph]), 0); + pos[glyph].set(base_x + run->offsets[glyph].du, + base_y + run->offsets[glyph].dv); + base_x += SkIntToScalar(run->advance_widths[glyph]); } size_t byte_length = run->glyph_count * sizeof(WORD); canvas_skia->drawPosText(run->glyphs.get(), byte_length, pos.get(), paint); |