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

Side by Side Diff: chrome/common/badge_util.cc

Issue 10790128: Revert 147915 - Cleanup gfx::Canvas now that 10562027 has landed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/badge_util.h" 5 #include "chrome/common/badge_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkTypeface.h" 10 #include "third_party/skia/include/core/SkTypeface.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 // When centering the text, we need to make sure there are an equal number 79 // When centering the text, we need to make sure there are an equal number
80 // of pixels on each side as otherwise the text looks off-center. So if the 80 // of pixels on each side as otherwise the text looks off-center. So if the
81 // padding would be uneven, clip one pixel off the right side. 81 // padding would be uneven, clip one pixel off the right side.
82 int badge_width = icon.width(); 82 int badge_width = icon.width();
83 if ((SkScalarRound(text_width) % 1) != (badge_width % 1)) 83 if ((SkScalarRound(text_width) % 1) != (badge_width % 1))
84 badge_width--; 84 badge_width--;
85 85
86 // Render the badge bitmap and overlay into a canvas. 86 // Render the badge bitmap and overlay into a canvas.
87 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas( 87 scoped_ptr<gfx::Canvas> canvas(
88 gfx::Size(badge_width, icon.height()), ui::SCALE_FACTOR_100P, false)); 88 new gfx::Canvas(gfx::Size(badge_width, icon.height()), false));
89 canvas->DrawImageInt(icon, 0, 0); 89 canvas->DrawImageInt(icon, 0, 0);
90 90
91 // Draw the text overlay centered horizontally and vertically. Skia expects 91 // Draw the text overlay centered horizontally and vertically. Skia expects
92 // us to specify the lower left coordinate of the text box, which is why we 92 // us to specify the lower left coordinate of the text box, which is why we
93 // add 'font_size - 1' to the height. 93 // add 'font_size - 1' to the height.
94 SkScalar x = (badge_width - text_width)/2; 94 SkScalar x = (badge_width - text_width)/2;
95 SkScalar y = (icon.height() - font_size)/2 + font_size - 1; 95 SkScalar y = (icon.height() - font_size)/2 + font_size - 1;
96 canvas->sk_canvas()->drawText( 96 canvas->sk_canvas()->drawText(
97 badge_text.c_str(), badge_text.size(), x, y, *paint); 97 badge_text.c_str(), badge_text.size(), x, y, *paint);
98 98
99 // Return the generated image. 99 // Return the generated image.
100 return canvas->ExtractImageRep().sk_bitmap(); 100 return canvas->ExtractBitmap();
101 } 101 }
102 102
103 } // namespace badge_util 103 } // namespace badge_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.cc ('k') | chrome/renderer/print_web_view_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698