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 23 matching lines...) Expand all Loading... |
34 if (typeface) { | 34 if (typeface) { |
35 text_paint->setFakeBoldText(true); | 35 text_paint->setFakeBoldText(true); |
36 } else { | 36 } else { |
37 // Fall back to the system font. We don't bold it because we aren't sure | 37 // Fall back to the system font. We don't bold it because we aren't sure |
38 // how it will look. | 38 // how it will look. |
39 // For the most part this code path will only be hit on Linux systems | 39 // For the most part this code path will only be hit on Linux systems |
40 // that don't have Arial. | 40 // that don't have Arial. |
41 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 41 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
42 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); | 42 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); |
43 typeface = SkTypeface::CreateFromName( | 43 typeface = SkTypeface::CreateFromName( |
44 UTF16ToUTF8(base_font.GetFontName()).c_str(), SkTypeface::kNormal); | 44 base_font.GetFontName().c_str(), SkTypeface::kNormal); |
45 DCHECK(typeface); | 45 DCHECK(typeface); |
46 } | 46 } |
47 | 47 |
48 text_paint->setTypeface(typeface); | 48 text_paint->setTypeface(typeface); |
49 // |text_paint| adds its own ref. Release the ref from CreateFontName. | 49 // |text_paint| adds its own ref. Release the ref from CreateFontName. |
50 typeface->unref(); | 50 typeface->unref(); |
51 } | 51 } |
52 return text_paint; | 52 return text_paint; |
53 } | 53 } |
54 | 54 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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->sk_canvas()->drawText( | 95 canvas->sk_canvas()->drawText( |
96 badge_text.c_str(), badge_text.size(), x, y, *paint); | 96 badge_text.c_str(), badge_text.size(), x, y, *paint); |
97 | 97 |
98 // Return the generated image. | 98 // Return the generated image. |
99 return canvas->ExtractBitmap(); | 99 return canvas->ExtractBitmap(); |
100 } | 100 } |
101 | 101 |
102 } // namespace badge_util | 102 } // namespace badge_util |
OLD | NEW |