| OLD | NEW |
| 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_LINUX_H_ | 5 #ifndef UI_GFX_PLATFORM_FONT_LINUX_H_ |
| 6 #define UI_GFX_PLATFORM_FONT_LINUX_H_ | 6 #define UI_GFX_PLATFORM_FONT_LINUX_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "third_party/skia/include/core/SkRefCnt.h" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
| 15 #include "ui/gfx/font_render_params.h" | 15 #include "ui/gfx/font_render_params.h" |
| 16 #include "ui/gfx/platform_font.h" | 16 #include "ui/gfx/platform_font.h" |
| 17 | 17 |
| 18 class SkTypeface; | 18 class SkTypeface; |
| 19 class SkPaint; | 19 class SkPaint; |
| 20 | 20 |
| 21 namespace gfx { | 21 namespace gfx { |
| 22 | 22 |
| 23 class GFX_EXPORT PlatformFontLinux : public PlatformFont { | 23 class GFX_EXPORT PlatformFontLinux : public PlatformFont { |
| 24 public: | 24 public: |
| 25 // TODO(derat): Get rid of the default constructor in favor of using | 25 // TODO(derat): Get rid of the default constructor in favor of using |
| 26 // gfx::FontList (which also has the concept of a default font but may contain | 26 // FontList (which also has the concept of a default font but may contain |
| 27 // multiple font families) everywhere. See http://crbug.com/398885#c16. | 27 // multiple font families) everywhere. See http://crbug.com/398885#c16. |
| 28 PlatformFontLinux(); | 28 PlatformFontLinux(); |
| 29 PlatformFontLinux(const std::string& font_name, int font_size_pixels); | 29 PlatformFontLinux(const std::string& font_name, int font_size_pixels); |
| 30 | 30 |
| 31 // Resets and reloads the cached system font used by the default constructor. | 31 // 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 | 32 // This function is useful when the system font has changed, for example, when |
| 33 // the locale has changed. | 33 // the locale has changed. |
| 34 static void ReloadDefaultFont(); | 34 static void ReloadDefaultFont(); |
| 35 | 35 |
| 36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 37 // Sets the default font. |font_description| is a gfx::FontList font | 37 // Sets the default font. |font_description| is a FontList font description; |
| 38 // description; only the first family will be used. | 38 // only the first family will be used. |
| 39 static void SetDefaultFontDescription(const std::string& font_description); | 39 static void SetDefaultFontDescription(const std::string& font_description); |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 // Overridden from PlatformFont: | 42 // Overridden from PlatformFont: |
| 43 Font DeriveFont(int size_delta, int style) const override; | 43 Font DeriveFont(int size_delta, |
| 44 int style, |
| 45 Font::Weight weight) const override; |
| 44 int GetHeight() override; | 46 int GetHeight() override; |
| 47 Font::Weight GetWeight() const override; |
| 45 int GetBaseline() override; | 48 int GetBaseline() override; |
| 46 int GetCapHeight() override; | 49 int GetCapHeight() override; |
| 47 int GetExpectedTextWidth(int length) override; | 50 int GetExpectedTextWidth(int length) override; |
| 48 int GetStyle() const override; | 51 int GetStyle() const override; |
| 49 const std::string& GetFontName() const override; | 52 const std::string& GetFontName() const override; |
| 50 std::string GetActualFontNameForTesting() const override; | 53 std::string GetActualFontNameForTesting() const override; |
| 51 int GetFontSize() const override; | 54 int GetFontSize() const override; |
| 52 const FontRenderParams& GetFontRenderParams() override; | 55 const FontRenderParams& GetFontRenderParams() override; |
| 53 | 56 |
| 54 private: | 57 private: |
| 55 // Create a new instance of this object with the specified properties. Called | 58 // Create a new instance of this object with the specified properties. Called |
| 56 // from DeriveFont. | 59 // from DeriveFont. |
| 57 PlatformFontLinux(sk_sp<SkTypeface> typeface, | 60 PlatformFontLinux(sk_sp<SkTypeface> typeface, |
| 58 const std::string& family, | 61 const std::string& family, |
| 59 int size_pixels, | 62 int size_pixels, |
| 60 int style, | 63 bool italic, |
| 64 Font::Weight weight, |
| 61 const FontRenderParams& params); | 65 const FontRenderParams& params); |
| 62 ~PlatformFontLinux() override; | 66 ~PlatformFontLinux() override; |
| 63 | 67 |
| 64 // Initializes this object based on the passed-in details. If |typeface| is | 68 // Initializes this object based on the passed-in details. If |typeface| is |
| 65 // empty, a new typeface will be loaded. | 69 // empty, a new typeface will be loaded. |
| 66 void InitFromDetails( | 70 void InitFromDetails( |
| 67 sk_sp<SkTypeface> typeface, | 71 sk_sp<SkTypeface> typeface, |
| 68 const std::string& font_family, | 72 const std::string& font_family, |
| 69 int font_size_pixels, | 73 int font_size_pixels, |
| 70 int style, | 74 bool italic, |
| 75 Font::Weight weight, |
| 71 const FontRenderParams& params); | 76 const FontRenderParams& params); |
| 72 | 77 |
| 73 // Initializes this object as a copy of another PlatformFontLinux. | 78 // Initializes this object as a copy of another PlatformFontLinux. |
| 74 void InitFromPlatformFont(const PlatformFontLinux* other); | 79 void InitFromPlatformFont(const PlatformFontLinux* other); |
| 75 | 80 |
| 76 // Computes the metrics if they have not yet been computed. | 81 // Computes the metrics if they have not yet been computed. |
| 77 void ComputeMetricsIfNecessary(); | 82 void ComputeMetricsIfNecessary(); |
| 78 | 83 |
| 79 sk_sp<SkTypeface> typeface_; | 84 sk_sp<SkTypeface> typeface_; |
| 80 | 85 |
| 81 // Additional information about the face. | 86 // Additional information about the face. |
| 82 // Skia actually expects a family name and not a font name. | 87 // Skia actually expects a family name and not a font name. |
| 83 std::string font_family_; | 88 std::string font_family_; |
| 84 int font_size_pixels_; | 89 int font_size_pixels_; |
| 85 int style_; | 90 bool italic_; |
| 86 float device_scale_factor_; | 91 float device_scale_factor_; |
| 87 | 92 |
| 88 // Information describing how the font should be rendered. | 93 // Information describing how the font should be rendered. |
| 89 FontRenderParams font_render_params_; | 94 FontRenderParams font_render_params_; |
| 90 | 95 |
| 91 // Cached metrics, generated on demand. | 96 // Cached metrics, generated on demand. |
| 92 bool metrics_need_computation_ = true; | 97 bool metrics_need_computation_ = true; |
| 93 int ascent_pixels_; | 98 int ascent_pixels_; |
| 94 int height_pixels_; | 99 int height_pixels_; |
| 95 int cap_height_pixels_; | 100 int cap_height_pixels_; |
| 96 double average_width_pixels_; | 101 double average_width_pixels_; |
| 102 Font::Weight weight_; |
| 97 | 103 |
| 98 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) |
| 99 // A font description string of the format used by gfx::FontList. | 105 // A font description string of the format used by FontList. |
| 100 static std::string* default_font_description_; | 106 static std::string* default_font_description_; |
| 101 #endif | 107 #endif |
| 102 | 108 |
| 103 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux); | 109 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux); |
| 104 }; | 110 }; |
| 105 | 111 |
| 106 } // namespace gfx | 112 } // namespace gfx |
| 107 | 113 |
| 108 #endif // UI_GFX_PLATFORM_FONT_LINUX_H_ | 114 #endif // UI_GFX_PLATFORM_FONT_LINUX_H_ |
| OLD | NEW |