OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_GFX_PLATFORM_FONT_GTK_ | |
6 #define UI_GFX_PLATFORM_FONT_GTK_ | |
7 #pragma once | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "third_party/skia/include/core/SkRefCnt.h" | |
11 #include "ui/gfx/platform_font.h" | |
12 | |
13 class SkTypeface; | |
14 class SkPaint; | |
15 | |
16 namespace gfx { | |
17 | |
18 class UI_EXPORT PlatformFontGtk : public PlatformFont { | |
19 public: | |
20 PlatformFontGtk(); | |
21 explicit PlatformFontGtk(const Font& other); | |
22 explicit PlatformFontGtk(NativeFont native_font); | |
23 PlatformFontGtk(const string16& font_name, | |
24 int font_size); | |
25 | |
26 // Converts |gfx_font| to a new pango font. Free the returned font with | |
27 // pango_font_description_free(). | |
28 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font); | |
29 | |
30 // Resets and reloads the cached system font used by the default constructor. | |
31 // This function is useful when the system font has changed, for example, when | |
32 // the locale has changed. | |
33 static void ReloadDefaultFont(); | |
34 | |
35 // Position as an offset from the height of the drawn text, used to draw | |
36 // an underline. This is a negative number, so the underline would be | |
37 // drawn at y + height + underline_position; | |
38 double underline_position() const; | |
39 // The thickness to draw the underline. | |
40 double underline_thickness() const; | |
41 | |
42 // Overridden from PlatformFont: | |
43 virtual Font DeriveFont(int size_delta, int style) const; | |
44 virtual int GetHeight() const; | |
45 virtual int GetBaseline() const; | |
46 virtual int GetAverageCharacterWidth() const; | |
47 virtual int GetStringWidth(const string16& text) const; | |
48 virtual int GetExpectedTextWidth(int length) const; | |
49 virtual int GetStyle() const; | |
50 virtual string16 GetFontName() const; | |
51 virtual int GetFontSize() const; | |
52 virtual NativeFont GetNativeFont() const; | |
53 | |
54 private: | |
55 // Create a new instance of this object with the specified properties. Called | |
56 // from DeriveFont. | |
57 PlatformFontGtk(SkTypeface* typeface, | |
58 const string16& name, | |
59 int size, | |
60 int style); | |
61 virtual ~PlatformFontGtk(); | |
62 | |
63 // Initialize this object. | |
64 void InitWithNameAndSize(const string16& font_name, int font_size); | |
65 void InitWithTypefaceNameSizeAndStyle(SkTypeface* typeface, | |
66 const string16& name, | |
67 int size, | |
68 int style); | |
69 void InitFromPlatformFont(const PlatformFontGtk* other); | |
70 | |
71 // Potentially slow call to get pango metrics (average width, underline info). | |
72 void InitPangoMetrics(); | |
73 | |
74 // Setup a Skia context to use the current typeface | |
75 void PaintSetup(SkPaint* paint) const; | |
76 | |
77 // Make |this| a copy of |other|. | |
78 void CopyFont(const Font& other); | |
79 | |
80 // The average width of a character, initialized and cached if needed. | |
81 double GetAverageWidth() const; | |
82 | |
83 // These two both point to the same SkTypeface. We use the SkAutoUnref to | |
84 // handle the reference counting, but without @typeface_ we would have to | |
85 // cast the SkRefCnt from @typeface_helper_ every time. | |
86 scoped_ptr<SkAutoUnref> typeface_helper_; | |
87 SkTypeface *typeface_; | |
88 | |
89 // Additional information about the face | |
90 // Skia actually expects a family name and not a font name. | |
91 string16 font_family_; | |
92 int font_size_pixels_; | |
93 int style_; | |
94 | |
95 // Cached metrics, generated at construction | |
96 int height_pixels_; | |
97 int ascent_pixels_; | |
98 | |
99 // The pango metrics are much more expensive so we wait until we need them | |
100 // to compute them. | |
101 bool pango_metrics_inited_; | |
102 double average_width_pixels_; | |
103 double underline_position_pixels_; | |
104 double underline_thickness_pixels_; | |
105 | |
106 // The default font, used for the default constructor. | |
107 static Font* default_font_; | |
108 }; | |
109 | |
110 } // namespace gfx | |
111 | |
112 #endif // UI_GFX_PLATFORM_FONT_GTK_ | |
OLD | NEW |