| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes
t.dart'; | 5 library canvas_rendering_context_2d_test; import '../../pkg/unittest/lib/unittes
t.dart'; |
| 6 import '../../pkg/unittest/lib/html_individual_config.dart'; | 6 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'dart:math'; | 8 import 'dart:math'; |
| 9 | 9 |
| 10 // Some rounding errors in the browsers. | 10 // Some rounding errors in the browsers. |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 var other = context.createImageDataFromImageData(imageData); | 667 var other = context.createImageDataFromImageData(imageData); |
| 668 expect(other.width, 15); | 668 expect(other.width, 15); |
| 669 expect(other.height, 15); | 669 expect(other.height, 15); |
| 670 }); | 670 }); |
| 671 | 671 |
| 672 test('createPattern', () { | 672 test('createPattern', () { |
| 673 var pattern = context.createPattern(new CanvasElement(), ''); | 673 var pattern = context.createPattern(new CanvasElement(), ''); |
| 674 //var pattern2 = context.createPatternFromImage(new ImageElement(), ''); | 674 //var pattern2 = context.createPatternFromImage(new ImageElement(), ''); |
| 675 }); | 675 }); |
| 676 }); | 676 }); |
| 677 |
| 678 group('fillText', () { |
| 679 setUp(setupFunc); |
| 680 tearDown(tearDownFunc); |
| 681 |
| 682 test('without maxWidth', () { |
| 683 context.font = '40pt Garamond'; |
| 684 context.fillStyle = 'blue'; |
| 685 |
| 686 // Draw a blue box. |
| 687 context.fillText('█', 50, 50); |
| 688 |
| 689 var width = context.measureText('█').width; |
| 690 |
| 691 checkPixel(readPixel(50, 50), [0, 0, 255, 255]); |
| 692 checkPixel(readPixel(60, 50), [0, 0, 255, 255]); |
| 693 |
| 694 expectPixelUnfilled(40, 50); |
| 695 expectPixelFilled(50, 50); |
| 696 expectPixelFilled(60, 50); |
| 697 |
| 698 // The box does not draw after `width` pixels. |
| 699 expectPixelFilled(50 + width, 50); |
| 700 expectPixelUnfilled(50 + width + 1, 50); |
| 701 }); |
| 702 |
| 703 test('with maxWidth null', () { |
| 704 context.font = '40pt Garamond'; |
| 705 context.fillStyle = 'blue'; |
| 706 |
| 707 // Draw a blue box with null maxWidth. |
| 708 context.fillText('█', 50, 50, null); |
| 709 |
| 710 var width = context.measureText('█').width; |
| 711 |
| 712 checkPixel(readPixel(50, 50), [0, 0, 255, 255]); |
| 713 checkPixel(readPixel(60, 50), [0, 0, 255, 255]); |
| 714 |
| 715 expectPixelUnfilled(40, 50); |
| 716 expectPixelFilled(50, 50); |
| 717 expectPixelFilled(60, 50); |
| 718 |
| 719 // The box does not draw after `width` pixels. |
| 720 expectPixelFilled(50 + width, 50); |
| 721 expectPixelUnfilled(50 + width + 1, 50); |
| 722 }); |
| 723 |
| 724 test('with maxWidth defined', () { |
| 725 context.font = '40pt Garamond'; |
| 726 context.fillStyle = 'blue'; |
| 727 |
| 728 // Draw a blue box that's at most 20 pixels wide. |
| 729 context.fillText('█', 50, 50, 20); |
| 730 |
| 731 checkPixel(readPixel(50, 50), [0, 0, 255, 255]); |
| 732 checkPixel(readPixel(60, 50), [0, 0, 255, 255]); |
| 733 |
| 734 // The box does not draw after 20 pixels. |
| 735 expectPixelUnfilled(40, 50); |
| 736 expectPixelUnfilled(71, 50); |
| 737 expectPixelUnfilled(90, 50); |
| 738 expectPixelFilled(50, 50); |
| 739 expectPixelFilled(60, 50); |
| 740 }); |
| 741 }); |
| 677 } | 742 } |
| OLD | NEW |