OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../../resources/testharness.js"></script> | |
3 <script src="../../resources/testharnessreport.js"></script> | |
4 <svg width="500" height="500" visibility="hidden"> | |
5 <rect width="1" height="1"/> | |
6 </svg> | |
7 <script> | |
8 var rectElement = document.querySelector("rect"); | |
fs
2016/06/29 09:28:17
Doesn't need to be global.
Shanmuga Pandi
2016/07/15 12:18:22
Acknowledged.
| |
9 var svgWidth = 500; | |
10 var EPSILON = Math.pow(2, -8); | |
11 var cssPixelsPerInch = 96; | |
12 var cssPixelsPerCentimeter = cssPixelsPerInch / 2.54; //2.54 cm/in | |
13 var cssPixelsPerMillimeter = cssPixelsPerCentimeter / 10; | |
14 var cssPixelsPerPoint = cssPixelsPerInch / 72; | |
15 var cssPixelsPerPica = cssPixelsPerInch / 6; | |
16 var expected; | |
17 var rect; | |
fs
2016/06/29 09:28:17
Neither do these two.
Shanmuga Pandi
2016/07/15 12:18:22
Acknowledged.
| |
18 | |
19 function svgViewportWidthPercent() | |
20 { | |
fs
2016/06/29 09:28:17
Move to previous line.
Alternatively just open-co
| |
21 return (svgWidth / 100); | |
fs
2016/06/29 09:28:17
Drop parenthesis.
| |
22 } | |
23 | |
24 test(function() { | |
25 rectElement.setAttribute("width", "calc(10 + 10)"); | |
26 expected = 20; | |
27 rect = rectElement.getBoundingClientRect(); | |
28 assert_approx_equals(rect.width, expected, EPSILON); | |
fs
2016/06/29 09:28:17
For some reduction in boilerplate, I think a struc
| |
29 | |
30 rectElement.setAttribute("width", "calc(10mm + 10)"); | |
31 expected = (10 * cssPixelsPerMillimeter) + 10; | |
32 rect = rectElement.getBoundingClientRect(); | |
33 assert_approx_equals(rect.width, expected, EPSILON); | |
34 | |
35 rectElement.setAttribute("width", "calc(10% + 10)"); | |
36 expected = (10 * svgViewportWidthPercent()) + 10; | |
37 rect = rectElement.getBoundingClientRect(); | |
38 assert_approx_equals(rect.width, expected, EPSILON); | |
39 | |
40 rectElement.setAttribute("width", "calc(1cm + 2in + 1cm + 2)"); | |
41 expected = (2 * cssPixelsPerInch) + (2 * cssPixelsPerCentimeter) + 2; | |
42 rect = rectElement.getBoundingClientRect(); | |
43 assert_approx_equals(rect.width, expected, EPSILON); | |
44 | |
45 rectElement.setAttribute("width", "calc(10% + 10 + 2% + 10pc)"); | |
46 expected = (12 * svgViewportWidthPercent()) + 10 + (10 * cssPixelsPerPica); | |
47 rect = rectElement.getBoundingClientRect(); | |
48 assert_approx_equals(rect.width, expected, EPSILON); | |
49 | |
fs
2016/06/29 09:28:17
Drop blank line.
| |
50 }, "Tests calc() in svgLength"); | |
51 | |
52 </script> | |
OLD | NEW |