[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / gfx / platform_font_pango.h
blobd0132eb8ac34685b182a3dd9f7058b329932a1cc
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.
39 static void SetDefaultFontDescription(const std::string& font_description);
40 #endif
42 // Position as an offset from the height of the drawn text, used to draw
43 // an underline. This is a negative number, so the underline would be
44 // drawn at y + height + underline_position.
45 double underline_position() const;
46 // The thickness to draw the underline.
47 double underline_thickness() const;
49 // Overridden from PlatformFont:
50 virtual Font DeriveFont(int size_delta, int style) const OVERRIDE;
51 virtual int GetHeight() const OVERRIDE;
52 virtual int GetBaseline() const OVERRIDE;
53 virtual int GetCapHeight() const OVERRIDE;
54 virtual int GetExpectedTextWidth(int length) const OVERRIDE;
55 virtual int GetStyle() const OVERRIDE;
56 virtual std::string GetFontName() const OVERRIDE;
57 virtual std::string GetActualFontNameForTesting() const OVERRIDE;
58 virtual int GetFontSize() const OVERRIDE;
59 virtual const FontRenderParams& GetFontRenderParams() const OVERRIDE;
60 virtual NativeFont GetNativeFont() const OVERRIDE;
62 private:
63 // Create a new instance of this object with the specified properties. Called
64 // from DeriveFont.
65 PlatformFontPango(const skia::RefPtr<SkTypeface>& typeface,
66 const std::string& name,
67 int size_pixels,
68 int style,
69 const FontRenderParams& params);
70 virtual ~PlatformFontPango();
72 // Initializes this object based on the passed-in details. If |typeface| is
73 // empty, a new typeface will be loaded.
74 void InitFromDetails(
75 const skia::RefPtr<SkTypeface>& typeface,
76 const std::string& font_family,
77 int font_size_pixels,
78 int style,
79 const FontRenderParams& params);
81 // Initializes this object as a copy of another PlatformFontPango.
82 void InitFromPlatformFont(const PlatformFontPango* other);
84 // Potentially slow call to get pango metrics (average width, underline info).
85 void InitPangoMetrics();
87 // Setup a Skia context to use the current typeface.
88 void PaintSetup(SkPaint* paint) const;
90 // Make |this| a copy of |other|.
91 void CopyFont(const Font& other);
93 // The average width of a character, initialized and cached if needed.
94 double GetAverageWidth() const;
96 skia::RefPtr<SkTypeface> typeface_;
98 // Additional information about the face.
99 // Skia actually expects a family name and not a font name.
100 std::string font_family_;
101 int font_size_pixels_;
102 int style_;
104 // Information describing how the font should be rendered.
105 FontRenderParams font_render_params_;
107 // Cached metrics, generated at construction.
108 int ascent_pixels_;
109 int height_pixels_;
110 int cap_height_pixels_;
112 // The pango metrics are much more expensive so we wait until we need them
113 // to compute them.
114 bool pango_metrics_inited_;
115 double average_width_pixels_;
116 double underline_position_pixels_;
117 double underline_thickness_pixels_;
119 // The default font, used for the default constructor.
120 static Font* default_font_;
122 #if defined(OS_CHROMEOS)
123 static std::string* default_font_description_;
124 #endif
126 DISALLOW_COPY_AND_ASSIGN(PlatformFontPango);
129 } // namespace gfx
131 #endif // UI_GFX_PLATFORM_FONT_PANGO_H_