| 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; | |
| 19 | |
| 20 namespace gfx { | 17 namespace gfx { |
| 21 | 18 |
| 22 class Font; | 19 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 | 20 |
| 33 // Utility class to ensure that PangoFontDescription is freed. | 21 // Utility class to ensure that PangoFontDescription is freed. |
| 34 class ScopedPangoFontDescription { | 22 class ScopedPangoFontDescription { |
| 35 public: | 23 public: |
| 36 explicit ScopedPangoFontDescription(PangoFontDescription* description) | 24 explicit ScopedPangoFontDescription(PangoFontDescription* description) |
| 37 : description_(description) { | 25 : description_(description) { |
| 38 DCHECK(description); | 26 DCHECK(description); |
| 39 } | 27 } |
| 40 | 28 |
| 41 ~ScopedPangoFontDescription() { | 29 ~ScopedPangoFontDescription() { |
| 42 pango_font_description_free(description_); | 30 pango_font_description_free(description_); |
| 43 } | 31 } |
| 44 | 32 |
| 45 PangoFontDescription* get() { return description_; } | 33 PangoFontDescription* get() { return description_; } |
| 46 | 34 |
| 47 private: | 35 private: |
| 48 PangoFontDescription* description_; | 36 PangoFontDescription* description_; |
| 49 | 37 |
| 50 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); | 38 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); |
| 51 }; | 39 }; |
| 52 | 40 |
| 53 // ---------------------------------------------------------------------------- | 41 // ---------------------------------------------------------------------------- |
| 54 // All other methods in this file are only to be used within the ui/ directory. | 42 // All other methods in this file are only to be used within the ui/ directory. |
| 55 // They are shared with internal skia interfaces. | 43 // They are shared with internal skia interfaces. |
| 56 // ---------------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------------- |
| 57 | 45 |
| 58 // Setup pango |layout|; set the |text|, the font description based on | 46 // Configures |layout| for the passed-in parameters. |
| 59 // |font_description|, the |width| in PANGO_SCALE for RTL locale, the base | 47 void SetUpPangoLayout( |
| 60 // |text_direction|, alignment, ellipsis, word wrapping, resolution, etc. | |
| 61 void SetupPangoLayoutWithFontDescription( | |
| 62 PangoLayout* layout, | 48 PangoLayout* layout, |
| 63 const base::string16& text, | 49 const base::string16& text, |
| 64 const std::string& font_description, | 50 const FontList& font_list, |
| 65 int width, | |
| 66 base::i18n::TextDirection text_direction, | 51 base::i18n::TextDirection text_direction, |
| 67 int flags); | 52 int flags); |
| 68 | 53 |
| 69 // Returns the size in pixels for the specified |pango_font|. | 54 // Returns the size in pixels for the specified |pango_font|. |
| 70 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); | 55 size_t GetPangoFontSizeInPixels(PangoFontDescription* pango_font); |
| 71 | 56 |
| 72 // Retrieves the Pango metrics for a Pango font description. Caches the metrics | 57 // 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 | 58 // and never frees them. The metrics objects are relatively small and very |
| 74 // expensive to look up. | 59 // expensive to look up. |
| 75 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); | 60 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); |
| 76 | 61 |
| 77 } // namespace gfx | 62 } // namespace gfx |
| 78 | 63 |
| 79 #endif // UI_GFX_PANGO_UTIL_H_ | 64 #endif // UI_GFX_PANGO_UTIL_H_ |
| OLD | NEW |