1 <svg width=
"100%" height=
"100%" xmlns=
"http://www.w3.org/2000/svg" class=
"reftest-wait">
3 <foreignObject><canvas xmlns=
"http://www.w3.org/1999/xhtml" id=
"canvas"/></foreignObject>
5 <rect width=
"100%" height=
"100%" fill=
"lime"/>
8 <text dominant-baseline=
"hanging" x=
"70" y=
"70">hanging
</text>
9 <text dominant-baseline=
"mathematical" x=
"70" y=
"140">mathematical
</text>
13 <text id=
"hanging" x=
"70" y=
"70" dy=
"0">hanging
</text>
14 <text id=
"mathematical" x=
"70" y=
"140" dy=
"0">mathematical
</text>
19 font: bold
30px Verdana, Helvetica, Arial, sans-serif;
23 function cover(id, offset) {
24 let element = document.getElementById(id);
25 element.dy.baseVal[
0].value = offset;
26 let rect = document.createElementNS(
"http://www.w3.org/2000/svg",
"rect");
27 let bbox = element.getBBox();
28 rect.x.baseVal.value = bbox.x;
29 rect.y.baseVal.value = bbox.y;
30 rect.width.baseVal.value = bbox.width;
31 rect.height.baseVal.value = bbox.height;
32 element.parentElement.appendChild(rect);
35 const canvas = document.getElementById('canvas');
36 const ctx = canvas.getContext('
2d');
37 ctx.font = 'bold
30px Verdana, Helvetica, Arial, sans-serif';
40 let textMetrics = ctx.measureText(text);
42 cover(
"hanging", textMetrics.actualBoundingBoxAscent *
1.1);
44 cover(
"mathematical", textMetrics.actualBoundingBoxAscent /
2 *
1.4);
46 document.documentElement.removeAttribute('class');