Refactor HpackDecoder's public API to ease integration into SpdyFramer.
[chromium-blink-merge.git] / ui / gfx / pango_util.h
blobdb60c2e6d5890dabff939838800d11309a0fd8f0
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_PANGO_UTIL_H_
6 #define UI_GFX_PANGO_UTIL_H_
8 #include <cairo/cairo.h>
9 #include <pango/pango.h>
10 #include <string>
12 #include "base/i18n/rtl.h"
13 #include "base/logging.h"
14 #include "base/strings/string16.h"
15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/gfx_export.h"
18 typedef struct _PangoContext PangoContext;
20 namespace gfx {
22 class Font;
23 class PlatformFontPango;
24 class Rect;
26 // Creates and returns a PangoContext. The caller owns the context.
27 PangoContext* GetPangoContext();
29 // Returns the resolution (DPI) used by pango. A negative values means the
30 // resolution hasn't been set.
31 double GetPangoResolution();
33 // Utility class to ensure that PangoFontDescription is freed.
34 class ScopedPangoFontDescription {
35 public:
36 explicit ScopedPangoFontDescription(PangoFontDescription* description)
37 : description_(description) {
38 DCHECK(description);
41 ~ScopedPangoFontDescription() {
42 pango_font_description_free(description_);
45 PangoFontDescription* get() { return description_; }
47 private:
48 PangoFontDescription* description_;
50 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription);
53 // ----------------------------------------------------------------------------
54 // All other methods in this file are only to be used within the ui/ directory.
55 // They are shared with internal skia interfaces.
56 // ----------------------------------------------------------------------------
58 // Setup pango |layout|; set the |text|, the font description based on
59 // |font_description|, the |width| in PANGO_SCALE for RTL locale, the base
60 // |text_direction|, alignment, ellipsis, word wrapping, resolution, etc.
61 void SetupPangoLayoutWithFontDescription(
62 PangoLayout* layout,
63 const base::string16& text,
64 const std::string& font_description,
65 int width,
66 base::i18n::TextDirection text_direction,
67 int flags);
69 // Returns the size in pixels for the specified |pango_font|.
70 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font);
72 // Retrieves the Pango metrics for a Pango font description. Caches the metrics
73 // and never frees them. The metrics objects are relatively small and very
74 // expensive to look up.
75 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc);
77 } // namespace gfx
79 #endif // UI_GFX_PANGO_UTIL_H_