| OLD | NEW |
| 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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 text_paint->setTypeface(typeface.get()); | 89 text_paint->setTypeface(typeface.get()); |
| 90 // |text_paint| adds its own ref. Release the ref from CreateFontName. | 90 // |text_paint| adds its own ref. Release the ref from CreateFontName. |
| 91 } | 91 } |
| 92 return text_paint; | 92 return text_paint; |
| 93 } | 93 } |
| 94 | 94 |
| 95 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon, | 95 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon, |
| 96 float font_size, | 96 float font_size, |
| 97 const string16& text, | 97 const base::string16& text, |
| 98 const string16& fallback) { | 98 const base::string16& fallback) { |
| 99 const int kMinPadding = 1; | 99 const int kMinPadding = 1; |
| 100 | 100 |
| 101 // Calculate the proper style/text overlay to render on the badge. | 101 // Calculate the proper style/text overlay to render on the badge. |
| 102 SkPaint* paint = badge_util::GetBadgeTextPaintSingleton(); | 102 SkPaint* paint = badge_util::GetBadgeTextPaintSingleton(); |
| 103 paint->setTextSize(SkFloatToScalar(font_size)); | 103 paint->setTextSize(SkFloatToScalar(font_size)); |
| 104 paint->setColor(SK_ColorWHITE); | 104 paint->setColor(SK_ColorWHITE); |
| 105 | 105 |
| 106 std::string badge_text = UTF16ToUTF8(text); | 106 std::string badge_text = UTF16ToUTF8(text); |
| 107 | 107 |
| 108 // See if the text will fit - otherwise use a default. | 108 // See if the text will fit - otherwise use a default. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 canvas->sk_canvas()->drawText( | 220 canvas->sk_canvas()->drawText( |
| 221 text.c_str(), text.size(), | 221 text.c_str(), text.size(), |
| 222 SkFloatToScalar(rect.x() + | 222 SkFloatToScalar(rect.x() + |
| 223 static_cast<float>(rect.width() - text_width) / 2), | 223 static_cast<float>(rect.width() - text_width) / 2), |
| 224 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding), | 224 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding), |
| 225 *text_paint); | 225 *text_paint); |
| 226 canvas->Restore(); | 226 canvas->Restore(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace badge_util | 229 } // namespace badge_util |
| OLD | NEW |