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