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

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

Issue 11280251: chrome: Use skia::RefPtr for skia ref-counted objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linuxbuild Created 8 years 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) 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/utf_string_conversions.h" 8 #include "base/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #else 61 #else
62 const char kPreferredTypeface[] = "Arial"; 62 const char kPreferredTypeface[] = "Arial";
63 #endif 63 #endif
64 64
65 static SkPaint* text_paint = NULL; 65 static SkPaint* text_paint = NULL;
66 if (!text_paint) { 66 if (!text_paint) {
67 text_paint = new SkPaint; 67 text_paint = new SkPaint;
68 text_paint->setAntiAlias(true); 68 text_paint->setAntiAlias(true);
69 text_paint->setTextAlign(SkPaint::kLeft_Align); 69 text_paint->setTextAlign(SkPaint::kLeft_Align);
70 70
71 SkTypeface* typeface = SkTypeface::CreateFromName( 71 skia::RefPtr<SkTypeface> typeface = skia::AdoptRef(
72 kPreferredTypeface, SkTypeface::kBold); 72 SkTypeface::CreateFromName(kPreferredTypeface, SkTypeface::kBold));
73 // Skia doesn't do any font fallback---if the user is missing the font then 73 // Skia doesn't do any font fallback---if the user is missing the font then
74 // typeface will be NULL. If we don't do manual fallback then we'll crash. 74 // typeface will be NULL. If we don't do manual fallback then we'll crash.
75 if (typeface) { 75 if (typeface) {
76 text_paint->setFakeBoldText(true); 76 text_paint->setFakeBoldText(true);
77 } else { 77 } else {
78 // Fall back to the system font. We don't bold it because we aren't sure 78 // Fall back to the system font. We don't bold it because we aren't sure
79 // how it will look. 79 // how it will look.
80 // For the most part this code path will only be hit on Linux systems 80 // For the most part this code path will only be hit on Linux systems
81 // that don't have Arial. 81 // that don't have Arial.
82 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 82 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
83 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); 83 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
84 typeface = SkTypeface::CreateFromName( 84 typeface = skia::AdoptRef(SkTypeface::CreateFromName(
85 base_font.GetFontName().c_str(), SkTypeface::kNormal); 85 base_font.GetFontName().c_str(), SkTypeface::kNormal));
86 DCHECK(typeface); 86 DCHECK(typeface);
87 } 87 }
88 88
89 text_paint->setTypeface(typeface); 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 typeface->unref();
92 } 91 }
93 return text_paint; 92 return text_paint;
94 } 93 }
95 94
96 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon, 95 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon,
97 float font_size, 96 float font_size,
98 const string16& text, 97 const string16& text,
99 const string16& fallback) { 98 const string16& fallback) {
100 const int kMinPadding = 1; 99 const int kMinPadding = 1;
101 100
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 canvas->sk_canvas()->drawText( 220 canvas->sk_canvas()->drawText(
222 text.c_str(), text.size(), 221 text.c_str(), text.size(),
223 SkFloatToScalar(rect.x() + 222 SkFloatToScalar(rect.x() +
224 static_cast<float>(rect.width() - text_width) / 2), 223 static_cast<float>(rect.width() - text_width) / 2),
225 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding), 224 SkFloatToScalar(rect.y() + kTextSize + kTopTextPadding),
226 *text_paint); 225 *text_paint);
227 canvas->Restore(); 226 canvas->Restore();
228 } 227 }
229 228
230 } // namespace badge_util 229 } // namespace badge_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/theme_helpers.cc ('k') | chrome/renderer/chrome_render_view_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698