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" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/win/scoped_gdi_object.h" | 12 #include "base/win/scoped_gdi_object.h" |
13 #include "skia/ext/bitmap_platform_device.h" | 13 #include "skia/ext/bitmap_platform_device.h" |
14 #include "skia/ext/skia_utils_win.h" | 14 #include "skia/ext/skia_utils_win.h" |
15 #include "third_party/skia/include/core/SkShader.h" | 15 #include "third_party/skia/include/core/SkShader.h" |
16 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
17 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
18 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 19 #include "ui/gfx/render_text.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 static inline int Round(double x) { | 23 static inline int Round(double x) { |
23 // Why oh why is this not in a standard header? | 24 // Why oh why is this not in a standard header? |
24 return static_cast<int>(floor(x + 0.5)); | 25 return static_cast<int>(floor(x + 0.5)); |
25 } | 26 } |
26 | 27 |
27 // We make sure that LTR text we draw in an RTL context is modified | 28 // We make sure that LTR text we draw in an RTL context is modified |
28 // appropriately to make sure it maintains it LTR orientation. | 29 // appropriately to make sure it maintains it LTR orientation. |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 374 } |
374 | 375 |
375 void CanvasSkia::DrawStringInt(const string16& text, | 376 void CanvasSkia::DrawStringInt(const string16& text, |
376 const gfx::Font& font, | 377 const gfx::Font& font, |
377 const SkColor& color, | 378 const SkColor& color, |
378 int x, int y, int w, int h, | 379 int x, int y, int w, int h, |
379 int flags) { | 380 int flags) { |
380 DrawStringInt(text, font.GetNativeFont(), color, x, y, w, h, flags); | 381 DrawStringInt(text, font.GetNativeFont(), color, x, y, w, h, flags); |
381 } | 382 } |
382 | 383 |
| 384 // TODO(msw): Copied from another DrawStringInt. Dig in, understand, and unify. |
| 385 void CanvasSkia::DrawStringInt(const gfx::RenderText& render_text) { |
| 386 SkRect fclip; |
| 387 if (!getClipBounds(&fclip)) |
| 388 return; |
| 389 const gfx::Rect& r = render_text.get_display_rect(); |
| 390 RECT text_bounds = { r.x(), r.y(), r.x() + r.width(), r.y() + r.height() }; |
| 391 SkIRect clip; |
| 392 fclip.round(&clip); |
| 393 if (!clip.intersect(skia::RECTToSkIRect(text_bounds))) |
| 394 return; |
| 395 |
| 396 // TODO(msw): Necessary with Uniscribe? |
| 397 // Clamp the max amount of text we'll draw to 32K. There seem to be bugs in |
| 398 // DrawText() if you e.g. ask it to character-break a no-whitespace string of |
| 399 // length > 43680 (for which it draws nothing), and since we clamped to 2K in |
| 400 // SizeStringInt() we're unlikely to be able to display this much anyway. |
| 401 const int kMaxStringLength = 32768 - 1; // So the trailing \0 fits in 32K. |
| 402 string16 clamped_string(render_text.text().substr(0, kMaxStringLength)); |
| 403 |
| 404 HDC dc; |
| 405 { |
| 406 // TODO(msw): Fix. |
| 407 skia::ScopedPlatformPaint scoped_platform_paint(this); |
| 408 dc = scoped_platform_paint.GetPlatformSurface(); |
| 409 SetBkMode(dc, TRANSPARENT); |
| 410 //int f = ComputeFormatFlags(flags, clamped_string); |
| 411 //DoDrawText(dc, clamped_string, &text_bounds, f); |
| 412 render_text.Draw(dc); |
| 413 } |
| 414 |
| 415 // TODO(msw): Necessary with Uniscribe? |
| 416 // Windows will have cleared the alpha channel of the text we drew. Assume |
| 417 // we're drawing to an opaque surface, or at least the text rect area is |
| 418 // opaque. |
| 419 skia::MakeOpaque(this, clip.fLeft, clip.fTop, clip.width(), |
| 420 clip.height()); |
| 421 } |
| 422 |
383 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If | 423 // Checks each pixel immediately adjacent to the given pixel in the bitmap. If |
384 // any of them are not the halo color, returns true. This defines the halo of | 424 // any of them are not the halo color, returns true. This defines the halo of |
385 // pixels that will appear around the text. Note that we have to check each | 425 // pixels that will appear around the text. Note that we have to check each |
386 // pixel against both the halo color and transparent since DrawStringWithHalo | 426 // pixel against both the halo color and transparent since DrawStringWithHalo |
387 // will modify the bitmap as it goes, and clears pixels shouldn't count as | 427 // will modify the bitmap as it goes, and clears pixels shouldn't count as |
388 // changed. | 428 // changed. |
389 static bool pixelShouldGetHalo(const SkBitmap& bitmap, | 429 static bool pixelShouldGetHalo(const SkBitmap& bitmap, |
390 int x, int y, | 430 int x, int y, |
391 SkColor halo_color) { | 431 SkColor halo_color) { |
392 if (x > 0 && | 432 if (x > 0 && |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 solid_part.width(), solid_part.height()); | 618 solid_part.width(), solid_part.height()); |
579 DrawStringInt(text, font, color, | 619 DrawStringInt(text, font, color, |
580 text_rect.x(), text_rect.y(), | 620 text_rect.x(), text_rect.y(), |
581 text_rect.width(), text_rect.height(), | 621 text_rect.width(), text_rect.height(), |
582 flags); | 622 flags); |
583 restore(); | 623 restore(); |
584 restore(); | 624 restore(); |
585 } | 625 } |
586 | 626 |
587 } // namespace gfx | 627 } // namespace gfx |
OLD | NEW |