blob: 2638ca2cdf8654b1b473b16e1c0828d1a0d6a1f3 [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
deratcd2d6fb2015-02-12 00:10:415#ifndef UI_GFX_PLATFORM_FONT_LINUX_H_
6#define UI_GFX_PLATFORM_FONT_LINUX_H_
[email protected]267c03d2011-02-02 23:03:077
danakj25c52c32016-04-12 21:51:088#include <memory>
[email protected]c963883562013-09-18 08:15:229#include <string>
10
[email protected]c92434032011-11-15 23:42:5011#include "base/compiler_specific.h"
avic89eb8d42015-12-23 08:08:1812#include "base/macros.h"
avic89eb8d42015-12-23 08:08:1813#include "build/build_config.h"
[email protected]3699ae52012-12-05 01:00:5414#include "skia/ext/refptr.h"
[email protected]267c03d2011-02-02 23:03:0715#include "third_party/skia/include/core/SkRefCnt.h"
[email protected]1e8f699b2014-07-14 19:40:5516#include "ui/gfx/font_render_params.h"
[email protected]08397d52011-02-05 01:53:3817#include "ui/gfx/platform_font.h"
[email protected]267c03d2011-02-02 23:03:0718
19class SkTypeface;
20class SkPaint;
21
22namespace gfx {
23
deratcd2d6fb2015-02-12 00:10:4124class GFX_EXPORT PlatformFontLinux : public PlatformFont {
[email protected]267c03d2011-02-02 23:03:0725 public:
Daniel Eratcb2db9b2015-02-11 15:15:0926 // 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.
deratcd2d6fb2015-02-12 00:10:4129 PlatformFontLinux();
30 PlatformFontLinux(const std::string& font_name, int font_size_pixels);
[email protected]267c03d2011-02-02 23:03:0731
[email protected]28e466c2011-04-06 05:01:2032 // 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]c963883562013-09-18 08:15:2237#if defined(OS_CHROMEOS)
Daniel Eratcb2db9b2015-02-11 15:15:0938 // Sets the default font. |font_description| is a gfx::FontList font
39 // description; only the first family will be used.
[email protected]c963883562013-09-18 08:15:2240 static void SetDefaultFontDescription(const std::string& font_description);
41#endif
42
[email protected]267c03d2011-02-02 23:03:0743 // Overridden from PlatformFont:
dchengbc07fa02014-10-29 20:07:2444 Font DeriveFont(int size_delta, int style) const override;
erikchen773b3a012016-01-07 22:03:5045 int GetHeight() override;
46 int GetBaseline() override;
47 int GetCapHeight() override;
48 int GetExpectedTextWidth(int length) override;
dchengbc07fa02014-10-29 20:07:2449 int GetStyle() const override;
erikchenc1439a42015-12-09 00:25:5550 const std::string& GetFontName() const override;
dchengbc07fa02014-10-29 20:07:2451 std::string GetActualFontNameForTesting() const override;
52 int GetFontSize() const override;
mukai5dad2e72014-12-16 00:00:3053 const FontRenderParams& GetFontRenderParams() override;
[email protected]267c03d2011-02-02 23:03:0754
55 private:
56 // Create a new instance of this object with the specified properties. Called
57 // from DeriveFont.
deratcd2d6fb2015-02-12 00:10:4158 PlatformFontLinux(const skia::RefPtr<SkTypeface>& typeface,
Daniel Eratcb2db9b2015-02-11 15:15:0959 const std::string& family,
[email protected]1e8f699b2014-07-14 19:40:5560 int size_pixels,
61 int style,
62 const FontRenderParams& params);
deratcd2d6fb2015-02-12 00:10:4163 ~PlatformFontLinux() override;
[email protected]267c03d2011-02-02 23:03:0764
[email protected]d90c0cd2014-07-08 02:31:3465 // 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]3699ae52012-12-05 01:00:5468 const skia::RefPtr<SkTypeface>& typeface,
[email protected]2fb26572013-12-11 08:43:0669 const std::string& font_family,
[email protected]1e8f699b2014-07-14 19:40:5570 int font_size_pixels,
71 int style,
72 const FontRenderParams& params);
[email protected]d90c0cd2014-07-08 02:31:3473
deratcd2d6fb2015-02-12 00:10:4174 // Initializes this object as a copy of another PlatformFontLinux.
75 void InitFromPlatformFont(const PlatformFontLinux* other);
[email protected]267c03d2011-02-02 23:03:0776
erikchen773b3a012016-01-07 22:03:5077 // Computes the metrics if they have not yet been computed.
78 void ComputeMetricsIfNecessary();
79
[email protected]3699ae52012-12-05 01:00:5480 skia::RefPtr<SkTypeface> typeface_;
[email protected]267c03d2011-02-02 23:03:0781
[email protected]1e8f699b2014-07-14 19:40:5582 // Additional information about the face.
[email protected]267c03d2011-02-02 23:03:0783 // Skia actually expects a family name and not a font name.
[email protected]610ae5f2011-10-27 23:55:3784 std::string font_family_;
[email protected]267c03d2011-02-02 23:03:0785 int font_size_pixels_;
86 int style_;
mukai5dad2e72014-12-16 00:00:3087 float device_scale_factor_;
[email protected]267c03d2011-02-02 23:03:0788
[email protected]1e8f699b2014-07-14 19:40:5589 // Information describing how the font should be rendered.
90 FontRenderParams font_render_params_;
91
erikchen773b3a012016-01-07 22:03:5092 // Cached metrics, generated on demand.
93 bool metrics_need_computation_ = true;
[email protected]267c03d2011-02-02 23:03:0794 int ascent_pixels_;
[email protected]d90c0cd2014-07-08 02:31:3495 int height_pixels_;
[email protected]0fbd8de2013-12-24 15:18:5596 int cap_height_pixels_;
[email protected]267c03d2011-02-02 23:03:0797 double average_width_pixels_;
[email protected]267c03d2011-02-02 23:03:0798
[email protected]c963883562013-09-18 08:15:2299#if defined(OS_CHROMEOS)
Daniel Eratcb2db9b2015-02-11 15:15:09100 // A font description string of the format used by gfx::FontList.
[email protected]c963883562013-09-18 08:15:22101 static std::string* default_font_description_;
102#endif
103
deratcd2d6fb2015-02-12 00:10:41104 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux);
[email protected]267c03d2011-02-02 23:03:07105};
106
107} // namespace gfx
108
deratcd2d6fb2015-02-12 00:10:41109#endif // UI_GFX_PLATFORM_FONT_LINUX_H_