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. 4 5 #ifndef UI_GFX_PANGO_UTIL_H_ 6 #define UI_GFX_PANGO_UTIL_H_ 7 8 #include <cairo/cairo.h> 9 #include <pango/pango.h> 10 11 #include "base/i18n/rtl.h" 12 #include "base/logging.h" 13 #include "base/strings/string16.h" 14 #include "third_party/skia/include/core/SkColor.h" 15 #include "ui/gfx/gfx_export.h" 16 17 namespace gfx { 18 19 class FontList; 20 21 // Utility class to ensure that PangoFontDescription is freed. 22 class ScopedPangoFontDescription { 23 public: ScopedPangoFontDescription(PangoFontDescription * description)24 explicit ScopedPangoFontDescription(PangoFontDescription* description) 25 : description_(description) { 26 DCHECK(description); 27 } 28 ScopedPangoFontDescription(const std::string & str)29 explicit ScopedPangoFontDescription(const std::string& str) 30 : description_(pango_font_description_from_string(str.c_str())) { 31 DCHECK(description_); 32 } 33 ~ScopedPangoFontDescription()34 ~ScopedPangoFontDescription() { 35 pango_font_description_free(description_); 36 } 37 get()38 PangoFontDescription* get() { return description_; } 39 40 private: 41 PangoFontDescription* description_; 42 43 DISALLOW_COPY_AND_ASSIGN(ScopedPangoFontDescription); 44 }; 45 46 // ---------------------------------------------------------------------------- 47 // All other methods in this file are only to be used within the ui/ directory. 48 // They are shared with internal skia interfaces. 49 // ---------------------------------------------------------------------------- 50 51 // Configures |layout| for the passed-in parameters. 52 void SetUpPangoLayout( 53 PangoLayout* layout, 54 const base::string16& text, 55 const FontList& font_list, 56 base::i18n::TextDirection text_direction, 57 int flags); 58 59 // Returns the size in pixels for the specified |pango_font|. 60 int GetPangoFontSizeInPixels(PangoFontDescription* pango_font); 61 62 // Retrieves the Pango metrics for a Pango font description. Caches the metrics 63 // and never frees them. The metrics objects are relatively small and very 64 // expensive to look up. 65 PangoFontMetrics* GetPangoFontMetrics(PangoFontDescription* desc); 66 67 } // namespace gfx 68 69 #endif // UI_GFX_PANGO_UTIL_H_ 70