OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_skia.h" | 5 #include "ui/gfx/canvas_skia.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // The intensity of black tells us the alpha value of the text. | 207 // The intensity of black tells us the alpha value of the text. |
208 for (int y = draw_rect.top; y < draw_rect.bottom; y++) { | 208 for (int y = draw_rect.top; y < draw_rect.bottom; y++) { |
209 for (int x = draw_rect.left; x < draw_rect.right; x++) { | 209 for (int x = draw_rect.left; x < draw_rect.right; x++) { |
210 // Gets the color directly. DrawText doesn't premultiply alpha so | 210 // Gets the color directly. DrawText doesn't premultiply alpha so |
211 // using SkBitmap::getColor() won't work here. | 211 // using SkBitmap::getColor() won't work here. |
212 SkColor color = *bmp.getAddr32(x, y); | 212 SkColor color = *bmp.getAddr32(x, y); |
213 // Calculate the alpha using the luminance. Since this is black text | 213 // Calculate the alpha using the luminance. Since this is black text |
214 // on a white background the luminosity must be inverted. | 214 // on a white background the luminosity must be inverted. |
215 BYTE alpha = 0xFF - color_utils::GetLuminanceForColor(color); | 215 BYTE alpha = 0xFF - color_utils::GetLuminanceForColor(color); |
216 *bmp.getAddr32(x, y) = SkPreMultiplyColor( | 216 *bmp.getAddr32(x, y) = SkPreMultiplyColor( |
217 SkColorSetARGB(alpha, text_color_r, text_color_b, text_color_g)); | 217 SkColorSetARGB(alpha, text_color_r, text_color_g, text_color_b)); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 bmp_device.EndPlatformPaint(); | 221 bmp_device.EndPlatformPaint(); |
222 } | 222 } |
223 | 223 |
224 // Draws the given text with a fade out gradient. |bmp_device| is a bitmap | 224 // Draws the given text with a fade out gradient. |bmp_device| is a bitmap |
225 // that is used to temporary drawing. The text is drawn in |text_rect| and | 225 // that is used to temporary drawing. The text is drawn in |text_rect| and |
226 // clipped to |draw_rect|. | 226 // clipped to |draw_rect|. |
227 void DrawTextGradientPart(HDC hdc, | 227 void DrawTextGradientPart(HDC hdc, |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 solid_part.width(), solid_part.height()); | 575 solid_part.width(), solid_part.height()); |
576 DrawStringInt(text, font, color, | 576 DrawStringInt(text, font, color, |
577 text_rect.x(), text_rect.y(), | 577 text_rect.x(), text_rect.y(), |
578 text_rect.width(), text_rect.height(), | 578 text_rect.width(), text_rect.height(), |
579 flags); | 579 flags); |
580 restore(); | 580 restore(); |
581 restore(); | 581 restore(); |
582 } | 582 } |
583 | 583 |
584 } // namespace gfx | 584 } // namespace gfx |
OLD | NEW |