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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/gtk_util.h" | 13 #include "base/gtk_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "gfx/font.h" | 15 #include "gfx/font.h" |
16 #include "gfx/gtk_util.h" | 16 #include "gfx/gtk_util.h" |
| 17 #include "gfx/platform_font_gtk.h" |
17 #include "gfx/rect.h" | 18 #include "gfx/rect.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const gunichar kAcceleratorChar = '&'; | 22 const gunichar kAcceleratorChar = '&'; |
22 | 23 |
23 // Font settings that we initialize once and then use when drawing text in | 24 // Font settings that we initialize once and then use when drawing text in |
24 // DrawStringInt(). | 25 // DrawStringInt(). |
25 static cairo_font_options_t* cairo_font_options = NULL; | 26 static cairo_font_options_t* cairo_font_options = NULL; |
26 | 27 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 143 |
143 // Set the resolution to match that used by Gtk. If we don't set the | 144 // Set the resolution to match that used by Gtk. If we don't set the |
144 // resolution and the resolution differs from the default, Gtk and Chrome end | 145 // resolution and the resolution differs from the default, Gtk and Chrome end |
145 // up drawing at different sizes. | 146 // up drawing at different sizes. |
146 double resolution = gfx::GetPangoResolution(); | 147 double resolution = gfx::GetPangoResolution(); |
147 if (resolution > 0) { | 148 if (resolution > 0) { |
148 pango_cairo_context_set_resolution(pango_layout_get_context(layout), | 149 pango_cairo_context_set_resolution(pango_layout_get_context(layout), |
149 resolution); | 150 resolution); |
150 } | 151 } |
151 | 152 |
152 PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font); | 153 PangoFontDescription* desc = font.GetNativeFont(); |
153 pango_layout_set_font_description(layout, desc); | 154 pango_layout_set_font_description(layout, desc); |
154 pango_font_description_free(desc); | 155 pango_font_description_free(desc); |
155 | 156 |
156 // Set text and accelerator character if needed. | 157 // Set text and accelerator character if needed. |
157 std::string utf8 = WideToUTF8(text); | 158 std::string utf8 = WideToUTF8(text); |
158 if (flags & gfx::Canvas::SHOW_PREFIX) { | 159 if (flags & gfx::Canvas::SHOW_PREFIX) { |
159 // Escape the text string to be used as markup. | 160 // Escape the text string to be used as markup. |
160 gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); | 161 gchar* escaped_text = g_markup_escape_text(utf8.c_str(), utf8.size()); |
161 pango_layout_set_markup_with_accel(layout, | 162 pango_layout_set_markup_with_accel(layout, |
162 escaped_text, | 163 escaped_text, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // Cairo should draw from the top left corner already. | 240 // Cairo should draw from the top left corner already. |
240 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) { | 241 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) { |
241 y += (h - height); | 242 y += (h - height); |
242 } else { | 243 } else { |
243 // Vertically centered. | 244 // Vertically centered. |
244 y += ((h - height) / 2); | 245 y += ((h - height) / 2); |
245 } | 246 } |
246 | 247 |
247 cairo_move_to(cr, x, y); | 248 cairo_move_to(cr, x, y); |
248 pango_cairo_show_layout(cr, layout); | 249 pango_cairo_show_layout(cr, layout); |
249 if (font.style() & gfx::Font::UNDERLINED) { | 250 if (font.GetStyle() & gfx::Font::UNDERLINED) { |
| 251 gfx::PlatformFontGtk* platform_font = |
| 252 static_cast<gfx::PlatformFontGtk*>(font.platform_font()); |
250 double underline_y = | 253 double underline_y = |
251 static_cast<double>(y) + height + font.underline_position(); | 254 static_cast<double>(y) + height + platform_font->underline_position(); |
252 cairo_set_line_width(cr, font.underline_thickness()); | 255 cairo_set_line_width(cr, platform_font->underline_thickness()); |
253 cairo_move_to(cr, x, underline_y); | 256 cairo_move_to(cr, x, underline_y); |
254 cairo_line_to(cr, x + width, underline_y); | 257 cairo_line_to(cr, x + width, underline_y); |
255 cairo_stroke(cr); | 258 cairo_stroke(cr); |
256 } | 259 } |
257 cairo_restore(cr); | 260 cairo_restore(cr); |
258 | 261 |
259 g_object_unref(layout); | 262 g_object_unref(layout); |
260 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. | 263 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. |
261 } | 264 } |
262 | 265 |
263 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { | 266 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { |
264 if (!pixbuf) { | 267 if (!pixbuf) { |
265 NOTREACHED(); | 268 NOTREACHED(); |
266 return; | 269 return; |
267 } | 270 } |
268 | 271 |
269 cairo_t* cr = beginPlatformPaint(); | 272 cairo_t* cr = beginPlatformPaint(); |
270 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 273 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
271 cairo_paint(cr); | 274 cairo_paint(cr); |
272 } | 275 } |
273 | 276 |
274 } // namespace gfx | 277 } // namespace gfx |
OLD | NEW |