1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_PLATFORM_FONT_LINUX_H_
6 #define UI_GFX_PLATFORM_FONT_LINUX_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "skia/ext/refptr.h"
13 #include "third_party/skia/include/core/SkRefCnt.h"
14 #include "ui/gfx/font_render_params.h"
15 #include "ui/gfx/platform_font.h"
22 class GFX_EXPORT PlatformFontLinux
: public PlatformFont
{
24 // TODO(derat): Get rid of the default constructor in favor of using
25 // gfx::FontList (which also has the concept of a default font but may contain
26 // multiple font families) everywhere. See http://crbug.com/398885#c16.
28 PlatformFontLinux(const std::string
& font_name
, int font_size_pixels
);
30 // Resets and reloads the cached system font used by the default constructor.
31 // This function is useful when the system font has changed, for example, when
32 // the locale has changed.
33 static void ReloadDefaultFont();
35 #if defined(OS_CHROMEOS)
36 // Sets the default font. |font_description| is a gfx::FontList font
37 // description; only the first family will be used.
38 static void SetDefaultFontDescription(const std::string
& font_description
);
41 // Overridden from PlatformFont:
42 Font
DeriveFont(int size_delta
, int style
) const override
;
43 int GetHeight() const override
;
44 int GetBaseline() const override
;
45 int GetCapHeight() const override
;
46 int GetExpectedTextWidth(int length
) const override
;
47 int GetStyle() const override
;
48 std::string
GetFontName() const override
;
49 std::string
GetActualFontNameForTesting() const override
;
50 int GetFontSize() const override
;
51 const FontRenderParams
& GetFontRenderParams() override
;
54 // Create a new instance of this object with the specified properties. Called
56 PlatformFontLinux(const skia::RefPtr
<SkTypeface
>& typeface
,
57 const std::string
& family
,
60 const FontRenderParams
& params
);
61 ~PlatformFontLinux() override
;
63 // Initializes this object based on the passed-in details. If |typeface| is
64 // empty, a new typeface will be loaded.
66 const skia::RefPtr
<SkTypeface
>& typeface
,
67 const std::string
& font_family
,
70 const FontRenderParams
& params
);
72 // Initializes this object as a copy of another PlatformFontLinux.
73 void InitFromPlatformFont(const PlatformFontLinux
* other
);
75 skia::RefPtr
<SkTypeface
> typeface_
;
77 // Additional information about the face.
78 // Skia actually expects a family name and not a font name.
79 std::string font_family_
;
80 int font_size_pixels_
;
82 #if defined(OS_CHROMEOS)
83 float device_scale_factor_
;
86 // Information describing how the font should be rendered.
87 FontRenderParams font_render_params_
;
89 // Cached metrics, generated at construction.
92 int cap_height_pixels_
;
93 double average_width_pixels_
;
95 #if defined(OS_CHROMEOS)
96 // A font description string of the format used by gfx::FontList.
97 static std::string
* default_font_description_
;
100 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux
);
105 #endif // UI_GFX_PLATFORM_FONT_LINUX_H_