| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/chrome_canvas.h" | 5 #include "app/gfx/chrome_canvas.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/gfx/chrome_font.h" | 9 #include "app/gfx/chrome_font.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 | 123 |
| 124 ChromeCanvas::ChromeCanvas() : skia::PlatformCanvasWin() { | 124 ChromeCanvas::ChromeCanvas() : skia::PlatformCanvasWin() { |
| 125 } | 125 } |
| 126 | 126 |
| 127 ChromeCanvas::~ChromeCanvas() { | 127 ChromeCanvas::~ChromeCanvas() { |
| 128 } | 128 } |
| 129 | 129 |
| 130 // static | 130 // static |
| 131 void ChromeCanvas::SizeStringInt(const std::wstring& text, | 131 void ChromeCanvas::SizeStringInt(const std::wstring& text, |
| 132 const ChromeFont& font, | 132 const gfx::Font& font, |
| 133 int *width, int *height, int flags) { | 133 int *width, int *height, int flags) { |
| 134 HDC dc = GetDC(NULL); | 134 HDC dc = GetDC(NULL); |
| 135 HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.hfont())); | 135 HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.hfont())); |
| 136 RECT b; | 136 RECT b; |
| 137 b.left = 0; | 137 b.left = 0; |
| 138 b.top = 0; | 138 b.top = 0; |
| 139 b.right = *width; | 139 b.right = *width; |
| 140 if (b.right == 0 && !text.empty()) { | 140 if (b.right == 0 && !text.empty()) { |
| 141 // Width needs to be at least 1 or else DoDrawText will not resize it. | 141 // Width needs to be at least 1 or else DoDrawText will not resize it. |
| 142 b.right = 1; | 142 b.right = 1; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // deletes the font and the DC lives longer. | 175 // deletes the font and the DC lives longer. |
| 176 SelectObject(dc, old_font); | 176 SelectObject(dc, old_font); |
| 177 | 177 |
| 178 // Windows will have cleared the alpha channel of the text we drew. Assume | 178 // Windows will have cleared the alpha channel of the text we drew. Assume |
| 179 // we're drawing to an opaque surface, or at least the text rect area is | 179 // we're drawing to an opaque surface, or at least the text rect area is |
| 180 // opaque. | 180 // opaque. |
| 181 getTopPlatformDevice().makeOpaque(x, y, w, h); | 181 getTopPlatformDevice().makeOpaque(x, y, w, h); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void ChromeCanvas::DrawStringInt(const std::wstring& text, | 184 void ChromeCanvas::DrawStringInt(const std::wstring& text, |
| 185 const ChromeFont& font, | 185 const gfx::Font& font, |
| 186 const SkColor& color, | 186 const SkColor& color, |
| 187 int x, int y, int w, int h, int flags) { | 187 int x, int y, int w, int h, int flags) { |
| 188 DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); | 188 DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If | 191 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If |
| 192 // any of them are not the halo color, returns true. This defines the halo of | 192 // any of them are not the halo color, returns true. This defines the halo of |
| 193 // pixels that will appear around the text. Note that we have to check each | 193 // pixels that will appear around the text. Note that we have to check each |
| 194 // pixel against both the halo color and transparent since DrawStringWithHalo | 194 // pixel against both the halo color and transparent since DrawStringWithHalo |
| 195 // will modify the bitmap as it goes, and clears pixels shouldn't count as | 195 // will modify the bitmap as it goes, and clears pixels shouldn't count as |
| (...skipping 13 matching lines...) Expand all Loading... |
| 209 *bitmap.getAddr32(x, y - 1) != 0) | 209 *bitmap.getAddr32(x, y - 1) != 0) |
| 210 return true; // Touched pixel above. | 210 return true; // Touched pixel above. |
| 211 if (y < bitmap.height() - 1 && | 211 if (y < bitmap.height() - 1 && |
| 212 *bitmap.getAddr32(x, y + 1) != halo_color && | 212 *bitmap.getAddr32(x, y + 1) != halo_color && |
| 213 *bitmap.getAddr32(x, y + 1) != 0) | 213 *bitmap.getAddr32(x, y + 1) != 0) |
| 214 return true; // Touched pixel below. | 214 return true; // Touched pixel below. |
| 215 return false; | 215 return false; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void ChromeCanvas::DrawStringWithHalo(const std::wstring& text, | 218 void ChromeCanvas::DrawStringWithHalo(const std::wstring& text, |
| 219 const ChromeFont& font, | 219 const gfx::Font& font, |
| 220 const SkColor& text_color, | 220 const SkColor& text_color, |
| 221 const SkColor& halo_color_in, | 221 const SkColor& halo_color_in, |
| 222 int x, int y, int w, int h, | 222 int x, int y, int w, int h, |
| 223 int flags) { | 223 int flags) { |
| 224 // Some callers will have semitransparent halo colors, which we don't handle | 224 // Some callers will have semitransparent halo colors, which we don't handle |
| 225 // (since the resulting image can have 1-bit transparency only). | 225 // (since the resulting image can have 1-bit transparency only). |
| 226 SkColor halo_color = halo_color_in | 0xFF000000; | 226 SkColor halo_color = halo_color_in | 0xFF000000; |
| 227 | 227 |
| 228 // Create a temporary buffer filled with the halo color. It must leave room | 228 // Create a temporary buffer filled with the halo color. It must leave room |
| 229 // for the 1-pixel border around the text. | 229 // for the 1-pixel border around the text. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 255 text_row[cur_x] = 0; // Make transparent. | 255 text_row[cur_x] = 0; // Make transparent. |
| 256 } else { | 256 } else { |
| 257 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. | 257 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 // Draw the halo bitmap with blur. | 262 // Draw the halo bitmap with blur. |
| 263 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); | 263 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); |
| 264 } | 264 } |
| OLD | NEW |