blob: 500cd48a8691a48678e29621aa33e0aa592f964e [file] [log] [blame]
[email protected]7c613752012-01-24 21:08:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]267c03d2011-02-02 23:03:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]c8703bb2011-10-19 14:35:155#ifndef UI_GFX_PLATFORM_FONT_PANGO_H_
6#define UI_GFX_PLATFORM_FONT_PANGO_H_
[email protected]267c03d2011-02-02 23:03:077
[email protected]c963883562013-09-18 08:15:228#include <string>
9
[email protected]c92434032011-11-15 23:42:5010#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
[email protected]3699ae52012-12-05 01:00:5412#include "skia/ext/refptr.h"
[email protected]267c03d2011-02-02 23:03:0713#include "third_party/skia/include/core/SkRefCnt.h"
[email protected]1e8f699b2014-07-14 19:40:5514#include "ui/gfx/font_render_params.h"
[email protected]08397d52011-02-05 01:53:3815#include "ui/gfx/platform_font.h"
[email protected]267c03d2011-02-02 23:03:0716
17class SkTypeface;
18class SkPaint;
19
20namespace gfx {
21
Daniel Eratcb2db9b2015-02-11 15:15:0922// TODO(derat): Rename this to PlatformFontLinux.
[email protected]4ffa7892013-09-27 16:56:0623class GFX_EXPORT PlatformFontPango : public PlatformFont {
[email protected]267c03d2011-02-02 23:03:0724 public:
Daniel Eratcb2db9b2015-02-11 15:15:0925 // 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]b6bb36e22011-09-21 17:52:5428 PlatformFontPango();
[email protected]1e8f699b2014-07-14 19:40:5529 PlatformFontPango(const std::string& font_name, int font_size_pixels);
[email protected]267c03d2011-02-02 23:03:0730
[email protected]28e466c2011-04-06 05:01:2031 // 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]c963883562013-09-18 08:15:2236#if defined(OS_CHROMEOS)
Daniel Eratcb2db9b2015-02-11 15:15:0937 // Sets the default font. |font_description| is a gfx::FontList font
38 // description; only the first family will be used.
[email protected]c963883562013-09-18 08:15:2239 static void SetDefaultFontDescription(const std::string& font_description);
40#endif
41
[email protected]267c03d2011-02-02 23:03:0742 // Overridden from PlatformFont:
dchengbc07fa02014-10-29 20:07:2443 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;
mukai5dad2e72014-12-16 00:00:3052 const FontRenderParams& GetFontRenderParams() override;
[email protected]267c03d2011-02-02 23:03:0753
54 private:
55 // Create a new instance of this object with the specified properties. Called
56 // from DeriveFont.
[email protected]3699ae52012-12-05 01:00:5457 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
Daniel Eratcb2db9b2015-02-11 15:15:0958 const std::string& family,
[email protected]1e8f699b2014-07-14 19:40:5559 int size_pixels,
60 int style,
61 const FontRenderParams& params);
dchengbc07fa02014-10-29 20:07:2462 ~PlatformFontPango() override;
[email protected]267c03d2011-02-02 23:03:0763
[email protected]d90c0cd2014-07-08 02:31:3464 // 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]3699ae52012-12-05 01:00:5467 const skia::RefPtr<SkTypeface>& typeface,
[email protected]2fb26572013-12-11 08:43:0668 const std::string& font_family,
[email protected]1e8f699b2014-07-14 19:40:5569 int font_size_pixels,
70 int style,
71 const FontRenderParams& params);
[email protected]d90c0cd2014-07-08 02:31:3472
73 // Initializes this object as a copy of another PlatformFontPango.
[email protected]b6bb36e22011-09-21 17:52:5474 void InitFromPlatformFont(const PlatformFontPango* other);
[email protected]267c03d2011-02-02 23:03:0775
[email protected]3699ae52012-12-05 01:00:5476 skia::RefPtr<SkTypeface> typeface_;
[email protected]267c03d2011-02-02 23:03:0777
[email protected]1e8f699b2014-07-14 19:40:5578 // Additional information about the face.
[email protected]267c03d2011-02-02 23:03:0779 // Skia actually expects a family name and not a font name.
[email protected]610ae5f2011-10-27 23:55:3780 std::string font_family_;
[email protected]267c03d2011-02-02 23:03:0781 int font_size_pixels_;
82 int style_;
mukai5dad2e72014-12-16 00:00:3083#if defined(OS_CHROMEOS)
84 float device_scale_factor_;
85#endif
[email protected]267c03d2011-02-02 23:03:0786
[email protected]1e8f699b2014-07-14 19:40:5587 // Information describing how the font should be rendered.
88 FontRenderParams font_render_params_;
89
[email protected]354ee472012-08-30 21:08:1590 // Cached metrics, generated at construction.
[email protected]267c03d2011-02-02 23:03:0791 int ascent_pixels_;
[email protected]d90c0cd2014-07-08 02:31:3492 int height_pixels_;
[email protected]0fbd8de2013-12-24 15:18:5593 int cap_height_pixels_;
[email protected]267c03d2011-02-02 23:03:0794 double average_width_pixels_;
[email protected]267c03d2011-02-02 23:03:0795
[email protected]c963883562013-09-18 08:15:2296#if defined(OS_CHROMEOS)
Daniel Eratcb2db9b2015-02-11 15:15:0997 // A font description string of the format used by gfx::FontList.
[email protected]c963883562013-09-18 08:15:2298 static std::string* default_font_description_;
99#endif
100
[email protected]354ee472012-08-30 21:08:15101 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango);
[email protected]267c03d2011-02-02 23:03:07102};
103
104} // namespace gfx
105
[email protected]c8703bb2011-10-19 14:35:15106#endif // UI_GFX_PLATFORM_FONT_PANGO_H_