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