| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "gfx/canvas_skia.h" | 5 #include "gfx/canvas_skia.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
| 10 #include <pango/pangocairo.h> | 10 #include <pango/pangocairo.h> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 if (hint_style) | 85 if (hint_style) |
| 86 g_free(hint_style); | 86 g_free(hint_style); |
| 87 if (rgba_style) | 87 if (rgba_style) |
| 88 g_free(rgba_style); | 88 g_free(rgba_style); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Pass a width > 0 to force wrapping and elliding. | 91 // Pass a width > 0 to force wrapping and elliding. |
| 92 static void SetupPangoLayout(PangoLayout* layout, | 92 static void SetupPangoLayout(PangoLayout* layout, |
| 93 const std::wstring& text, | 93 const string16& text, |
| 94 const gfx::Font& font, | 94 const gfx::Font& font, |
| 95 int width, | 95 int width, |
| 96 int flags) { | 96 int flags) { |
| 97 if (!cairo_font_options) | 97 if (!cairo_font_options) |
| 98 UpdateCairoFontOptions(); | 98 UpdateCairoFontOptions(); |
| 99 // This needs to be done early on; it has no effect when called just before | 99 // This needs to be done early on; it has no effect when called just before |
| 100 // pango_cairo_show_layout(). | 100 // pango_cairo_show_layout(). |
| 101 pango_cairo_context_set_font_options( | 101 pango_cairo_context_set_font_options( |
| 102 pango_layout_get_context(layout), cairo_font_options); | 102 pango_layout_get_context(layout), cairo_font_options); |
| 103 | 103 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 133 if (resolution > 0) { | 133 if (resolution > 0) { |
| 134 pango_cairo_context_set_resolution(pango_layout_get_context(layout), | 134 pango_cairo_context_set_resolution(pango_layout_get_context(layout), |
| 135 resolution); | 135 resolution); |
| 136 } | 136 } |
| 137 | 137 |
| 138 PangoFontDescription* desc = font.GetNativeFont(); | 138 PangoFontDescription* desc = font.GetNativeFont(); |
| 139 pango_layout_set_font_description(layout, desc); | 139 pango_layout_set_font_description(layout, desc); |
| 140 pango_font_description_free(desc); | 140 pango_font_description_free(desc); |
| 141 | 141 |
| 142 // Set text and accelerator character if needed. | 142 // Set text and accelerator character if needed. |
| 143 std::string utf8 = WideToUTF8(text); | 143 std::string utf8 = UTF16ToUTF8(text); |
| 144 if (flags & gfx::Canvas::SHOW_PREFIX) { | 144 if (flags & gfx::Canvas::SHOW_PREFIX) { |
| 145 // Escape the text string to be used as markup. | 145 // Escape the text string to be used as markup. |
| 146 gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); | 146 gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); |
| 147 pango_layout_set_markup_with_accel(layout, | 147 pango_layout_set_markup_with_accel(layout, |
| 148 escaped_text, | 148 escaped_text, |
| 149 strlen(escaped_text), | 149 strlen(escaped_text), |
| 150 kAcceleratorChar, NULL); | 150 kAcceleratorChar, NULL); |
| 151 g_free(escaped_text); | 151 g_free(escaped_text); |
| 152 } else if (flags & gfx::Canvas::HIDE_PREFIX) { | 152 } else if (flags & gfx::Canvas::HIDE_PREFIX) { |
| 153 // Remove the ampersand character. | 153 // Remove the ampersand character. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 layout_(NULL), | 204 layout_(NULL), |
| 205 text_x_(bounds.x()), | 205 text_x_(bounds.x()), |
| 206 text_y_(bounds.y()), | 206 text_y_(bounds.y()), |
| 207 text_width_(0), | 207 text_width_(0), |
| 208 text_height_(0) { | 208 text_height_(0) { |
| 209 DCHECK(!bounds_.IsEmpty()); | 209 DCHECK(!bounds_.IsEmpty()); |
| 210 | 210 |
| 211 cr_ = canvas_->beginPlatformPaint(); | 211 cr_ = canvas_->beginPlatformPaint(); |
| 212 layout_ = pango_cairo_create_layout(cr_); | 212 layout_ = pango_cairo_create_layout(cr_); |
| 213 | 213 |
| 214 SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); | 214 SetupPangoLayout(layout_, WideToUTF16Hack(text), font, bounds_.width(), |
| 215 flags_); |
| 215 | 216 |
| 216 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); | 217 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); |
| 217 | 218 |
| 218 cairo_save(cr_); | 219 cairo_save(cr_); |
| 219 | 220 |
| 220 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); | 221 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); |
| 221 cairo_clip(cr_); | 222 cairo_clip(cr_); |
| 222 | 223 |
| 223 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_); | 224 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_); |
| 224 | 225 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 : skia::PlatformCanvas(width, height, is_opaque) { | 303 : skia::PlatformCanvas(width, height, is_opaque) { |
| 303 } | 304 } |
| 304 | 305 |
| 305 CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { | 306 CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { |
| 306 } | 307 } |
| 307 | 308 |
| 308 CanvasSkia::~CanvasSkia() { | 309 CanvasSkia::~CanvasSkia() { |
| 309 } | 310 } |
| 310 | 311 |
| 311 // static | 312 // static |
| 312 void CanvasSkia::SizeStringInt(const std::wstring& text, | 313 void CanvasSkia::SizeStringInt(const string16& text, |
| 313 const gfx::Font& font, | 314 const gfx::Font& font, |
| 314 int* width, int* height, | 315 int* width, int* height, |
| 315 int flags) { | 316 int flags) { |
| 316 int org_width = *width; | 317 int org_width = *width; |
| 317 cairo_surface_t* surface = | 318 cairo_surface_t* surface = |
| 318 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); | 319 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); |
| 319 cairo_t* cr = cairo_create(surface); | 320 cairo_t* cr = cairo_create(surface); |
| 320 PangoLayout* layout = pango_cairo_create_layout(cr); | 321 PangoLayout* layout = pango_cairo_create_layout(cr); |
| 321 | 322 |
| 322 SetupPangoLayout(layout, text, font, *width, flags); | 323 SetupPangoLayout(layout, text, font, *width, flags); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 NOTREACHED(); | 378 NOTREACHED(); |
| 378 return; | 379 return; |
| 379 } | 380 } |
| 380 | 381 |
| 381 cairo_t* cr = beginPlatformPaint(); | 382 cairo_t* cr = beginPlatformPaint(); |
| 382 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
| 383 cairo_paint(cr); | 384 cairo_paint(cr); |
| 384 } | 385 } |
| 385 | 386 |
| 386 } // namespace gfx | 387 } // namespace gfx |
| OLD | NEW |