lengthadjust.html (2042B)
1 <!DOCTYPE html> 2 <title>lengthAdjust content/IDL attribute</title> 3 <link rel="help" href="https://svgwg.org/svg2-draft/text.html#TextElementLengthAdjustAttribute"> 4 <link rel="help" href="https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getComputedTextLength"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 8 <svg> 9 <text x="0" y="215" textLength="200">Stretched text</text> 10 <text x="0" y="215" textLength="200">Stretched text</text> 11 </svg> 12 13 <script> 14 test(() => { 15 const text = document.querySelectorAll('text')[0]; 16 assert_equals(text.getAttribute('lengthAdjust'), null); 17 assert_equals(text.lengthAdjust.baseVal, SVGTextContentElement.LENGTHADJUST_SPACING); 18 assert_equals(text.textLength.baseVal.value, 200); 19 let lastLength = text.getComputedTextLength(); 20 assert_between_exclusive(lastLength, 0, 200); 21 22 text.setAttribute('lengthAdjust', 'spacingAndGlyphs'); 23 assert_equals(text.lengthAdjust.baseVal, SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS); 24 assert_equals(text.textLength.baseVal.value, 200); 25 assert_greater_than(text.getComputedTextLength(), lastLength); 26 }, 'Tests dynamic updates of the "lengthAdjust" content attribute'); 27 28 test(() => { 29 const text = document.querySelectorAll('text')[1]; 30 assert_equals(text.getAttribute('lengthAdjust'), null); 31 assert_equals(text.lengthAdjust.baseVal, SVGTextContentElement.LENGTHADJUST_SPACING); 32 assert_equals(text.textLength.baseVal.value, 200); 33 let lastLength = text.getComputedTextLength(); 34 assert_between_exclusive(lastLength, 0, 200); 35 36 text.lengthAdjust.baseVal = SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS; 37 assert_equals(text.getAttribute('lengthAdjust'), 'spacingAndGlyphs'); 38 assert_equals(text.lengthAdjust.baseVal, SVGTextContentElement.LENGTHADJUST_SPACINGANDGLYPHS); 39 assert_equals(text.textLength.baseVal.value, 200); 40 assert_greater_than(text.getComputedTextLength(), lastLength); 41 }, 'Tests dynamic updates of the "lengthAdjust" IDL attribute'); 42 </script>