diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/svg/test/test_text_lengthAdjust.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/svg/test/test_text_lengthAdjust.html')
-rw-r--r-- | dom/svg/test/test_text_lengthAdjust.html | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/dom/svg/test/test_text_lengthAdjust.html b/dom/svg/test/test_text_lengthAdjust.html new file mode 100644 index 0000000000..21c2454451 --- /dev/null +++ b/dom/svg/test/test_text_lengthAdjust.html @@ -0,0 +1,106 @@ +<!DOCTYPE html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=569722 +--> +<head> + <meta charset=UTF-8> + <title>Test for Bug 569722</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=569722">Mozilla Bug 569722</a> +<p id="display"></p> +<div id="content"> + <svg width="400" height="200"> + <text x="0" y="100" style="font: 16px sans-serif">aaa</text> + </svg> +</div> + +<pre id="test"> +<script class="testbody" type="application/javascript"> +SimpleTest.waitForExplicitFinish(); + +function close(x, y, message) { + ok(Math.abs(x - y) < 1e-4, message); +} + +function runTest() { + var text = document.querySelector("text"); + + // get the original length + var length = text.getComputedTextLength(); + + // get the original glyph positions + var startPositions = [], + endPositions = [], + extents = []; + for (let i = 0; i < 3; i++) { + startPositions.push(text.getStartPositionOfChar(i)); + endPositions.push(text.getEndPositionOfChar(i)); + extents.push(text.getExtentOfChar(i)); + } + + // widths should all be the same + is(extents[0].width, extents[1].width); + is(extents[0].width, extents[2].width); + + var checkCharNumAtPosition = function(x, y, i) { + var p = document.querySelector("svg").createSVGPoint(); + p.x = x; + p.y = y; + is(text.getCharNumAtPosition(p), i, "getCharNumAtPosition(" + i + ")"); + }; + + var checkPositions = function(start, end, width) { + for (let i = 0; i < 3; i++) { + // check their positions + close(text.getStartPositionOfChar(i).x, start[i], "start position of glyph " + i); + close(text.getEndPositionOfChar(i).x, end[i], "end position of glyph " + i); + close(text.getExtentOfChar(i).x, start[i], "left edge of extent of glyph " + i); + close(text.getExtentOfChar(i).width, width, "width of glyph " + i); + checkCharNumAtPosition((start[i] + end[i]) / 2, 100, i); + } + }; + + var w = extents[0].width; + + var doLengthAdjustSpacingTest = function() { + // getComputedTextLength should return the sum of the advances, and since + // we are just changing the positions of the glyphs, it should be the same + // as without a textLength="" attribute + close(text.getComputedTextLength(), length, "getComputedTextLength when lengthAdjust=\"spacing\""); + + // expected start and end positions of the glyphs + var start = [0, 50 - w / 2, 100 - w]; + var end = [w, 50 + w / 2, 100]; + checkPositions(start, end, w); + }; + + // switch to adjust glyph positions, using the default value of lengthAdjust="" + text.setAttribute("textLength", "100"); + doLengthAdjustSpacingTest(); + // then with an explicit lengthAdjust="spacing" + text.setAttribute("lengthAdjust", "spacing"); + doLengthAdjustSpacingTest(); + + // now test with lengthAdjust="spacingAndGlyphs" + text.setAttribute("lengthAdjust", "spacingAndGlyphs"); + + // now that each glyph is stretched, the total advance should be the textLength + close(text.getComputedTextLength(), 100, "getComputedTextLength when lengthAdjust=\"spacingAndGlyphs\""); + + // expected start and end positions of the glyphs + var start = [0, 33.3333, 66.6666]; + var end = [33.3333, 66.6666, 100]; + checkPositions(start, end, 33.3333); + + SimpleTest.finish(); +} + +window.addEventListener("load", runTest); +</script> +</pre> +</body> +</html> |