blob: 6c4f50fe871b0126548557976e8391c1d973b5fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:html="http://www.w3.org/1999/xhtml">
<title>'textLength' on <textPath> with 'text-anchor' adjustments</title>
<html:script src="/resources/testharness.js"/>
<html:script src="/resources/testharnessreport.js"/>
<html:link rel="stylesheet" href="/fonts/ahem.css"/>
<html:link rel="help" href="https://svgwg.org/svg2-draft/text.html#TextPathElement"/>
<html:link rel="help" href="https://svgwg.org/svg2-draft/text.html#TextElementTextLengthAttribute"/>
<defs>
<path id="p" d="M0,25h100"/>
</defs>
<g font-family="Ahem" font-size="20px">
<text expected-x="0">
<textPath href="#p" textLength="25" lengthAdjust="spacing"
text-anchor="start">XXXX</textPath>
</text>
<text expected-x="0" transform="translate(0 50)">
<textPath href="#p" textLength="25" lengthAdjust="spacingAndGlyphs"
text-anchor="start">XXXX</textPath>
</text>
<text expected-x="37.5">
<textPath href="#p" textLength="25" lengthAdjust="spacing"
text-anchor="middle" startOffset="50%">XXXX</textPath>
</text>
<text expected-x="37.5" transform="translate(0 50)">
<textPath href="#p" textLength="25" lengthAdjust="spacingAndGlyphs"
text-anchor="middle" startOffset="50%">XXXX</textPath>
</text>
<text expected-x="75">
<textPath href="#p" textLength="25" lengthAdjust="spacing"
text-anchor="end" startOffset="100%">XXXX</textPath>
</text>
<text expected-x="75" transform="translate(0 50)">
<textPath href="#p" textLength="25" lengthAdjust="spacingAndGlyphs"
text-anchor="end" startOffset="100%">XXXX</textPath>
</text>
</g>
<script>
test(t => {
let texts = Array.from(document.getElementsByTagName('text'));
for (let text of texts) {
let bbox = text.getBBox();
let textpath = text.firstElementChild;
let description = 'text-anchor=' + textpath.getAttribute('text-anchor');
assert_approx_equals(bbox.x, parseFloat(text.getAttribute('expected-x')), 0.5,
'x, ' + description);
assert_approx_equals(bbox.width, 25, 0.5,
'width, ' + description);
}
});
</script>
</svg>
|