开发者

How to make SVG respect a text-width and have it break lines accordingly?

开发者 https://www.devze.com 2023-02-03 15:45 出处:网络
Like in HTML, but I\'d prefer to not use foreignObject. This should be a standard-pr开发者_开发问答oblem so I guess there is a standard-solution, couldn\'t find one though.

Like in HTML, but I'd prefer to not use foreignObject.

This should be a standard-pr开发者_开发问答oblem so I guess there is a standard-solution, couldn't find one though.

Thanks

Raffael


The SVG 1.2T <textArea> element is the standard way. It's possible to implement similar functionality using javascript too, which can be good as a fallback. See e.g http://www.carto.net/papers/svg/textFlow/.


I rendered the line breaking aided by the PHP-function imagettfbbox(), to measure the line-length.

Best

Raffael


Okay ... the label for that is "word wrap" and it seems like this is only implemented in SVG 1.2. Though the example on W3C (http://www.w3.org/TR/SVGTiny12/text.html#TextInAnArea) is not supported by FireFox ... oh my


The standard solution is SVG1.2, but it's unimplemented so I guess the foreignObject solution is the best at the moment.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号