Roll src/third_party/skia 591a2ca:b3fe1b8
[chromium-blink-merge.git] / ui / gfx / platform_font_linux.h
blobc31f2491bf8bb518329dec87b98ddbe8fa5657de
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_
8 #include <string>
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"
17 class SkTypeface;
18 class SkPaint;
20 namespace gfx {
22 class GFX_EXPORT PlatformFontLinux : public PlatformFont {
23 public:
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.
27 PlatformFontLinux();
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);
39 #endif
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;
53 private:
54 // Create a new instance of this object with the specified properties. Called
55 // from DeriveFont.
56 PlatformFontLinux(const skia::RefPtr<SkTypeface>& typeface,
57 const std::string& family,
58 int size_pixels,
59 int style,
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.
65 void InitFromDetails(
66 const skia::RefPtr<SkTypeface>& typeface,
67 const std::string& font_family,
68 int font_size_pixels,
69 int style,
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_;
81 int style_;
82 #if defined(OS_CHROMEOS)
83 float device_scale_factor_;
84 #endif
86 // Information describing how the font should be rendered.
87 FontRenderParams font_render_params_;
89 // Cached metrics, generated at construction.
90 int ascent_pixels_;
91 int height_pixels_;
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_;
98 #endif
100 DISALLOW_COPY_AND_ASSIGN(PlatformFontLinux);
103 } // namespace gfx
105 #endif // UI_GFX_PLATFORM_FONT_LINUX_H_