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_
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 PlatformFontPango
: public PlatformFont
{
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
);
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
;
57 // Create a new instance of this object with the specified properties. Called
59 PlatformFontPango(const skia::RefPtr
<SkTypeface
>& typeface
,
60 const std::string
& name
,
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.
69 const skia::RefPtr
<SkTypeface
>& typeface
,
70 const std::string
& font_family
,
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_
;
85 #if defined(OS_CHROMEOS)
86 float device_scale_factor_
;
89 // Information describing how the font should be rendered.
90 FontRenderParams font_render_params_
;
92 // Cached metrics, generated at construction.
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_
;
106 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango
);
111 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_