in reply to SVG text width calculation
Use the attribute text-anchor="middle" instead of computing the width yourself (which is hard to do as you usually wouldn't easily get at the individual glyphs' widths of the particular font being used).
Here's an example that centers text above a rectangle:
<?xml version="1.0" encoding="UTF-8"?> <svg version="1.2" width="100%" height="100%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg"> <g transform="translate(100 100)"> <rect width="200" height="50" x="-100" y="10" fill="lightyellow"/> <text text-anchor="middle">Some centered text</text> </g> </svg>
(tested with Firefox 3.6.8 and Opera 10.63)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: SVG text width calculation
by moritz (Cardinal) on Dec 29, 2010 at 21:45 UTC | |
|
Re^2: SVG text width calculation
by Anonymous Monk on Dec 29, 2010 at 22:38 UTC |