OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <title>SVGlength tests</title> | 2 <title>SVGlength tests</title> |
3 <script src=../../resources/testharness.js></script> | 3 <script src=../../resources/testharness.js></script> |
4 <script src=../../resources/testharnessreport.js></script> | 4 <script src=../../resources/testharnessreport.js></script> |
5 <div id="testcontainer"> | 5 <div id="testcontainer"> |
6 <svg width="1" height="1" visibility="hidden"> | 6 <svg width="1" height="1" visibility="hidden"> |
7 </svg> | 7 </svg> |
8 </div> | 8 </div> |
9 <div id=log></div> | 9 <div id=log></div> |
10 <script> | 10 <script> |
11 var svg = document.querySelector("svg"); | 11 var svg = document.querySelector("svg"); |
12 var EPSILON = Math.pow(2, -8); | 12 var EPSILON = Math.pow(2, -8); |
13 var lengths = [ 10, 0, 360, 500, 90, 180, 45, 25.9]; | 13 var lengths = [ 10, 0, 360, 500, 90, 180, 45, 25.9]; |
14 | 14 |
15 var units = { | 15 var units = { |
16 "" : 1, | 16 "" : 1, |
17 "%": 2, | 17 "%": 2, |
18 "em": 3, | 18 "em": 3, |
19 "ex": 4, | 19 "ex": 4, |
20 "px": 5, | 20 "px": 5, |
21 "cm": 6, | 21 "cm": 6, |
22 "mm": 7, | 22 "mm": 7, |
23 "in": 8, | 23 "in": 8, |
24 "pt": 9, | 24 "pt": 9, |
25 "pc": 10, | 25 "pc": 10, |
26 "rem": 11 | 26 "rem": 11, |
| 27 "ch":12 |
27 }; | 28 }; |
28 var highestExposedUnit = 10; // SVG_LENGTHTYPE_PC | 29 var highestExposedUnit = 10; // SVG_LENGTHTYPE_PC |
29 var unitconstants = { | 30 var unitconstants = { |
30 "UNKNOWN" : 0, | 31 "UNKNOWN" : 0, |
31 "NUMBER": 1, | 32 "NUMBER": 1, |
32 "PERCENTAGE": 2, | 33 "PERCENTAGE": 2, |
33 "EMS": 3, | 34 "EMS": 3, |
34 "EXS": 4, | 35 "EXS": 4, |
35 "PX": 5, | 36 "PX": 5, |
36 "CM": 6, | 37 "CM": 6, |
37 "MM": 7, | 38 "MM": 7, |
38 "IN": 8, | 39 "IN": 8, |
39 "PT": 9, | 40 "PT": 9, |
40 "PC": 10, | 41 "PC": 10, |
41 }; | 42 }; |
42 var nonexposedunitconstants = { | 43 var nonexposedunitconstants = { |
43 "REMS": 11 | 44 "REMS": 11, |
| 45 "CHS":12 |
44 }; | 46 }; |
45 | 47 |
46 function convertTo(value, unit, outunit) { | 48 function convertTo(value, unit, outunit) { |
47 var userUnits; | 49 var userUnits; |
48 var cssPixelsPerInch = 96; | 50 var cssPixelsPerInch = 96; |
49 var cssPixelsPerCentimeter = cssPixelsPerInch / 2.54; //2.54 cm/in | 51 var cssPixelsPerCentimeter = cssPixelsPerInch / 2.54; //2.54 cm/in |
50 var cssPixelsPerMillimeter = cssPixelsPerCentimeter / 10; | 52 var cssPixelsPerMillimeter = cssPixelsPerCentimeter / 10; |
51 var cssPixelsPerPoint = cssPixelsPerInch / 72; | 53 var cssPixelsPerPoint = cssPixelsPerInch / 72; |
52 var cssPixelsPerPica = cssPixelsPerInch / 6; | 54 var cssPixelsPerPica = cssPixelsPerInch / 6; |
53 | 55 |
54 switch(unit) { | 56 switch(unit) { |
55 case "": | 57 case "": |
56 case "px": | 58 case "px": |
57 userUnits = value; | 59 userUnits = value; |
58 break; | 60 break; |
59 case "%": | 61 case "%": |
60 case "em": | 62 case "em": |
61 case "ex": | 63 case "ex": |
62 case "rem": | 64 case "rem": |
| 65 case "ch": |
63 return value; | 66 return value; |
64 case "cm": | 67 case "cm": |
65 userUnits = value * cssPixelsPerCentimeter; | 68 userUnits = value * cssPixelsPerCentimeter; |
66 break; | 69 break; |
67 case "mm": | 70 case "mm": |
68 userUnits = value * cssPixelsPerMillimeter; | 71 userUnits = value * cssPixelsPerMillimeter; |
69 break; | 72 break; |
70 case "in": | 73 case "in": |
71 userUnits = value * cssPixelsPerInch; | 74 userUnits = value * cssPixelsPerInch; |
72 break; | 75 break; |
73 case "pt": | 76 case "pt": |
74 userUnits = value * cssPixelsPerPoint; | 77 userUnits = value * cssPixelsPerPoint; |
75 break; | 78 break; |
76 case "pc": | 79 case "pc": |
77 userUnits = value * cssPixelsPerPica; | 80 userUnits = value * cssPixelsPerPica; |
78 break; | 81 break; |
79 } | 82 } |
80 | 83 |
81 switch(outunit) { | 84 switch(outunit) { |
82 case "": | 85 case "": |
83 case "px": | 86 case "px": |
84 return userUnits; | 87 return userUnits; |
85 case "%": | 88 case "%": |
86 case "em": | 89 case "em": |
87 case "ex": | 90 case "ex": |
88 case "rem": | 91 case "rem": |
| 92 case "ch": |
89 return value; | 93 return value; |
90 case "cm": | 94 case "cm": |
91 return userUnits / cssPixelsPerCentimeter; | 95 return userUnits / cssPixelsPerCentimeter; |
92 case "mm": | 96 case "mm": |
93 return userUnits / cssPixelsPerMillimeter; | 97 return userUnits / cssPixelsPerMillimeter; |
94 case "in": | 98 case "in": |
95 return userUnits / cssPixelsPerInch; | 99 return userUnits / cssPixelsPerInch; |
96 case "pt": | 100 case "pt": |
97 return userUnits / cssPixelsPerPoint; | 101 return userUnits / cssPixelsPerPoint; |
98 case "pc": | 102 case "pc": |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 else | 184 else |
181 assert_equals(result, ref.valueAsString); | 185 assert_equals(result, ref.valueAsString); |
182 }, "newValueSpecifiedUnits(" + units[unit] + ", " + length + ")" ); | 186 }, "newValueSpecifiedUnits(" + units[unit] + ", " + length + ")" ); |
183 }; | 187 }; |
184 | 188 |
185 } | 189 } |
186 }); | 190 }); |
187 | 191 |
188 | 192 |
189 </script> | 193 </script> |
OLD | NEW |