| 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.h" | 5 #include "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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 if (hint_style) | 84 if (hint_style) |
| 85 g_free(hint_style); | 85 g_free(hint_style); |
| 86 if (rgba_style) | 86 if (rgba_style) |
| 87 g_free(rgba_style); | 87 g_free(rgba_style); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 namespace gfx { | 92 namespace gfx { |
| 93 | 93 |
| 94 Canvas::Canvas(int width, int height, bool is_opaque) | 94 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) |
| 95 : skia::PlatformCanvas(width, height, is_opaque) { | 95 : skia::PlatformCanvas(width, height, is_opaque) { |
| 96 } | 96 } |
| 97 | 97 |
| 98 Canvas::Canvas() : skia::PlatformCanvas() { | 98 CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { |
| 99 } | 99 } |
| 100 | 100 |
| 101 Canvas::~Canvas() { | 101 CanvasSkia::~CanvasSkia() { |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Pass a width > 0 to force wrapping and elliding. | 104 // Pass a width > 0 to force wrapping and elliding. |
| 105 static void SetupPangoLayout(PangoLayout* layout, | 105 static void SetupPangoLayout(PangoLayout* layout, |
| 106 const std::wstring& text, | 106 const std::wstring& text, |
| 107 const gfx::Font& font, | 107 const gfx::Font& font, |
| 108 int width, | 108 int width, |
| 109 int flags) { | 109 int flags) { |
| 110 if (!cairo_font_options) | 110 if (!cairo_font_options) |
| 111 UpdateCairoFontOptions(); | 111 UpdateCairoFontOptions(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 escaped_text, | 161 escaped_text, |
| 162 strlen(escaped_text), | 162 strlen(escaped_text), |
| 163 kAcceleratorChar, NULL); | 163 kAcceleratorChar, NULL); |
| 164 g_free(escaped_text); | 164 g_free(escaped_text); |
| 165 } else { | 165 } else { |
| 166 pango_layout_set_text(layout, utf8.data(), utf8.size()); | 166 pango_layout_set_text(layout, utf8.data(), utf8.size()); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 // static | 170 // static |
| 171 void Canvas::SizeStringInt(const std::wstring& text, | 171 void CanvasSkia::SizeStringInt(const std::wstring& text, |
| 172 const gfx::Font& font, | 172 const gfx::Font& font, |
| 173 int* width, int* height, int flags) { | 173 int* width, int* height, int flags) { |
| 174 int org_width = *width; | 174 int org_width = *width; |
| 175 cairo_surface_t* surface = | 175 cairo_surface_t* surface = |
| 176 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); | 176 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); |
| 177 cairo_t* cr = cairo_create(surface); | 177 cairo_t* cr = cairo_create(surface); |
| 178 PangoLayout* layout = pango_cairo_create_layout(cr); | 178 PangoLayout* layout = pango_cairo_create_layout(cr); |
| 179 | 179 |
| 180 SetupPangoLayout(layout, text, font, *width, flags); | 180 SetupPangoLayout(layout, text, font, *width, flags); |
| 181 | 181 |
| 182 pango_layout_get_pixel_size(layout, width, height); | 182 pango_layout_get_pixel_size(layout, width, height); |
| 183 | 183 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 // asked for. See the loop in pango-layout.c process_item that determines | 195 // asked for. See the loop in pango-layout.c process_item that determines |
| 196 // where to wrap. | 196 // where to wrap. |
| 197 *width = org_width; | 197 *width = org_width; |
| 198 } | 198 } |
| 199 | 199 |
| 200 g_object_unref(layout); | 200 g_object_unref(layout); |
| 201 cairo_destroy(cr); | 201 cairo_destroy(cr); |
| 202 cairo_surface_destroy(surface); | 202 cairo_surface_destroy(surface); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void Canvas::DrawStringInt(const std::wstring& text, | 205 void CanvasSkia::DrawStringInt(const std::wstring& text, |
| 206 const gfx::Font& font, | 206 const gfx::Font& font, |
| 207 const SkColor& color, | 207 const SkColor& color, |
| 208 int x, int y, int w, int h, | 208 int x, int y, int w, int h, |
| 209 int flags) { | 209 int flags) { |
| 210 if (w <= 0 || h <= 0) | 210 if (w <= 0 || h <= 0) |
| 211 return; | 211 return; |
| 212 | 212 |
| 213 cairo_t* cr = beginPlatformPaint(); | 213 cairo_t* cr = beginPlatformPaint(); |
| 214 PangoLayout* layout = pango_cairo_create_layout(cr); | 214 PangoLayout* layout = pango_cairo_create_layout(cr); |
| 215 | 215 |
| 216 SetupPangoLayout(layout, text, font, w, flags); | 216 SetupPangoLayout(layout, text, font, w, flags); |
| 217 | 217 |
| 218 pango_layout_set_height(layout, h * PANGO_SCALE); | 218 pango_layout_set_height(layout, h * PANGO_SCALE); |
| 219 | 219 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 248 cairo_move_to(cr, x, underline_y); | 248 cairo_move_to(cr, x, underline_y); |
| 249 cairo_line_to(cr, x + width, underline_y); | 249 cairo_line_to(cr, x + width, underline_y); |
| 250 cairo_stroke(cr); | 250 cairo_stroke(cr); |
| 251 } | 251 } |
| 252 cairo_restore(cr); | 252 cairo_restore(cr); |
| 253 | 253 |
| 254 g_object_unref(layout); | 254 g_object_unref(layout); |
| 255 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. | 255 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. |
| 256 } | 256 } |
| 257 | 257 |
| 258 void Canvas::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { | 258 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { |
| 259 if (!pixbuf) { | 259 if (!pixbuf) { |
| 260 NOTREACHED(); | 260 NOTREACHED(); |
| 261 return; | 261 return; |
| 262 } | 262 } |
| 263 | 263 |
| 264 cairo_t* cr = beginPlatformPaint(); | 264 cairo_t* cr = beginPlatformPaint(); |
| 265 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 265 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
| 266 cairo_paint(cr); | 266 cairo_paint(cr); |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace gfx | 269 } // namespace gfx |
| OLD | NEW |