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

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

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop TNoRef 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 "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 10 matching lines...) Expand all
21 #else 21 #else
22 const char kPreferredTypeface[] = "Arial"; 22 const char kPreferredTypeface[] = "Arial";
23 #endif 23 #endif
24 24
25 static SkPaint* text_paint = NULL; 25 static SkPaint* text_paint = NULL;
26 if (!text_paint) { 26 if (!text_paint) {
27 text_paint = new SkPaint; 27 text_paint = new SkPaint;
28 text_paint->setAntiAlias(true); 28 text_paint->setAntiAlias(true);
29 text_paint->setTextAlign(SkPaint::kLeft_Align); 29 text_paint->setTextAlign(SkPaint::kLeft_Align);
30 30
31 SkTypeface* typeface = SkTypeface::CreateFromName( 31 skia::RefPtr<SkTypeface> typeface = SkTypeface::CreateFromName(
32 kPreferredTypeface, SkTypeface::kBold); 32 kPreferredTypeface, SkTypeface::kBold);
33 // Skia doesn't do any font fallback---if the user is missing the font then 33 // Skia doesn't do any font fallback---if the user is missing the font then
34 // typeface will be NULL. If we don't do manual fallback then we'll crash. 34 // typeface will be NULL. If we don't do manual fallback then we'll crash.
35 if (typeface) { 35 if (typeface) {
36 text_paint->setFakeBoldText(true); 36 text_paint->setFakeBoldText(true);
37 } else { 37 } else {
38 // Fall back to the system font. We don't bold it because we aren't sure 38 // Fall back to the system font. We don't bold it because we aren't sure
39 // how it will look. 39 // how it will look.
40 // For the most part this code path will only be hit on Linux systems 40 // For the most part this code path will only be hit on Linux systems
41 // that don't have Arial. 41 // that don't have Arial.
42 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 42 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
43 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); 43 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
44 typeface = SkTypeface::CreateFromName( 44 typeface = SkTypeface::CreateFromName(
45 base_font.GetFontName().c_str(), SkTypeface::kNormal); 45 base_font.GetFontName().c_str(), SkTypeface::kNormal);
46 DCHECK(typeface); 46 DCHECK(typeface);
47 } 47 }
48 48
49 text_paint->setTypeface(typeface); 49 text_paint->setTypeface(typeface.get());
50 // |text_paint| adds its own ref. Release the ref from CreateFontName. 50 // |text_paint| adds its own ref. Release the ref from CreateFontName.
51 typeface->unref();
52 } 51 }
53 return text_paint; 52 return text_paint;
54 } 53 }
55 54
56 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon, 55 SkBitmap DrawBadgeIconOverlay(const SkBitmap& icon,
57 float font_size, 56 float font_size,
58 const string16& text, 57 const string16& text,
59 const string16& fallback) { 58 const string16& fallback) {
60 const int kMinPadding = 1; 59 const int kMinPadding = 1;
61 60
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 SkScalar x = (badge_width - text_width)/2; 93 SkScalar x = (badge_width - text_width)/2;
95 SkScalar y = (icon.height() - font_size)/2 + font_size - 1; 94 SkScalar y = (icon.height() - font_size)/2 + font_size - 1;
96 canvas->sk_canvas()->drawText( 95 canvas->sk_canvas()->drawText(
97 badge_text.c_str(), badge_text.size(), x, y, *paint); 96 badge_text.c_str(), badge_text.size(), x, y, *paint);
98 97
99 // Return the generated image. 98 // Return the generated image.
100 return canvas->ExtractImageRep().sk_bitmap(); 99 return canvas->ExtractImageRep().sk_bitmap();
101 } 100 }
102 101
103 } // namespace badge_util 102 } // namespace badge_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698