如何使用html5 canvas获取文本的边框? [英] How to get the bounding box of a text using html5 canvas?

查看:122
本文介绍了如何使用html5 canvas获取文本的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想得到一些文本的边框。

解决方案

我在提交问题之前找到了答案:

http:/ /mudcu.be/journal/2011/01/html5-typographic-metrics/#bboxUnicode
http://www.w3schools.com/tags/canvas_measuretext.asp

  var text_width = ctx.measureText( some text)。width; 

我在 text_height 中使用行高。 / p>

这没有给出确切的边界框,但在呈现文本之前它是快速且可用的。


I would like to get some text's bounding box.

解决方案

I found the answer before I submited the question:

http://mudcu.be/journal/2011/01/html5-typographic-metrics/#bboxUnicode http://www.w3schools.com/tags/canvas_measuretext.asp

var text_width = ctx.measureText("some text").width;

I used line height for text_height.

This gives not exact bounding box, but it is fast and usable before text rendering.

这篇关于如何使用html5 canvas获取文本的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆