| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 // When centering the text, we need to make sure there are an equal number | 118 // When centering the text, we need to make sure there are an equal number |
| 119 // of pixels on each side as otherwise the text looks off-center. So if the | 119 // of pixels on each side as otherwise the text looks off-center. So if the |
| 120 // padding would be uneven, clip one pixel off the right side. | 120 // padding would be uneven, clip one pixel off the right side. |
| 121 int badge_width = icon.width(); | 121 int badge_width = icon.width(); |
| 122 if ((SkScalarRound(text_width) % 1) != (badge_width % 1)) | 122 if ((SkScalarRound(text_width) % 1) != (badge_width % 1)) |
| 123 badge_width--; | 123 badge_width--; |
| 124 | 124 |
| 125 // Render the badge bitmap and overlay into a canvas. | 125 // Render the badge bitmap and overlay into a canvas. |
| 126 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas( | 126 scoped_ptr<gfx::Canvas> canvas(new gfx::Canvas( |
| 127 gfx::Size(badge_width, icon.height()), 1.0f, false)); | 127 gfx::Size(badge_width, icon.height()), ui::SCALE_FACTOR_100P, false)); |
| 128 canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(icon), 0, 0); | 128 canvas->DrawImageInt(gfx::ImageSkia::CreateFrom1xBitmap(icon), 0, 0); |
| 129 | 129 |
| 130 // Draw the text overlay centered horizontally and vertically. Skia expects | 130 // Draw the text overlay centered horizontally and vertically. Skia expects |
| 131 // us to specify the lower left coordinate of the text box, which is why we | 131 // us to specify the lower left coordinate of the text box, which is why we |
| 132 // add 'font_size - 1' to the height. | 132 // add 'font_size - 1' to the height. |
| 133 SkScalar x = (badge_width - text_width)/2; | 133 SkScalar x = (badge_width - text_width)/2; |
| 134 SkScalar y = (icon.height() - font_size)/2 + font_size - 1; | 134 SkScalar y = (icon.height() - font_size)/2 + font_size - 1; |
| 135 canvas->sk_canvas()->drawText( | 135 canvas->sk_canvas()->drawText( |
| 136 badge_text.c_str(), badge_text.size(), x, y, *paint); | 136 badge_text.c_str(), badge_text.size(), x, y, *paint); |
| 137 | 137 |
| (...skipping 82 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 |