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

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

Issue 382273002: ui/gfx: Allow for font-specific rendering settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix fontconfig leak Created 6 years, 5 months 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
« no previous file with comments | « ui/gfx/platform_font_mac.mm ('k') | ui/gfx/platform_font_pango.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "skia/ext/refptr.h" 12 #include "skia/ext/refptr.h"
13 #include "third_party/skia/include/core/SkRefCnt.h" 13 #include "third_party/skia/include/core/SkRefCnt.h"
14 #include "ui/gfx/font_render_params.h"
14 #include "ui/gfx/platform_font.h" 15 #include "ui/gfx/platform_font.h"
15 16
16 class SkTypeface; 17 class SkTypeface;
17 class SkPaint; 18 class SkPaint;
18 19
19 namespace gfx { 20 namespace gfx {
20 21
21 class GFX_EXPORT PlatformFontPango : public PlatformFont { 22 class GFX_EXPORT PlatformFontPango : public PlatformFont {
22 public: 23 public:
23 PlatformFontPango(); 24 PlatformFontPango();
24 explicit PlatformFontPango(NativeFont native_font); 25 explicit PlatformFontPango(NativeFont native_font);
25 PlatformFontPango(const std::string& font_name, int font_size); 26 PlatformFontPango(const std::string& font_name, int font_size_pixels);
26 27
27 // Converts |gfx_font| to a new pango font. Free the returned font with 28 // Converts |gfx_font| to a new pango font. Free the returned font with
28 // pango_font_description_free(). 29 // pango_font_description_free().
29 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); 30 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
30 31
31 // Resets and reloads the cached system font used by the default constructor. 32 // Resets and reloads the cached system font used by the default constructor.
32 // This function is useful when the system font has changed, for example, when 33 // This function is useful when the system font has changed, for example, when
33 // the locale has changed. 34 // the locale has changed.
34 static void ReloadDefaultFont(); 35 static void ReloadDefaultFont();
35 36
(...skipping 12 matching lines...) Expand all
48 // Overridden from PlatformFont: 49 // Overridden from PlatformFont:
49 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE; 50 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE;
50 virtual int GetHeight() const OVERRIDE; 51 virtual int GetHeight() const OVERRIDE;
51 virtual int GetBaseline() const OVERRIDE; 52 virtual int GetBaseline() const OVERRIDE;
52 virtual int GetCapHeight() const OVERRIDE; 53 virtual int GetCapHeight() const OVERRIDE;
53 virtual int GetExpectedTextWidth(int length) const OVERRIDE; 54 virtual int GetExpectedTextWidth(int length) const OVERRIDE;
54 virtual int GetStyle() const OVERRIDE; 55 virtual int GetStyle() const OVERRIDE;
55 virtual std::string GetFontName() const OVERRIDE; 56 virtual std::string GetFontName() const OVERRIDE;
56 virtual std::string GetActualFontNameForTesting() const OVERRIDE; 57 virtual std::string GetActualFontNameForTesting() const OVERRIDE;
57 virtual int GetFontSize() const OVERRIDE; 58 virtual int GetFontSize() const OVERRIDE;
59 virtual const FontRenderParams& GetFontRenderParams() const OVERRIDE;
58 virtual NativeFont GetNativeFont() const OVERRIDE; 60 virtual NativeFont GetNativeFont() const OVERRIDE;
59 61
60 private: 62 private:
61 // Create a new instance of this object with the specified properties. Called 63 // Create a new instance of this object with the specified properties. Called
62 // from DeriveFont. 64 // from DeriveFont.
63 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface, 65 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
64 const std::string& name, 66 const std::string& name,
65 int size, 67 int size_pixels,
66 int style); 68 int style,
69 const FontRenderParams& params);
67 virtual ~PlatformFontPango(); 70 virtual ~PlatformFontPango();
68 71
69 // Initializes this object based on the passed-in details. If |typeface| is 72 // Initializes this object based on the passed-in details. If |typeface| is
70 // empty, a new typeface will be loaded. 73 // empty, a new typeface will be loaded.
71 void InitFromDetails( 74 void InitFromDetails(
72 const skia::RefPtr<SkTypeface>& typeface, 75 const skia::RefPtr<SkTypeface>& typeface,
73 const std::string& font_family, 76 const std::string& font_family,
74 int font_size, 77 int font_size_pixels,
75 int style); 78 int style,
79 const FontRenderParams& params);
76 80
77 // Initializes this object as a copy of another PlatformFontPango. 81 // Initializes this object as a copy of another PlatformFontPango.
78 void InitFromPlatformFont(const PlatformFontPango* other); 82 void InitFromPlatformFont(const PlatformFontPango* other);
79 83
80 // Potentially slow call to get pango metrics (average width, underline info). 84 // Potentially slow call to get pango metrics (average width, underline info).
81 void InitPangoMetrics(); 85 void InitPangoMetrics();
82 86
83 // Setup a Skia context to use the current typeface. 87 // Setup a Skia context to use the current typeface.
84 void PaintSetup(SkPaint* paint) const; 88 void PaintSetup(SkPaint* paint) const;
85 89
86 // Make |this| a copy of |other|. 90 // Make |this| a copy of |other|.
87 void CopyFont(const Font& other); 91 void CopyFont(const Font& other);
88 92
89 // The average width of a character, initialized and cached if needed. 93 // The average width of a character, initialized and cached if needed.
90 double GetAverageWidth() const; 94 double GetAverageWidth() const;
91 95
92 skia::RefPtr<SkTypeface> typeface_; 96 skia::RefPtr<SkTypeface> typeface_;
93 97
94 // Additional information about the face 98 // Additional information about the face.
95 // Skia actually expects a family name and not a font name. 99 // Skia actually expects a family name and not a font name.
96 std::string font_family_; 100 std::string font_family_;
97 int font_size_pixels_; 101 int font_size_pixels_;
98 int style_; 102 int style_;
99 103
104 // Information describing how the font should be rendered.
105 FontRenderParams font_render_params_;
106
100 // Cached metrics, generated at construction. 107 // Cached metrics, generated at construction.
101 int ascent_pixels_; 108 int ascent_pixels_;
102 int height_pixels_; 109 int height_pixels_;
103 int cap_height_pixels_; 110 int cap_height_pixels_;
104 111
105 // The pango metrics are much more expensive so we wait until we need them 112 // The pango metrics are much more expensive so we wait until we need them
106 // to compute them. 113 // to compute them.
107 bool pango_metrics_inited_; 114 bool pango_metrics_inited_;
108 double average_width_pixels_; 115 double average_width_pixels_;
109 double underline_position_pixels_; 116 double underline_position_pixels_;
110 double underline_thickness_pixels_; 117 double underline_thickness_pixels_;
111 118
112 // The default font, used for the default constructor. 119 // The default font, used for the default constructor.
113 static Font* default_font_; 120 static Font* default_font_;
114 121
115 #if defined(OS_CHROMEOS) 122 #if defined(OS_CHROMEOS)
116 static std::string* default_font_description_; 123 static std::string* default_font_description_;
117 #endif 124 #endif
118 125
119 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango); 126 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango);
120 }; 127 };
121 128
122 } // namespace gfx 129 } // namespace gfx
123 130
124 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_ 131 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_
OLDNEW
« no previous file with comments | « ui/gfx/platform_font_mac.mm ('k') | ui/gfx/platform_font_pango.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698