OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_PANGO_UTIL_H_ | 5 #ifndef UI_GFX_PANGO_UTIL_H_ |
6 #define UI_GFX_PANGO_UTIL_H_ | 6 #define UI_GFX_PANGO_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <cairo/cairo.h> | 9 #include <cairo/cairo.h> |
10 #include <pango/pango.h> | 10 #include <pango/pango.h> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/logging.h" |
14 #include "base/string16.h" | 15 #include "base/string16.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
16 #include "ui/base/ui_export.h" | 17 #include "ui/base/ui_export.h" |
17 | 18 |
18 typedef struct _PangoContext PangoContext; | 19 typedef struct _PangoContext PangoContext; |
19 | 20 |
20 namespace gfx { | 21 namespace gfx { |
21 | 22 |
22 class Font; | 23 class Font; |
23 class PlatformFontPango; | 24 class PlatformFontPango; |
24 class Rect; | 25 class Rect; |
25 | 26 |
26 // Creates and returns a PangoContext. The caller owns the context. | 27 // Creates and returns a PangoContext. The caller owns the context. |
27 PangoContext* GetPangoContext(); | 28 PangoContext* GetPangoContext(); |
28 | 29 |
29 // Returns the resolution (DPI) used by pango. A negative values means the | 30 // Returns the resolution (DPI) used by pango. A negative values means the |
30 // resolution hasn't been set. | 31 // resolution hasn't been set. |
31 double GetPangoResolution(); | 32 double GetPangoResolution(); |
32 | 33 |
| 34 // Utility class to ensure that PangoFontDescription is freed. |
| 35 class ScopedPangoFontDescription { |
| 36 public: |
| 37 explicit ScopedPangoFontDescription(PangoFontDescription* description) |
| 38 : description_(description) { |
| 39 DCHECK(description); |
| 40 } |
| 41 |
| 42 ~ScopedPangoFontDescription() { |
| 43 pango_font_description_free(description_); |
| 44 } |
| 45 |
| 46 PangoFontDescription* get() { return description_; } |
| 47 |
| 48 private: |
| 49 PangoFontDescription* description_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); |
| 52 }; |
| 53 |
33 // Uses Pango to draw text onto |cr|. This is the public method for d | 54 // Uses Pango to draw text onto |cr|. This is the public method for d |
34 void UI_EXPORT DrawTextOntoCairoSurface(cairo_t* cr, | 55 void UI_EXPORT DrawTextOntoCairoSurface(cairo_t* cr, |
35 const string16& text, | 56 const string16& text, |
36 const gfx::Font& font, | 57 const gfx::Font& font, |
37 const gfx::Rect& bounds, | 58 const gfx::Rect& bounds, |
38 const gfx::Rect& clip, | 59 const gfx::Rect& clip, |
39 SkColor text_color, | 60 SkColor text_color, |
40 int flags); | 61 int flags); |
41 | 62 |
42 // ---------------------------------------------------------------------------- | 63 // ---------------------------------------------------------------------------- |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); | 116 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); |
96 | 117 |
97 // Retrieves the Pango metrics for a Pango font description. Caches the metrics | 118 // Retrieves the Pango metrics for a Pango font description. Caches the metrics |
98 // and never frees them. The metrics objects are relatively small and very | 119 // and never frees them. The metrics objects are relatively small and very |
99 // expensive to look up. | 120 // expensive to look up. |
100 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); | 121 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); |
101 | 122 |
102 } // namespace gfx | 123 } // namespace gfx |
103 | 124 |
104 #endif // UI_GFX_PANGO_UTIL_H_ | 125 #endif // UI_GFX_PANGO_UTIL_H_ |
OLD | NEW |