Chromium Code Reviews| Index: gfx/canvas_skia_linux.cc |
| diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc |
| index 57705a68618fa83359b5bb03a7efa5a88371b86d..b8eb8927a0ecc7c4c30dfe133160f4d8d3660c26 100644 |
| --- a/gfx/canvas_skia_linux.cc |
| +++ b/gfx/canvas_skia_linux.cc |
| @@ -208,14 +208,17 @@ void CanvasSkia::SizeStringInt(const std::wstring& text, |
| cairo_surface_destroy(surface); |
| } |
| -void CanvasSkia::DrawStringInt(const std::wstring& text, |
| - const gfx::Font& font, |
| - const SkColor& color, |
| - int x, int y, int w, int h, |
| - int flags) { |
| +void CanvasSkia::DrawStringWithHalo(const std::wstring& text, |
|
DaveMoore
2010/11/17 01:07:43
I don't think this method should be called "DrawSt
xiyuan
2010/11/17 17:59:22
One possible way to share is wrapping the common c
|
| + const gfx::Font& font, |
| + const SkColor& text_color, |
| + const SkColor& halo_color, |
| + int x, int y, int w, int h, |
| + int flags) { |
| if (w <= 0 || h <= 0) |
| return; |
| + bool has_halo = text_color != halo_color; |
| + |
| cairo_t* cr = beginPlatformPaint(); |
| PangoLayout* layout = pango_cairo_create_layout(cr); |
| @@ -224,16 +227,15 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, |
| pango_layout_set_height(layout, h * PANGO_SCALE); |
| cairo_save(cr); |
| - cairo_set_source_rgba(cr, |
| - SkColorGetR(color) / 255.0, |
| - SkColorGetG(color) / 255.0, |
| - SkColorGetB(color) / 255.0, |
| - SkColorGetA(color) / 255.0); |
| int width, height; |
| pango_layout_get_pixel_size(layout, &width, &height); |
| - cairo_rectangle(cr, x, y, w, h); |
| + // Use a bigger clip rect for text with halo. |
| + if (has_halo) |
| + cairo_rectangle(cr, x - 1, y - 1, w + 2, h + 2); |
| + else |
| + cairo_rectangle(cr, x, y, w, h); |
| cairo_clip(cr); |
| if (flags & Canvas::TEXT_VALIGN_TOP) { |
| @@ -245,8 +247,46 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, |
| y += ((h - height) / 2); |
| } |
| - cairo_move_to(cr, x, y); |
| - pango_cairo_show_layout(cr, layout); |
| + if (has_halo) { |
| + CanvasSkia text_canvas(w + 2, h + 2, false); |
| + text_canvas.FillRectInt(static_cast<SkColor>(0), 0, 0, w + 2, h + 2); |
| + |
| + cairo_t* text_cr = text_canvas.beginPlatformPaint(); |
| + |
| + cairo_move_to(text_cr, 1, 1); |
| + pango_cairo_layout_path(text_cr, layout); |
| + |
| + cairo_set_source_rgba(text_cr, |
| + SkColorGetR(halo_color) / 255.0, |
| + SkColorGetG(halo_color) / 255.0, |
| + SkColorGetB(halo_color) / 255.0, |
| + SkColorGetA(halo_color) / 255.0); |
| + cairo_set_line_width(text_cr, 2.0); |
| + cairo_stroke_preserve(text_cr); |
| + |
| + cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); |
| + cairo_set_source_rgba(text_cr, |
| + SkColorGetR(text_color) / 255.0, |
| + SkColorGetG(text_color) / 255.0, |
| + SkColorGetB(text_color) / 255.0, |
| + SkColorGetA(text_color) / 255.0); |
| + cairo_fill(text_cr); |
| + |
| + text_canvas.endPlatformPaint(); |
| + |
| + const SkBitmap& text_bitmap = const_cast<SkBitmap&>( |
| + text_canvas.getTopPlatformDevice().accessBitmap(false)); |
| + DrawBitmapInt(text_bitmap, x - 1, y - 1); |
| + } else { |
| + cairo_move_to(cr, x, y); |
| + cairo_set_source_rgba(cr, |
| + SkColorGetR(text_color) / 255.0, |
| + SkColorGetG(text_color) / 255.0, |
| + SkColorGetB(text_color) / 255.0, |
| + SkColorGetA(text_color) / 255.0); |
| + pango_cairo_show_layout(cr, layout); |
| + } |
| + |
| if (font.GetStyle() & gfx::Font::UNDERLINED) { |
| gfx::PlatformFontGtk* platform_font = |
| static_cast<gfx::PlatformFontGtk*>(font.platform_font()); |
| @@ -263,6 +303,14 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, |
| // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. |
| } |
| +void CanvasSkia::DrawStringInt(const std::wstring& text, |
| + const gfx::Font& font, |
| + const SkColor& color, |
| + int x, int y, int w, int h, |
| + int flags) { |
| + DrawStringWithHalo(text, font, color, color, x, y, w, h, flags); |
| +} |
| + |
| void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { |
| if (!pixbuf) { |
| NOTREACHED(); |