|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>SVGGraphicsElement.prototype.getBBox for non-rendered elements</title> |
| 3 | +<link rel="help" href="https://svgwg.org/svg2-draft/coords.html#BoundingBoxes"> |
| 4 | +<script src="/resources/testharness.js"></script> |
| 5 | +<script src="/resources/testharnessreport.js"></script> |
| 6 | +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 500 500" width="500px" height="500px"> |
| 7 | + <symbol id="symbol1"> |
| 8 | + <rect id="symbol1_rect" x="50" y="60" width="100" height="150"></rect> |
| 9 | + </symbol> |
| 10 | + <g id="g_none" style="display:none"> |
| 11 | + <rect id="g_none_rect" x="70" y="80" width="200" height="250"></rect> |
| 12 | + </g> |
| 13 | + <rect id="none_rect" x="90" y="100" width="20" height="25" display="none"></rect> |
| 14 | +</svg> |
| 15 | +<script> |
| 16 | + function assert_bbox(id, opt, x, y, width, height, epsilon) { |
| 17 | + if (epsilon == undefined) { |
| 18 | + epsilon = 0.1; |
| 19 | + } |
| 20 | + let bbox = document.getElementById(id).getBBox(); |
| 21 | + assert_approx_equals(bbox.x, x, epsilon, id + ".getBBox().x " + JSON.stringify(opt)); |
| 22 | + assert_approx_equals(bbox.y, y, epsilon, id + ".getBBox().y " + JSON.stringify(opt)); |
| 23 | + assert_approx_equals(bbox.width, width, epsilon, id + ".getBBox().width " + JSON.stringify(opt)); |
| 24 | + assert_approx_equals(bbox.height, height, epsilon, id + ".getBBox().height " + JSON.stringify(opt)); |
| 25 | + } |
| 26 | + |
| 27 | + test(() => { |
| 28 | + assert_bbox("symbol1", {}, 0, 0, 0, 0); |
| 29 | + assert_bbox("symbol1_rect", {}, 50, 60, 100, 150); |
| 30 | + }, "Non-rendered symbol with rect"); |
| 31 | + |
| 32 | + test(() => { |
| 33 | + assert_bbox("g_none", {}, 0, 0, 0, 0); |
| 34 | + assert_bbox("g_none_rect", {}, 70, 80, 200, 250); |
| 35 | + }, "display:none <g> with rect"); |
| 36 | + |
| 37 | + test(() => { |
| 38 | + assert_bbox("none_rect", {}, 90, 100, 20, 25); |
| 39 | + }, "display:none <rect>"); |
| 40 | +</script> |
0 commit comments