| 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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 SkColorGetR(color) / 255.0, | 178 SkColorGetR(color) / 255.0, |
| 179 SkColorGetG(color) / 255.0, | 179 SkColorGetG(color) / 255.0, |
| 180 SkColorGetB(color) / 255.0); | 180 SkColorGetB(color) / 255.0); |
| 181 | 181 |
| 182 std::string utf8 = WideToUTF8(text); | 182 std::string utf8 = WideToUTF8(text); |
| 183 pango_layout_set_text(layout, utf8.data(), utf8.size()); | 183 pango_layout_set_text(layout, utf8.data(), utf8.size()); |
| 184 | 184 |
| 185 int width, height; | 185 int width, height; |
| 186 pango_layout_get_pixel_size(layout, &width, &height); | 186 pango_layout_get_pixel_size(layout, &width, &height); |
| 187 | 187 |
| 188 cairo_rectangle(cr, x, y, width, height); |
| 189 cairo_clip(cr); |
| 190 |
| 188 if (flags & Canvas::TEXT_VALIGN_TOP) { | 191 if (flags & Canvas::TEXT_VALIGN_TOP) { |
| 189 // Cairo should draw from the top left corner already. | 192 // Cairo should draw from the top left corner already. |
| 190 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) { | 193 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) { |
| 191 y += (h - height); | 194 y += (h - height); |
| 192 } else { | 195 } else { |
| 193 // Vertically centered. | 196 // Vertically centered. |
| 194 y += ((h - height) / 2); | 197 y += ((h - height) / 2); |
| 195 } | 198 } |
| 196 | 199 |
| 197 cairo_rectangle(cr, x, y, w, h); | |
| 198 cairo_clip(cr); | |
| 199 | |
| 200 cairo_move_to(cr, x, y); | 200 cairo_move_to(cr, x, y); |
| 201 pango_cairo_show_layout(cr, layout); | 201 pango_cairo_show_layout(cr, layout); |
| 202 if (font.style() & gfx::Font::UNDERLINED) { |
| 203 double underline_y = |
| 204 static_cast<double>(y) + height + font.underline_position(); |
| 205 cairo_set_line_width(cr, font.underline_thickness()); |
| 206 cairo_move_to(cr, x, underline_y); |
| 207 cairo_line_to(cr, x + width, underline_y); |
| 208 cairo_stroke(cr); |
| 209 } |
| 202 cairo_restore(cr); | 210 cairo_restore(cr); |
| 203 | 211 |
| 204 g_object_unref(layout); | 212 g_object_unref(layout); |
| 205 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. | 213 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. |
| 206 } | 214 } |
| 207 | 215 |
| 208 void Canvas::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { | 216 void Canvas::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { |
| 209 if (!pixbuf) { | 217 if (!pixbuf) { |
| 210 NOTREACHED(); | 218 NOTREACHED(); |
| 211 return; | 219 return; |
| 212 } | 220 } |
| 213 | 221 |
| 214 cairo_t* cr = beginPlatformPaint(); | 222 cairo_t* cr = beginPlatformPaint(); |
| 215 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 223 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
| 216 cairo_paint(cr); | 224 cairo_paint(cr); |
| 217 } | 225 } |
| 218 | 226 |
| 219 } // namespace gfx | 227 } // namespace gfx |
| OLD | NEW |