OLD | NEW |
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 76 } |
77 | 77 |
78 // When centering the text, we need to make sure there are an equal number | 78 // When centering the text, we need to make sure there are an equal number |
79 // of pixels on each side as otherwise the text looks off-center. So if the | 79 // of pixels on each side as otherwise the text looks off-center. So if the |
80 // padding would be uneven, clip one pixel off the right side. | 80 // padding would be uneven, clip one pixel off the right side. |
81 int badge_width = icon.width(); | 81 int badge_width = icon.width(); |
82 if ((SkScalarRound(text_width) % 1) != (badge_width % 1)) | 82 if ((SkScalarRound(text_width) % 1) != (badge_width % 1)) |
83 badge_width--; | 83 badge_width--; |
84 | 84 |
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(new gfx::CanvasSkia); |
87 new gfx::CanvasSkia(badge_width, icon.height(), false)); | 87 canvas->Init(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->skia_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 |
OLD | NEW |