| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gfx/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/base/range/range.h" | 10 #include "ui/base/range/range.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 SkColor halo_color_in, | 370 SkColor halo_color_in, |
| 371 int x, int y, int w, int h, | 371 int x, int y, int w, int h, |
| 372 int flags) { | 372 int flags) { |
| 373 // Some callers will have semitransparent halo colors, which we don't handle | 373 // Some callers will have semitransparent halo colors, which we don't handle |
| 374 // (since the resulting image can have 1-bit transparency only). | 374 // (since the resulting image can have 1-bit transparency only). |
| 375 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF); | 375 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF); |
| 376 | 376 |
| 377 // Create a temporary buffer filled with the halo color. It must leave room | 377 // Create a temporary buffer filled with the halo color. It must leave room |
| 378 // for the 1-pixel border around the text. | 378 // for the 1-pixel border around the text. |
| 379 Size size(w + 2, h + 2); | 379 Size size(w + 2, h + 2); |
| 380 Canvas text_canvas(size, true); | 380 Canvas text_canvas(size, scale_factor(), true); |
| 381 SkPaint bkgnd_paint; | 381 SkPaint bkgnd_paint; |
| 382 bkgnd_paint.setColor(halo_color); | 382 bkgnd_paint.setColor(halo_color); |
| 383 text_canvas.DrawRect(gfx::Rect(size), bkgnd_paint); | 383 text_canvas.DrawRect(gfx::Rect(size), bkgnd_paint); |
| 384 | 384 |
| 385 // Draw the text into the temporary buffer. This will have correct | 385 // Draw the text into the temporary buffer. This will have correct |
| 386 // ClearType since the background color is the same as the halo color. | 386 // ClearType since the background color is the same as the halo color. |
| 387 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags); | 387 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags); |
| 388 | 388 |
| 389 uint32_t halo_premul = SkPreMultiplyColor(halo_color); | 389 uint32_t halo_premul = SkPreMultiplyColor(halo_color); |
| 390 SkBitmap& text_bitmap = const_cast<SkBitmap&>( | 390 SkBitmap& text_bitmap = const_cast<SkBitmap&>( |
| 391 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true)); | 391 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true)); |
| 392 | 392 |
| 393 for (int cur_y = 0; cur_y < h + 2; cur_y++) { | 393 for (int cur_y = 0; cur_y < text_bitmap.height(); cur_y++) { |
| 394 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); | 394 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); |
| 395 for (int cur_x = 0; cur_x < w + 2; cur_x++) { | 395 for (int cur_x = 0; cur_x < text_bitmap.width(); cur_x++) { |
| 396 if (text_row[cur_x] == halo_premul) { | 396 if (text_row[cur_x] == halo_premul) { |
| 397 // This pixel was not touched by the text routines. See if it borders | 397 // This pixel was not touched by the text routines. See if it borders |
| 398 // a touched pixel in any of the 4 directions (not diagonally). | 398 // a touched pixel in any of the 4 directions (not diagonally). |
| 399 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) | 399 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) |
| 400 text_row[cur_x] = 0; // Make transparent. | 400 text_row[cur_x] = 0; // Make transparent. |
| 401 } else { | 401 } else { |
| 402 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. | 402 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 // Draw the halo bitmap with blur. | 407 // Draw the halo bitmap with blur. |
| 408 DrawImageInt(text_bitmap, x - 1, y - 1); | 408 DrawImageInt(gfx::ImageSkiaRep(text_bitmap, text_canvas.scale_factor()), |
| 409 x - 1, y - 1); |
| 409 } | 410 } |
| 410 | 411 |
| 411 void Canvas::DrawFadeTruncatingString( | 412 void Canvas::DrawFadeTruncatingString( |
| 412 const string16& text, | 413 const string16& text, |
| 413 TruncateFadeMode truncate_mode, | 414 TruncateFadeMode truncate_mode, |
| 414 size_t desired_characters_to_truncate_from_head, | 415 size_t desired_characters_to_truncate_from_head, |
| 415 const gfx::Font& font, | 416 const gfx::Font& font, |
| 416 SkColor color, | 417 SkColor color, |
| 417 const gfx::Rect& display_rect) { | 418 const gfx::Rect& display_rect) { |
| 418 int flags = NO_ELLIPSIS; | 419 int flags = NO_ELLIPSIS; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 rect.set_height(line_height); | 474 rect.set_height(line_height); |
| 474 render_text->SetDisplayRect(rect); | 475 render_text->SetDisplayRect(rect); |
| 475 | 476 |
| 476 canvas_->save(SkCanvas::kClip_SaveFlag); | 477 canvas_->save(SkCanvas::kClip_SaveFlag); |
| 477 ClipRect(display_rect); | 478 ClipRect(display_rect); |
| 478 render_text->Draw(this); | 479 render_text->Draw(this); |
| 479 canvas_->restore(); | 480 canvas_->restore(); |
| 480 } | 481 } |
| 481 | 482 |
| 482 } // namespace gfx | 483 } // namespace gfx |
| OLD | NEW |