blob: 6652e5938a40d5b7f39e9bc9aa53590675f4e177 [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]267c03d2011-02-02 23:03:0714#include "third_party/skia/include/core/SkRefCnt.h"
[email protected]1e8f699b2014-07-14 19:40:5515#include "ui/gfx/font_render_params.h"
[email protected]08397d52011-02-05 01:53:3816#include "ui/gfx/platform_font.h"
[email protected]267c03d2011-02-02 23:03:0717
18class SkTypeface;
19class SkPaint;
20
21namespace gfx {
22
deratcd2d6fb2015-02-12 00:10:4123class GFX_EXPORT PlatformFontLinux : 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
mboc998e8902016-06-02 11:40:3526 // FontList (which also has the concept of a default font but may contain
Daniel Eratcb2db9b2015-02-11 15:15:0927 // multiple font families) everywhere. See http://crbug.com/398885#c16.
deratcd2d6fb2015-02-12 00:10:4128 PlatformFontLinux();
29 PlatformFontLinux(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)
mboc998e8902016-06-02 11:40:3537 // Sets the default font. |font_description| is a FontList font description;
38 // 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:
mboc998e8902016-06-02 11:40:3543 Font DeriveFont(int size_delta,
44 int style,
45 Font::Weight weight) const override;
erikchen773b3a012016-01-07 22:03:5046 int GetHeight() override;
mboc998e8902016-06-02 11:40:3547 Font::Weight GetWeight() const override;
erikchen773b3a012016-01-07 22:03:5048 int GetBaseline() override;
49 int GetCapHeight() override;
50 int GetExpectedTextWidth(int length) override;
dchengbc07fa02014-10-29 20:07:2451 int GetStyle() const override;
erikchenc1439a42015-12-09 00:25:5552 const std::string& GetFontName() const override;
dchengbc07fa02014-10-29 20:07:2453 std::string GetActualFontNameForTesting() const override;
54 int GetFontSize() const override;
mukai5dad2e72014-12-16 00:00:3055 const FontRenderParams& GetFontRenderParams() override;
[email protected]267c03d2011-02-02 23:03:0756
57 private:
58 // Create a new instance of this object with the specified properties. Called
59 // from DeriveFont.
tomhudson399950b2016-05-11 11:00:1360 PlatformFontLinux(sk_sp<SkTypeface> typeface,
Daniel Eratcb2db9b2015-02-11 15:15:0961 const std::string& family,
[email protected]1e8f699b2014-07-14 19:40:5562 int size_pixels,
mbocfcf964632016-06-06 19:54:4163 int style,
mboc998e8902016-06-02 11:40:3564 Font::Weight weight,
[email protected]1e8f699b2014-07-14 19:40:5565 const FontRenderParams& params);
deratcd2d6fb2015-02-12 00:10:4166 ~PlatformFontLinux() override;
[email protected]267c03d2011-02-02 23:03:0767
[email protected]d90c0cd2014-07-08 02:31:3468 // Initializes this object based on the passed-in details. If |typeface| is
69 // empty, a new typeface will be loaded.
70 void InitFromDetails(
tomhudson399950b2016-05-11 11:00:1371 sk_sp<SkTypeface> typeface,
[email protected]2fb26572013-12-11 08:43:0672 const std::string& font_family,
[email protected]1e8f699b2014-07-14 19:40:5573 int font_size_pixels,
mbocfcf964632016-06-06 19:54:4174 int style,
mboc998e8902016-06-02 11:40:3575 Font::Weight weight,
[email protected]1e8f699b2014-07-14 19:40:5576 const FontRenderParams& params);
[email protected]d90c0cd2014-07-08 02:31:3477
deratcd2d6fb2015-02-12 00:10:4178 // Initializes this object as a copy of another PlatformFontLinux.
79 void InitFromPlatformFont(const PlatformFontLinux* other);
[email protected]267c03d2011-02-02 23:03:0780
erikchen773b3a012016-01-07 22:03:5081 // Computes the metrics if they have not yet been computed.
82 void ComputeMetricsIfNecessary();
83
tomhudson399950b2016-05-11 11:00:1384 sk_sp<SkTypeface> typeface_;
[email protected]267c03d2011-02-02 23:03:0785
[email protected]1e8f699b2014-07-14 19:40:5586 // Additional information about the face.
[email protected]267c03d2011-02-02 23:03:0787 // Skia actually expects a family name and not a font name.
[email protected]610ae5f2011-10-27 23:55:3788 std::string font_family_;
[email protected]267c03d2011-02-02 23:03:0789 int font_size_pixels_;
mbocfcf964632016-06-06 19:54:4190 int style_;
mukai5dad2e72014-12-16 00:00:3091 float device_scale_factor_;
[email protected]267c03d2011-02-02 23:03:0792
[email protected]1e8f699b2014-07-14 19:40:5593 // Information describing how the font should be rendered.
94 FontRenderParams font_render_params_;
95
erikchen773b3a012016-01-07 22:03:5096 // Cached metrics, generated on demand.
97 bool metrics_need_computation_ = true;
[email protected]267c03d2011-02-02 23:03:0798 int ascent_pixels_;
[email protected]d90c0cd2014-07-08 02:31:3499 int height_pixels_;
[email protected]0fbd8de2013-12-24 15:18:55100 int cap_height_pixels_;
[email protected]267c03d2011-02-02 23:03:07101 double average_width_pixels_;
mboc998e8902016-06-02 11:40:35102 Font::Weight weight_;
[email protected]267c03d2011-02-02 23:03:07103
[email protected]c963883562013-09-18 08:15:22104#if defined(OS_CHROMEOS)
mboc998e8902016-06-02 11:40:35105 // A font description string of the format used by FontList.
[email protected]c963883562013-09-18 08:15:22106 static std::string* default_font_description_;
107#endif
108
deratcd2d6fb2015-02-12 00:10:41109 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux);
[email protected]267c03d2011-02-02 23:03:07110};
111
112} // namespace gfx
113
deratcd2d6fb2015-02-12 00:10:41114#endif // UI_GFX_PLATFORM_FONT_LINUX_H_