base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / gfx / platform_font_pango.h
blob47f402eeb4e57eb83bcde6b39215f52a06185330
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_PANGO_H_
6 #define UI_GFX_PLATFORM_FONT_PANGO_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 PlatformFontPango : public PlatformFont {
23 public:
24 PlatformFontPango();
25 explicit PlatformFontPango(NativeFont native_font);
26 PlatformFontPango(const std::string& font_name, int font_size_pixels);
28 // Converts |gfx_font| to a new pango font. Free the returned font with
29 // pango_font_description_free().
30 static PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& gfx_font);
32 // 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();
37 #if defined(OS_CHROMEOS)
38 // Sets the default font. |font_description| is a Pango font description that
39 // will be passed to pango_font_description_from_string().
40 static void SetDefaultFontDescription(const std::string& font_description);
41 #endif
43 // Overridden from PlatformFont:
44 Font DeriveFont(int size_delta, int style) const override;
45 int GetHeight() const override;
46 int GetBaseline() const override;
47 int GetCapHeight() const override;
48 int GetExpectedTextWidth(int length) const override;
49 int GetStyle() const override;
50 std::string GetFontName() const override;
51 std::string GetActualFontNameForTesting() const override;
52 int GetFontSize() const override;
53 const FontRenderParams& GetFontRenderParams() override;
54 NativeFont GetNativeFont() const override;
56 private:
57 // Create a new instance of this object with the specified properties. Called
58 // from DeriveFont.
59 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
60 const std::string& name,
61 int size_pixels,
62 int style,
63 const FontRenderParams& params);
64 ~PlatformFontPango() override;
66 // Initializes this object based on the passed-in details. If |typeface| is
67 // empty, a new typeface will be loaded.
68 void InitFromDetails(
69 const skia::RefPtr<SkTypeface>& typeface,
70 const std::string& font_family,
71 int font_size_pixels,
72 int style,
73 const FontRenderParams& params);
75 // Initializes this object as a copy of another PlatformFontPango.
76 void InitFromPlatformFont(const PlatformFontPango* other);
78 skia::RefPtr<SkTypeface> typeface_;
80 // Additional information about the face.
81 // Skia actually expects a family name and not a font name.
82 std::string font_family_;
83 int font_size_pixels_;
84 int style_;
85 #if defined(OS_CHROMEOS)
86 float device_scale_factor_;
87 #endif
89 // Information describing how the font should be rendered.
90 FontRenderParams font_render_params_;
92 // Cached metrics, generated at construction.
93 int ascent_pixels_;
94 int height_pixels_;
95 int cap_height_pixels_;
96 double average_width_pixels_;
98 // The default font, used for the default constructor.
99 static Font* default_font_;
101 #if defined(OS_CHROMEOS)
102 // A Pango font description.
103 static std::string* default_font_description_;
104 #endif
106 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango);
109 } // namespace gfx
111 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_