wpt / svg / text / scripted / getcharnumatposition-zoomed.html

Status: FAIL | Duration: 47ms | Subtests: 0/1 | Open test on wpt.live | wpt.fyi

/svg/text/scripted/getcharnumatposition-zoomed.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>SVGTextContentElement.getCharNumAtPosition</title>
<link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/text.html#__svg__SVGTextContentElement__getCharNumAtPosition">
<link rel="stylesheet" href="/fonts/ahem.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<svg width="800" height="600">
<style>
text {
  font: 20px/1 Ahem;
  zoom: 3;
}
</style>
<text><tspan id="htb" x="40" y="100">abc</tspan></text>
</svg>

<script>
function newPoint(x, y) {
  const p = document.querySelector('svg').createSVGPoint();
  p.x = x;
  p.y = y;
  return p;
}

setup({ explicit_done: true });

document.fonts.ready.then(() => {
  test(() => {
    const element = document.querySelector('#htb');
    assert_equals(element.getNumberOfChars(), 3);
    const start = 40;
    assert_equals(element.getCharNumAtPosition(newPoint(start - 10, 100)), -1);
    assert_equals(element.getCharNumAtPosition(newPoint(start + 10, 100)), 0);
    assert_equals(element.getCharNumAtPosition(newPoint(start + 30, 100)), 1);
    assert_equals(element.getCharNumAtPosition(newPoint(start + 50, 100)), 2);
    assert_equals(element.getCharNumAtPosition(newPoint(start + 70, 100)), -1);
  }, 'CSS zoomed text');

  done();
});
</script>