[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 | |
[email protected] | c8703bb | 2011-10-19 14:35:15 | [diff] [blame] | 5 | #ifndef UI_GFX_PLATFORM_FONT_PANGO_H_ |
| 6 | #define UI_GFX_PLATFORM_FONT_PANGO_H_ |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 7 | |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | c9243403 | 2011-11-15 23:42:50 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | 3699ae5 | 2012-12-05 01:00:54 | [diff] [blame] | 12 | #include "skia/ext/refptr.h" |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 13 | #include "third_party/skia/include/core/SkRefCnt.h" |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 14 | #include "ui/gfx/font_render_params.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 15 | #include "ui/gfx/platform_font.h" |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 16 | |
| 17 | class SkTypeface; |
| 18 | class SkPaint; |
| 19 | |
| 20 | namespace gfx { |
| 21 | |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame^] | 22 | // TODO(derat): Rename this to PlatformFontLinux. |
[email protected] | 4ffa789 | 2013-09-27 16:56:06 | [diff] [blame] | 23 | class GFX_EXPORT PlatformFontPango : 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 |
| 26 | // gfx::FontList (which also has the concept of a default font but may contain |
| 27 | // multiple font families) everywhere. See http://crbug.com/398885#c16. |
[email protected] | b6bb36e2 | 2011-09-21 17:52:54 | [diff] [blame] | 28 | PlatformFontPango(); |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 29 | PlatformFontPango(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) |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame^] | 37 | // Sets the default font. |font_description| is a gfx::FontList font |
| 38 | // description; 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: |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 43 | Font DeriveFont(int size_delta, int style) const override; |
| 44 | int GetHeight() const override; |
| 45 | int GetBaseline() const override; |
| 46 | int GetCapHeight() const override; |
| 47 | int GetExpectedTextWidth(int length) const override; |
| 48 | int GetStyle() const override; |
| 49 | std::string GetFontName() const override; |
| 50 | std::string GetActualFontNameForTesting() const override; |
| 51 | int GetFontSize() const override; |
mukai | 5dad2e7 | 2014-12-16 00:00:30 | [diff] [blame] | 52 | const FontRenderParams& GetFontRenderParams() override; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | // Create a new instance of this object with the specified properties. Called |
| 56 | // from DeriveFont. |
[email protected] | 3699ae5 | 2012-12-05 01:00:54 | [diff] [blame] | 57 | PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface, |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame^] | 58 | const std::string& family, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 59 | int size_pixels, |
| 60 | int style, |
| 61 | const FontRenderParams& params); |
dcheng | bc07fa0 | 2014-10-29 20:07:24 | [diff] [blame] | 62 | ~PlatformFontPango() override; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 63 | |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 64 | // Initializes this object based on the passed-in details. If |typeface| is |
| 65 | // empty, a new typeface will be loaded. |
| 66 | void InitFromDetails( |
[email protected] | 3699ae5 | 2012-12-05 01:00:54 | [diff] [blame] | 67 | const skia::RefPtr<SkTypeface>& typeface, |
[email protected] | 2fb2657 | 2013-12-11 08:43:06 | [diff] [blame] | 68 | const std::string& font_family, |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 69 | int font_size_pixels, |
| 70 | int style, |
| 71 | const FontRenderParams& params); |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 72 | |
| 73 | // Initializes this object as a copy of another PlatformFontPango. |
[email protected] | b6bb36e2 | 2011-09-21 17:52:54 | [diff] [blame] | 74 | void InitFromPlatformFont(const PlatformFontPango* other); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 75 | |
[email protected] | 3699ae5 | 2012-12-05 01:00:54 | [diff] [blame] | 76 | skia::RefPtr<SkTypeface> typeface_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 77 | |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 78 | // Additional information about the face. |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 79 | // Skia actually expects a family name and not a font name. |
[email protected] | 610ae5f | 2011-10-27 23:55:37 | [diff] [blame] | 80 | std::string font_family_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 81 | int font_size_pixels_; |
| 82 | int style_; |
mukai | 5dad2e7 | 2014-12-16 00:00:30 | [diff] [blame] | 83 | #if defined(OS_CHROMEOS) |
| 84 | float device_scale_factor_; |
| 85 | #endif |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 86 | |
[email protected] | 1e8f699b | 2014-07-14 19:40:55 | [diff] [blame] | 87 | // Information describing how the font should be rendered. |
| 88 | FontRenderParams font_render_params_; |
| 89 | |
[email protected] | 354ee47 | 2012-08-30 21:08:15 | [diff] [blame] | 90 | // Cached metrics, generated at construction. |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 91 | int ascent_pixels_; |
[email protected] | d90c0cd | 2014-07-08 02:31:34 | [diff] [blame] | 92 | int height_pixels_; |
[email protected] | 0fbd8de | 2013-12-24 15:18:55 | [diff] [blame] | 93 | int cap_height_pixels_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 94 | double average_width_pixels_; |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 95 | |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 96 | #if defined(OS_CHROMEOS) |
Daniel Erat | cb2db9b | 2015-02-11 15:15:09 | [diff] [blame^] | 97 | // A font description string of the format used by gfx::FontList. |
[email protected] | c96388356 | 2013-09-18 08:15:22 | [diff] [blame] | 98 | static std::string* default_font_description_; |
| 99 | #endif |
| 100 | |
[email protected] | 354ee47 | 2012-08-30 21:08:15 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(PlatformFontPango); |
[email protected] | 267c03d | 2011-02-02 23:03:07 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace gfx |
| 105 | |
[email protected] | c8703bb | 2011-10-19 14:35:15 | [diff] [blame] | 106 | #endif // UI_GFX_PLATFORM_FONT_PANGO_H_ |