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/gfx/font_list.h" | 10 #include "ui/gfx/font_list.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 SkColor halo_color_in, | 343 SkColor halo_color_in, |
344 const Rect& display_rect, | 344 const Rect& display_rect, |
345 int flags) { | 345 int flags) { |
346 // Some callers will have semitransparent halo colors, which we don't handle | 346 // Some callers will have semitransparent halo colors, which we don't handle |
347 // (since the resulting image can have 1-bit transparency only). | 347 // (since the resulting image can have 1-bit transparency only). |
348 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF); | 348 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF); |
349 | 349 |
350 // Create a temporary buffer filled with the halo color. It must leave room | 350 // Create a temporary buffer filled with the halo color. It must leave room |
351 // for the 1-pixel border around the text. | 351 // for the 1-pixel border around the text. |
352 Size size(display_rect.width() + 2, display_rect.height() + 2); | 352 Size size(display_rect.width() + 2, display_rect.height() + 2); |
353 Canvas text_canvas(size, scale_factor(), true); | 353 Canvas text_canvas(size, image_scale(), true); |
354 SkPaint bkgnd_paint; | 354 SkPaint bkgnd_paint; |
355 bkgnd_paint.setColor(halo_color); | 355 bkgnd_paint.setColor(halo_color); |
356 text_canvas.DrawRect(Rect(size), bkgnd_paint); | 356 text_canvas.DrawRect(Rect(size), bkgnd_paint); |
357 | 357 |
358 // Draw the text into the temporary buffer. This will have correct | 358 // Draw the text into the temporary buffer. This will have correct |
359 // ClearType since the background color is the same as the halo color. | 359 // ClearType since the background color is the same as the halo color. |
360 text_canvas.DrawStringRectWithFlags( | 360 text_canvas.DrawStringRectWithFlags( |
361 text, font_list, text_color, | 361 text, font_list, text_color, |
362 Rect(1, 1, display_rect.width(), display_rect.height()), flags); | 362 Rect(1, 1, display_rect.width(), display_rect.height()), flags); |
363 | 363 |
(...skipping 10 matching lines...) Expand all Loading... |
374 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) | 374 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) |
375 text_row[cur_x] = 0; // Make transparent. | 375 text_row[cur_x] = 0; // Make transparent. |
376 } else { | 376 } else { |
377 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. | 377 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. |
378 } | 378 } |
379 } | 379 } |
380 } | 380 } |
381 | 381 |
382 // Draw the halo bitmap with blur. | 382 // Draw the halo bitmap with blur. |
383 ImageSkia text_image = ImageSkia(ImageSkiaRep(text_bitmap, | 383 ImageSkia text_image = ImageSkia(ImageSkiaRep(text_bitmap, |
384 text_canvas.scale_factor())); | 384 text_canvas.image_scale())); |
385 DrawImageInt(text_image, display_rect.x() - 1, display_rect.y() - 1); | 385 DrawImageInt(text_image, display_rect.x() - 1, display_rect.y() - 1); |
386 } | 386 } |
387 | 387 |
388 void Canvas::DrawFadeTruncatingStringRect( | 388 void Canvas::DrawFadeTruncatingStringRect( |
389 const base::string16& text, | 389 const base::string16& text, |
390 TruncateFadeMode truncate_mode, | 390 TruncateFadeMode truncate_mode, |
391 size_t desired_characters_to_truncate_from_head, | 391 size_t desired_characters_to_truncate_from_head, |
392 const FontList& font_list, | 392 const FontList& font_list, |
393 SkColor color, | 393 SkColor color, |
394 const Rect& display_rect) { | 394 const Rect& display_rect) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 size_t desired_characters_to_truncate_from_head, | 463 size_t desired_characters_to_truncate_from_head, |
464 const Font& font, | 464 const Font& font, |
465 SkColor color, | 465 SkColor color, |
466 const Rect& display_rect) { | 466 const Rect& display_rect) { |
467 DrawFadeTruncatingStringRect(text, truncate_mode, | 467 DrawFadeTruncatingStringRect(text, truncate_mode, |
468 desired_characters_to_truncate_from_head, | 468 desired_characters_to_truncate_from_head, |
469 FontList(font), color, display_rect); | 469 FontList(font), color, display_rect); |
470 } | 470 } |
471 | 471 |
472 } // namespace gfx | 472 } // namespace gfx |
OLD | NEW |