简体   繁体   English

canvas 中的绘图文本

[英]Drawing text in a canvas

I need to draw text in a canvas, but the current fillText implementation overcomplicates a lot of features that I need (like being able to draw multiple lines).我需要在 canvas 中绘制文本,但是当前的fillText实现使我需要的许多功能过于复杂(例如能够绘制多条线)。

Because I need to copy the pixels from the canvas later, it must be drawn in the canvas, it can't be a span element over the canvas.因为后面需要从canvas复制像素,所以必须在canvas中绘制,不能是canvas之上的span元素。

Being able to make it editable is a plus, but not required.能够使其可编辑是一个加号,但不是必需的。

Is there any library that provides advanced features to draw text in a canvas?是否有任何库提供在 canvas 中绘制文本的高级功能? (It must work at least on IE9, Firefox, Chrome and Opera) (它必须至少在 IE9、Firefox、Chrome 和 Opera 上工作)

I only know of the FLOT Canvas Text plugin for jquery .我只知道 jquery 的FLOT Canvas 文本插件

But if I were you I'd still do it with a <span> because it would then be Search Engine friendly.但如果我是你,我仍然会使用<span>因为它对搜索引擎友好。 You can easily get the text of a span (or most) elements using element.innerHTML or element.innerText depending on the object.您可以使用 element.innerHTML 或 element.innerText 轻松获取跨度(或大多数)元素的文本,具体取决于 object。 then you can process/pass that.然后你可以处理/传递它。 eg for a span such as例如对于一个跨度,如

<span id="myspan"> lorem ipsum </span>

I can say我可以说

spanText = document.getElementById("myspan").innerText;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM