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

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

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Render the badge bitmap and overlay into a canvas. 85 // Render the badge bitmap and overlay into a canvas.
86 scoped_ptr<gfx::CanvasSkia> canvas( 86 scoped_ptr<gfx::CanvasSkia> canvas(
87 new gfx::CanvasSkia(badge_width, icon.height(), false)); 87 new gfx::CanvasSkia(badge_width, icon.height(), false));
88 canvas->DrawBitmapInt(icon, 0, 0); 88 canvas->DrawBitmapInt(icon, 0, 0);
89 89
90 // Draw the text overlay centered horizontally and vertically. Skia expects 90 // Draw the text overlay centered horizontally and vertically. Skia expects
91 // us to specify the lower left coordinate of the text box, which is why we 91 // us to specify the lower left coordinate of the text box, which is why we
92 // add 'font_size - 1' to the height. 92 // add 'font_size - 1' to the height.
93 SkScalar x = (badge_width - text_width)/2; 93 SkScalar x = (badge_width - text_width)/2;
94 SkScalar y = (icon.height() - font_size)/2 + font_size - 1; 94 SkScalar y = (icon.height() - font_size)/2 + font_size - 1;
95 canvas->drawText(badge_text.c_str(), badge_text.size(), x, y, *paint); 95 canvas->sk_canvas()->drawText(
96 badge_text.c_str(), badge_text.size(), x, y, *paint);
96 97
97 // Return the generated image. 98 // Return the generated image.
98 return canvas->ExtractBitmap(); 99 return canvas->ExtractBitmap();
99 } 100 }
100 101
101 } // namespace badge_util 102 } // namespace badge_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698