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> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (!determined_resolution) { | 137 if (!determined_resolution) { |
138 determined_resolution = true; | 138 determined_resolution = true; |
139 PangoContext* default_context = GetPangoContext(); | 139 PangoContext* default_context = GetPangoContext(); |
140 resolution = pango_cairo_context_get_resolution(default_context); | 140 resolution = pango_cairo_context_get_resolution(default_context); |
141 g_object_unref(default_context); | 141 g_object_unref(default_context); |
142 } | 142 } |
143 return resolution; | 143 return resolution; |
144 } | 144 } |
145 | 145 |
146 void DrawTextOntoCairoSurface(cairo_t* cr, | 146 void DrawTextOntoCairoSurface(cairo_t* cr, |
147 const string16& text, | 147 const base::string16& text, |
148 const gfx::Font& font, | 148 const gfx::Font& font, |
149 const gfx::Rect& bounds, | 149 const gfx::Rect& bounds, |
150 const gfx::Rect& clip, | 150 const gfx::Rect& clip, |
151 SkColor text_color, | 151 SkColor text_color, |
152 int flags) { | 152 int flags) { |
153 PangoLayout* layout = pango_cairo_create_layout(cr); | 153 PangoLayout* layout = pango_cairo_create_layout(cr); |
154 base::i18n::TextDirection text_direction = | 154 base::i18n::TextDirection text_direction = |
155 base::i18n::GetFirstStrongCharacterDirection(text); | 155 base::i18n::GetFirstStrongCharacterDirection(text); |
156 DCHECK(!bounds.IsEmpty()); | 156 DCHECK(!bounds.IsEmpty()); |
157 | 157 |
(...skipping 15 matching lines...) Expand all Loading... |
173 DrawPangoLayout(cr, layout, font, bounds, text_rect, | 173 DrawPangoLayout(cr, layout, font, bounds, text_rect, |
174 text_color, text_direction, flags); | 174 text_color, text_direction, flags); |
175 | 175 |
176 cairo_restore(cr); | 176 cairo_restore(cr); |
177 g_object_unref(layout); | 177 g_object_unref(layout); |
178 } | 178 } |
179 | 179 |
180 // Pass a width greater than 0 to force wrapping and eliding. | 180 // Pass a width greater than 0 to force wrapping and eliding. |
181 static void SetupPangoLayoutWithoutFont( | 181 static void SetupPangoLayoutWithoutFont( |
182 PangoLayout* layout, | 182 PangoLayout* layout, |
183 const string16& text, | 183 const base::string16& text, |
184 int width, | 184 int width, |
185 base::i18n::TextDirection text_direction, | 185 base::i18n::TextDirection text_direction, |
186 int flags) { | 186 int flags) { |
187 cairo_font_options_t* cairo_font_options = GetCairoFontOptions(); | 187 cairo_font_options_t* cairo_font_options = GetCairoFontOptions(); |
188 | 188 |
189 // If we got an explicit request to turn off subpixel rendering, disable it on | 189 // If we got an explicit request to turn off subpixel rendering, disable it on |
190 // a copy of the static font options object. | 190 // a copy of the static font options object. |
191 bool copied_cairo_font_options = false; | 191 bool copied_cairo_font_options = false; |
192 if ((flags & Canvas::NO_SUBPIXEL_RENDERING) && | 192 if ((flags & Canvas::NO_SUBPIXEL_RENDERING) && |
193 (cairo_font_options_get_antialias(cairo_font_options) == | 193 (cairo_font_options_get_antialias(cairo_font_options) == |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 strlen(escaped_text), | 259 strlen(escaped_text), |
260 kAcceleratorChar, NULL); | 260 kAcceleratorChar, NULL); |
261 g_free(escaped_text); | 261 g_free(escaped_text); |
262 } else { | 262 } else { |
263 std::string utf8; | 263 std::string utf8; |
264 | 264 |
265 // Remove the ampersand character. A double ampersand is output as | 265 // Remove the ampersand character. A double ampersand is output as |
266 // a single ampersand. | 266 // a single ampersand. |
267 if (flags & Canvas::HIDE_PREFIX) { | 267 if (flags & Canvas::HIDE_PREFIX) { |
268 DCHECK_EQ(1, g_unichar_to_utf8(kAcceleratorChar, NULL)); | 268 DCHECK_EQ(1, g_unichar_to_utf8(kAcceleratorChar, NULL)); |
269 string16 accelerator_removed = | 269 base::string16 accelerator_removed = |
270 RemoveAcceleratorChar(text, static_cast<char16>(kAcceleratorChar), | 270 RemoveAcceleratorChar(text, static_cast<char16>(kAcceleratorChar), |
271 NULL, NULL); | 271 NULL, NULL); |
272 utf8 = UTF16ToUTF8(accelerator_removed); | 272 utf8 = UTF16ToUTF8(accelerator_removed); |
273 } else { | 273 } else { |
274 utf8 = UTF16ToUTF8(text); | 274 utf8 = UTF16ToUTF8(text); |
275 } | 275 } |
276 | 276 |
277 pango_layout_set_text(layout, utf8.data(), utf8.size()); | 277 pango_layout_set_text(layout, utf8.data(), utf8.size()); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 void SetupPangoLayout(PangoLayout* layout, | 281 void SetupPangoLayout(PangoLayout* layout, |
282 const string16& text, | 282 const base::string16& text, |
283 const Font& font, | 283 const Font& font, |
284 int width, | 284 int width, |
285 base::i18n::TextDirection text_direction, | 285 base::i18n::TextDirection text_direction, |
286 int flags) { | 286 int flags) { |
287 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); | 287 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); |
288 | 288 |
289 ScopedPangoFontDescription desc(font.GetNativeFont()); | 289 ScopedPangoFontDescription desc(font.GetNativeFont()); |
290 pango_layout_set_font_description(layout, desc.get()); | 290 pango_layout_set_font_description(layout, desc.get()); |
291 } | 291 } |
292 | 292 |
293 void SetupPangoLayoutWithFontDescription( | 293 void SetupPangoLayoutWithFontDescription( |
294 PangoLayout* layout, | 294 PangoLayout* layout, |
295 const string16& text, | 295 const base::string16& text, |
296 const std::string& font_description, | 296 const std::string& font_description, |
297 int width, | 297 int width, |
298 base::i18n::TextDirection text_direction, | 298 base::i18n::TextDirection text_direction, |
299 int flags) { | 299 int flags) { |
300 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); | 300 SetupPangoLayoutWithoutFont(layout, text, width, text_direction, flags); |
301 | 301 |
302 ScopedPangoFontDescription desc( | 302 ScopedPangoFontDescription desc( |
303 pango_font_description_from_string(font_description.c_str())); | 303 pango_font_description_from_string(font_description.c_str())); |
304 pango_layout_set_font_description(layout, desc.get()); | 304 pango_layout_set_font_description(layout, desc.get()); |
305 } | 305 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 407 |
408 if (i == desc_to_metrics->end()) { | 408 if (i == desc_to_metrics->end()) { |
409 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); | 409 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); |
410 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); | 410 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); |
411 return metrics; | 411 return metrics; |
412 } | 412 } |
413 return i->second; | 413 return i->second; |
414 } | 414 } |
415 | 415 |
416 } // namespace gfx | 416 } // namespace gfx |
OLD | NEW |