tspan

tspanエレメントは、textエレメントの内側で使用する。

書き方

<tspan x="X座標" y="Y座標" dx="X座標" dy="Y座標" rotate="角度" textLength="?" lengthAdjust="?" style="style data">
描画文字列
</tspan>

x="X座標"

文字列の開始座標を絶対座標で指定する。文字列の左端の座標となる。

y="Y座標"

文字列のベースラインの座標を絶対座標で指定する。

dx="相対X座標"

文字列の開始座標を相対座標で指定する。文字列の左端の座標となる。

dy="相対Y座標"

文字列のベースラインの座標を相対座標で指定する。

rotate="角度"

tsapnで囲んだ文字列の1文字毎の角度を1つづつ指定する。指定しないと0と見なされる。

textLength="?"

lengthAdjust="?"

使用例

絶対座標による位置変更。textのstyleを引き継いでいる。

<text x="20" y="40" style="font-family:Verdana; font-size:20pt; fill:blue">
ABCDEFpqwxyz
<tspan x="20" y="70">
ghijklMNOPQR
</tspan>
</text>

相対座標による位置変更。色やサイズも同時に変更。

<text x="20" y="40" style="font-family:Verdana; font-size:20pt; fill:blue">
AB<tspan dy="10" style="fill:red">CDEF</tspan>pqw<tspan style="fill:red">xyz</tspan>

<tspan x="20" y="70">
ghijkl<tspan dy="10" style="font-size:10pt">MNOPQR</tspan>
</tspan>
</text>

角度をつけてみる。

<text x="20" y="50" style="font-family:Verdana; font-size:10pt; fill:blue">
FLAT <tspan rotate="-50 -30 -10 10 30 50" style="fill:red;font-size:20pt">ROTATE</tspan> FLAT
</text>

<text x="20" y="90" style="font-family:Verdana; font-size:10pt; fill:blue">
FLAT <tspan rotate="-50 -30 -10" style="fill:red;font-size:20pt">ROTATE</tspan> FLAT
</text>