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 | 7 |
8 #include <cairo/cairo.h> | 8 #include <cairo/cairo.h> |
9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
10 #include <string> | |
11 | 10 |
12 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
16 #include "ui/gfx/gfx_export.h" | 15 #include "ui/gfx/gfx_export.h" |
17 | 16 |
18 typedef struct _PangoContext PangoContext; | 17 typedef struct _PangoContext PangoContext; |
msw
2014/07/08 20:38:31
nit: can this be moved to the .cc file?
Daniel Erat
2014/07/08 20:54:31
good catch. i think it can be deleted entirely; th
| |
19 | 18 |
20 namespace gfx { | 19 namespace gfx { |
21 | 20 |
22 class Font; | 21 class FontList; |
23 class PlatformFontPango; | |
24 class Rect; | |
25 | |
26 // Creates and returns a PangoContext. The caller owns the context. | |
27 PangoContext* GetPangoContext(); | |
28 | |
29 // Returns the resolution (DPI) used by pango. A negative values means the | |
30 // resolution hasn't been set. | |
31 double GetPangoResolution(); | |
32 | 22 |
33 // Utility class to ensure that PangoFontDescription is freed. | 23 // Utility class to ensure that PangoFontDescription is freed. |
34 class ScopedPangoFontDescription { | 24 class ScopedPangoFontDescription { |
35 public: | 25 public: |
36 explicit ScopedPangoFontDescription(PangoFontDescription* description) | 26 explicit ScopedPangoFontDescription(PangoFontDescription* description) |
37 : description_(description) { | 27 : description_(description) { |
38 DCHECK(description); | 28 DCHECK(description); |
39 } | 29 } |
40 | 30 |
41 ~ScopedPangoFontDescription() { | 31 ~ScopedPangoFontDescription() { |
42 pango_font_description_free(description_); | 32 pango_font_description_free(description_); |
43 } | 33 } |
44 | 34 |
45 PangoFontDescription* get() { return description_; } | 35 PangoFontDescription* get() { return description_; } |
46 | 36 |
47 private: | 37 private: |
48 PangoFontDescription* description_; | 38 PangoFontDescription* description_; |
49 | 39 |
50 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); | 40 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); |
51 }; | 41 }; |
52 | 42 |
53 // ---------------------------------------------------------------------------- | 43 // ---------------------------------------------------------------------------- |
54 // All other methods in this file are only to be used within the ui/ directory. | 44 // All other methods in this file are only to be used within the ui/ directory. |
55 // They are shared with internal skia interfaces. | 45 // They are shared with internal skia interfaces. |
56 // ---------------------------------------------------------------------------- | 46 // ---------------------------------------------------------------------------- |
57 | 47 |
58 // Setup pango |layout|; set the |text|, the font description based on | 48 // Configures |layout| for the passed-in parameters. |
59 // |font_description|, the |width| in PANGO_SCALE for RTL locale, the base | 49 void SetUpPangoLayout( |
60 // |text_direction|, alignment, ellipsis, word wrapping, resolution, etc. | |
61 void SetupPangoLayoutWithFontDescription( | |
62 PangoLayout* layout, | 50 PangoLayout* layout, |
63 const base::string16& text, | 51 const base::string16& text, |
64 const std::string& font_description, | 52 const FontList& font_list, |
65 int width, | |
66 base::i18n::TextDirection text_direction, | 53 base::i18n::TextDirection text_direction, |
67 int flags); | 54 int flags); |
68 | 55 |
69 // Returns the size in pixels for the specified |pango_font|. | 56 // Returns the size in pixels for the specified |pango_font|. |
70 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); | 57 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); |
71 | 58 |
72 // Retrieves the Pango metrics for a Pango font description. Caches the metrics | 59 // 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 | 60 // and never frees them. The metrics objects are relatively small and very |
74 // expensive to look up. | 61 // expensive to look up. |
75 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); | 62 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); |
76 | 63 |
77 } // namespace gfx | 64 } // namespace gfx |
78 | 65 |
79 #endif // UI_GFX_PANGO_UTIL_H_ | 66 #endif // UI_GFX_PANGO_UTIL_H_ |
OLD | NEW |