[email protected] | 7c61375 | 2012-01-24 21:08:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 5 | #ifndef UI_GFX_PLATFORM_FONT_LINUX_H_ |
| 6 | #define UI_GFX_PLATFORM_FONT_LINUX_H_ |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 7 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8 | #include <memory> |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | c9243403 | 2011-11-15 23:42:50 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
avi | c89eb8d4 | 2015-12-23 08:08:18 | [diff] [blame] | 12 | #include "base/macros.h" |
avi | c89eb8d4 | 2015-12-23 08:08:18 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 14 | #include "third_party/skia/include/core/SkRefCnt.h" |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 15 | #include "ui/gfx/font_render_params.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 16 | #include "ui/gfx/platform_font.h" |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 17 | |
| 18 | class SkTypeface; |
| 19 | class SkPaint; |
| 20 | |
| 21 | namespace gfx { |
| 22 | |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 23 | class GFX_EXPORT PlatformFontLinux : public PlatformFont { |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 24 | public: |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame] | 25 | // TODO(derat): Get rid of the default constructor in favor of using |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 26 | // FontList (which also has the concept of a default font but may contain |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame] | 27 | // multiple font families) everywhere. See http://crbug.com/398885#c16. |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 28 | PlatformFontLinux(); |
| 29 | PlatformFontLinux(const std::string& font_name, int font_size_pixels); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 30 | |
[email protected] | 28e466c | 2011-04-06 05:01:20 | [diff] [blame] | 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 |
| 33 | // the locale has changed. |
| 34 | static void ReloadDefaultFont(); |
| 35 | |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 36 | #if defined(OS_CHROMEOS) |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 37 | // Sets the default font. |font_description| is a FontList font description; |
| 38 | // only the first family will be used. |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 39 | static void SetDefaultFontDescription(const std::string& font_description); |
| 40 | #endif |
| 41 | |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 42 | // Overridden from PlatformFont: |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 43 | Font DeriveFont(int size_delta, |
| 44 | int style, |
| 45 | Font::Weight weight) const override; |
erikchen | 773b3a01 | 2016-01-07 22:03:50 | [diff] [blame] | 46 | int GetHeight() override; |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 47 | Font::Weight GetWeight() const override; |
erikchen | 773b3a01 | 2016-01-07 22:03:50 | [diff] [blame] | 48 | int GetBaseline() override; |
| 49 | int GetCapHeight() override; |
| 50 | int GetExpectedTextWidth(int length) override; |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 51 | int GetStyle() const override; |
erikchen | c1439a4 | 2015-12-09 00:25:55 | [diff] [blame] | 52 | const std::string& GetFontName() const override; |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 53 | std::string GetActualFontNameForTesting() const override; |
| 54 | int GetFontSize() const override; |
mukai | 5dad2e7 | 2014-12-16 00:00:30 | [diff] [blame] | 55 | const FontRenderParams& GetFontRenderParams() override; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | // Create a new instance of this object with the specified properties. Called |
| 59 | // from DeriveFont. |
tomhudson | 399950b | 2016-05-11 11:00:13 | [diff] [blame] | 60 | PlatformFontLinux(sk_sp<SkTypeface> typeface, |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame] | 61 | const std::string& family, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 62 | int size_pixels, |
mboc | fcf96463 | 2016-06-06 19:54:41 | [diff] [blame] | 63 | int style, |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 64 | Font::Weight weight, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 65 | const FontRenderParams& params); |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 66 | ~PlatformFontLinux() override; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 67 | |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 68 | // Initializes this object based on the passed-in details. If |typeface| is |
| 69 | // empty, a new typeface will be loaded. |
| 70 | void InitFromDetails( |
tomhudson | 399950b | 2016-05-11 11:00:13 | [diff] [blame] | 71 | sk_sp<SkTypeface> typeface, |
[email protected] | 2fb2657 | 2013-12-11 08:43:06 | [diff] [blame] | 72 | const std::string& font_family, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 73 | int font_size_pixels, |
mboc | fcf96463 | 2016-06-06 19:54:41 | [diff] [blame] | 74 | int style, |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 75 | Font::Weight weight, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 76 | const FontRenderParams& params); |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 77 | |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 78 | // Initializes this object as a copy of another PlatformFontLinux. |
| 79 | void InitFromPlatformFont(const PlatformFontLinux* other); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 80 | |
erikchen | 773b3a01 | 2016-01-07 22:03:50 | [diff] [blame] | 81 | // Computes the metrics if they have not yet been computed. |
| 82 | void ComputeMetricsIfNecessary(); |
| 83 | |
tomhudson | 399950b | 2016-05-11 11:00:13 | [diff] [blame] | 84 | sk_sp<SkTypeface> typeface_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 85 | |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 86 | // Additional information about the face. |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 87 | // Skia actually expects a family name and not a font name. |
[email protected] | 610ae5f | 2011-10-27 23:55:37 | [diff] [blame] | 88 | std::string font_family_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 89 | int font_size_pixels_; |
mboc | fcf96463 | 2016-06-06 19:54:41 | [diff] [blame] | 90 | int style_; |
mukai | 5dad2e7 | 2014-12-16 00:00:30 | [diff] [blame] | 91 | float device_scale_factor_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 92 | |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 93 | // Information describing how the font should be rendered. |
| 94 | FontRenderParams font_render_params_; |
| 95 | |
erikchen | 773b3a01 | 2016-01-07 22:03:50 | [diff] [blame] | 96 | // Cached metrics, generated on demand. |
| 97 | bool metrics_need_computation_ = true; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 98 | int ascent_pixels_; |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 99 | int height_pixels_; |
[email protected] | 0fbd8de | 2013-12-24 15:18:55 | [diff] [blame] | 100 | int cap_height_pixels_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 101 | double average_width_pixels_; |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 102 | Font::Weight weight_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 103 | |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 104 | #if defined(OS_CHROMEOS) |
mboc | 998e890 | 2016-06-02 11:40:35 | [diff] [blame] | 105 | // A font description string of the format used by FontList. |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 106 | static std::string* default_font_description_; |
| 107 | #endif |
| 108 | |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 109 | DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace gfx |
| 113 | |
derat | cd2d6fb | 2015-02-12 00:10:41 | [diff] [blame] | 114 | #endif // UI_GFX_PLATFORM_FONT_LINUX_H_ |