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

Side by Side Diff: ui/gfx/platform_font_pango.h

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 #ifndef UI_GFX_PLATFORM_FONT_PANGO_H_ 5 #ifndef UI_GFX_PLATFORM_FONT_PANGO_H_
6 #define UI_GFX_PLATFORM_FONT_PANGO_H_ 6 #define UI_GFX_PLATFORM_FONT_PANGO_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "skia/ext/refptr.h"
10 #include "third_party/skia/include/core/SkRefCnt.h" 11 #include "third_party/skia/include/core/SkRefCnt.h"
11 #include "ui/gfx/platform_font.h" 12 #include "ui/gfx/platform_font.h"
12 13
13 class SkTypeface; 14 class SkTypeface;
14 class SkPaint; 15 class SkPaint;
15 16
16 namespace gfx { 17 namespace gfx {
17 18
18 class UI_EXPORT PlatformFontPango : public PlatformFont { 19 class UI_EXPORT PlatformFontPango : public PlatformFont {
19 public: 20 public:
(...skipping 25 matching lines...) Expand all
45 virtual int GetStringWidth(const string16& text) const OVERRIDE; 46 virtual int GetStringWidth(const string16& text) const OVERRIDE;
46 virtual int GetExpectedTextWidth(int length) const OVERRIDE; 47 virtual int GetExpectedTextWidth(int length) const OVERRIDE;
47 virtual int GetStyle() const OVERRIDE; 48 virtual int GetStyle() const OVERRIDE;
48 virtual std::string GetFontName() const OVERRIDE; 49 virtual std::string GetFontName() const OVERRIDE;
49 virtual int GetFontSize() const OVERRIDE; 50 virtual int GetFontSize() const OVERRIDE;
50 virtual NativeFont GetNativeFont() const OVERRIDE; 51 virtual NativeFont GetNativeFont() const OVERRIDE;
51 52
52 private: 53 private:
53 // Create a new instance of this object with the specified properties. Called 54 // Create a new instance of this object with the specified properties. Called
54 // from DeriveFont. 55 // from DeriveFont.
55 PlatformFontPango(SkTypeface* typeface, 56 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
56 const std::string& name, 57 const std::string& name,
57 int size, 58 int size,
58 int style); 59 int style);
59 virtual ~PlatformFontPango(); 60 virtual ~PlatformFontPango();
60 61
61 // Initialize this object. 62 // Initialize this object.
62 void InitWithNameAndSize(const std::string& font_name, int font_size); 63 void InitWithNameAndSize(const std::string& font_name, int font_size);
63 void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface, 64 void InitWithTypefaceNameSizeAndStyle(
64 const std::string& name, 65 const skia::RefPtr<SkTypeface>& typeface,
65 int size, 66 const std::string& name,
66 int style); 67 int size,
68 int style);
67 void InitFromPlatformFont(const PlatformFontPango* other); 69 void InitFromPlatformFont(const PlatformFontPango* other);
68 70
69 // Potentially slow call to get pango metrics (average width, underline info). 71 // Potentially slow call to get pango metrics (average width, underline info).
70 void InitPangoMetrics(); 72 void InitPangoMetrics();
71 73
72 // Setup a Skia context to use the current typeface. 74 // Setup a Skia context to use the current typeface.
73 void PaintSetup(SkPaint* paint) const; 75 void PaintSetup(SkPaint* paint) const;
74 76
75 // Make |this| a copy of |other|. 77 // Make |this| a copy of |other|.
76 void CopyFont(const Font& other); 78 void CopyFont(const Font& other);
77 79
78 // The average width of a character, initialized and cached if needed. 80 // The average width of a character, initialized and cached if needed.
79 double GetAverageWidth() const; 81 double GetAverageWidth() const;
80 82
81 // These two both point to the same SkTypeface. We use the SkAutoUnref to 83 skia::RefPtr<SkTypeface> typeface_;
82 // handle the reference counting, but without @typeface_ we would have to
83 // cast the SkRefCnt from @typeface_helper_ every time.
84 scoped_ptr<SkAutoUnref> typeface_helper_;
85 SkTypeface* typeface_;
86 84
87 // Additional information about the face 85 // Additional information about the face
88 // Skia actually expects a family name and not a font name. 86 // Skia actually expects a family name and not a font name.
89 std::string font_family_; 87 std::string font_family_;
90 int font_size_pixels_; 88 int font_size_pixels_;
91 int style_; 89 int style_;
92 90
93 // Cached metrics, generated at construction. 91 // Cached metrics, generated at construction.
94 int height_pixels_; 92 int height_pixels_;
95 int ascent_pixels_; 93 int ascent_pixels_;
96 94
97 // The pango metrics are much more expensive so we wait until we need them 95 // The pango metrics are much more expensive so we wait until we need them
98 // to compute them. 96 // to compute them.
99 bool pango_metrics_inited_; 97 bool pango_metrics_inited_;
100 double average_width_pixels_; 98 double average_width_pixels_;
101 double underline_position_pixels_; 99 double underline_position_pixels_;
102 double underline_thickness_pixels_; 100 double underline_thickness_pixels_;
103 101
104 // The default font, used for the default constructor. 102 // The default font, used for the default constructor.
105 static Font* default_font_; 103 static Font* default_font_;
106 104
107 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango); 105 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango);
108 }; 106 };
109 107
110 } // namespace gfx 108 } // namespace gfx
111 109
112 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_ 110 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698