| 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 #include "ui/gfx/pango_util.h" | 5 #include "ui/gfx/pango_util.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <fontconfig/fontconfig.h> | 8 #include <fontconfig/fontconfig.h> |
| 9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
| 10 #include <pango/pangocairo.h> | 10 #include <pango/pangocairo.h> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <map> | 14 #include <map> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
| 21 #include "ui/gfx/font_render_params_linux.h" | 21 #include "ui/gfx/font_render_params_linux.h" |
| 22 #include "ui/gfx/platform_font_pango.h" | 22 #include "ui/gfx/platform_font_pango.h" |
| 23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 24 #include "ui/gfx/text_utils.h" | 24 #include "ui/gfx/text_utils.h" |
| 25 | 25 |
| 26 #if defined(TOOLKIT_GTK) | |
| 27 #include <gdk/gdk.h> | |
| 28 #endif | |
| 29 | |
| 30 namespace gfx { | 26 namespace gfx { |
| 31 | 27 |
| 32 namespace { | 28 namespace { |
| 33 | 29 |
| 34 // Marker for accelerators in the text. | 30 // Marker for accelerators in the text. |
| 35 const gunichar kAcceleratorChar = '&'; | 31 const gunichar kAcceleratorChar = '&'; |
| 36 | 32 |
| 37 // Return |cairo_font_options|. If needed, allocate and update it. | 33 // Return |cairo_font_options|. If needed, allocate and update it. |
| 38 // TODO(derat): Return font-specific options: http://crbug.com/125235 | 34 // TODO(derat): Return font-specific options: http://crbug.com/125235 |
| 39 cairo_font_options_t* GetCairoFontOptions() { | 35 cairo_font_options_t* GetCairoFontOptions() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 pixels_in_point = pango_dpi / 72.0; // 72 points in an inch | 105 pixels_in_point = pango_dpi / 72.0; // 72 points in an inch |
| 110 determined_value = true; | 106 determined_value = true; |
| 111 } | 107 } |
| 112 | 108 |
| 113 return pixels_in_point; | 109 return pixels_in_point; |
| 114 } | 110 } |
| 115 | 111 |
| 116 } // namespace | 112 } // namespace |
| 117 | 113 |
| 118 PangoContext* GetPangoContext() { | 114 PangoContext* GetPangoContext() { |
| 119 #if defined(TOOLKIT_GTK) | |
| 120 return gdk_pango_context_get(); | |
| 121 #else | |
| 122 PangoFontMap* font_map = pango_cairo_font_map_get_default(); | 115 PangoFontMap* font_map = pango_cairo_font_map_get_default(); |
| 123 return pango_font_map_create_context(font_map); | 116 return pango_font_map_create_context(font_map); |
| 124 #endif | |
| 125 } | 117 } |
| 126 | 118 |
| 127 double GetPangoResolution() { | 119 double GetPangoResolution() { |
| 128 static double resolution; | 120 static double resolution; |
| 129 static bool determined_resolution = false; | 121 static bool determined_resolution = false; |
| 130 if (!determined_resolution) { | 122 if (!determined_resolution) { |
| 131 determined_resolution = true; | 123 determined_resolution = true; |
| 132 PangoContext* default_context = GetPangoContext(); | 124 PangoContext* default_context = GetPangoContext(); |
| 133 resolution = pango_cairo_context_get_resolution(default_context); | 125 resolution = pango_cairo_context_get_resolution(default_context); |
| 134 g_object_unref(default_context); | 126 g_object_unref(default_context); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 287 |
| 296 if (i == desc_to_metrics->end()) { | 288 if (i == desc_to_metrics->end()) { |
| 297 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); | 289 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); |
| 298 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); | 290 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); |
| 299 return metrics; | 291 return metrics; |
| 300 } | 292 } |
| 301 return i->second; | 293 return i->second; |
| 302 } | 294 } |
| 303 | 295 |
| 304 } // namespace gfx | 296 } // namespace gfx |
| OLD | NEW |