OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/canvas_skia.h" | 5 #include "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 "gfx/font.h" | 10 #include "gfx/font.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 flags &= ~gfx::Canvas::CHARACTER_BREAK; | 156 flags &= ~gfx::Canvas::CHARACTER_BREAK; |
157 | 157 |
158 // Weird undocumented behavior: if the width is 0, DoDrawText() won't | 158 // Weird undocumented behavior: if the width is 0, DoDrawText() won't |
159 // calculate a size at all. So set it to 1, which it will then change. | 159 // calculate a size at all. So set it to 1, which it will then change. |
160 if (!text.empty()) | 160 if (!text.empty()) |
161 *width = 1; | 161 *width = 1; |
162 } | 162 } |
163 RECT r = { 0, 0, *width, *height }; | 163 RECT r = { 0, 0, *width, *height }; |
164 | 164 |
165 HDC dc = GetDC(NULL); | 165 HDC dc = GetDC(NULL); |
166 HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.hfont())); | 166 HFONT old_font = static_cast<HFONT>(SelectObject(dc, font.GetNativeFont())); |
167 DoDrawText(dc, clamped_string, &r, | 167 DoDrawText(dc, clamped_string, &r, |
168 ComputeFormatFlags(flags, clamped_string) | DT_CALCRECT); | 168 ComputeFormatFlags(flags, clamped_string) | DT_CALCRECT); |
169 SelectObject(dc, old_font); | 169 SelectObject(dc, old_font); |
170 ReleaseDC(NULL, dc); | 170 ReleaseDC(NULL, dc); |
171 | 171 |
172 *width = r.right; | 172 *width = r.right; |
173 *height = r.bottom; | 173 *height = r.bottom; |
174 } | 174 } |
175 | 175 |
176 void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font, | 176 void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font, |
(...skipping 28 matching lines...) Expand all Loading... |
205 // Windows will have cleared the alpha channel of the text we drew. Assume | 205 // Windows will have cleared the alpha channel of the text we drew. Assume |
206 // we're drawing to an opaque surface, or at least the text rect area is | 206 // we're drawing to an opaque surface, or at least the text rect area is |
207 // opaque. | 207 // opaque. |
208 getTopPlatformDevice().makeOpaque(x, y, w, h); | 208 getTopPlatformDevice().makeOpaque(x, y, w, h); |
209 } | 209 } |
210 | 210 |
211 void CanvasSkia::DrawStringInt(const std::wstring& text, | 211 void CanvasSkia::DrawStringInt(const std::wstring& text, |
212 const gfx::Font& font, | 212 const gfx::Font& font, |
213 const SkColor& color, | 213 const SkColor& color, |
214 int x, int y, int w, int h, int flags) { | 214 int x, int y, int w, int h, int flags) { |
215 DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); | 215 DrawStringInt(text, font.GetNativeFont(), color, x, y, w, h, flags); |
216 } | 216 } |
217 | 217 |
218 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If | 218 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If |
219 // any of them are not the halo color, returns true. This defines the halo of | 219 // any of them are not the halo color, returns true. This defines the halo of |
220 // pixels that will appear around the text. Note that we have to check each | 220 // pixels that will appear around the text. Note that we have to check each |
221 // pixel against both the halo color and transparent since DrawStringWithHalo | 221 // pixel against both the halo color and transparent since DrawStringWithHalo |
222 // will modify the bitmap as it goes, and clears pixels shouldn't count as | 222 // will modify the bitmap as it goes, and clears pixels shouldn't count as |
223 // changed. | 223 // changed. |
224 static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y, | 224 static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y, |
225 SkColor halo_color) { | 225 SkColor halo_color) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. | 284 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. |
285 } | 285 } |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 // Draw the halo bitmap with blur. | 289 // Draw the halo bitmap with blur. |
290 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); | 290 drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1)); |
291 } | 291 } |
292 | 292 |
293 } // namespace gfx | 293 } // namespace gfx |
OLD | NEW |