简体   繁体   English

如何向 html5 canvas 添加文本功能

[英]How to add text functionality to html5 canvas

I am making a whiteboard based on the html5 canvas and have add various functions like upload pdf, pencil, undo, redo and so on.我正在制作基于 html5 canvas 的白板,并添加了各种功能,如上传 pdf、铅笔、撤消、重做等。 Can someone help me with the the text tool.有人可以帮助我使用文本工具。 Basically after selecting the text tool on clicking on the canvas a text box should appear there to which we can input the text and the text appears on the canvas.基本上在单击 canvas 选择文本工具后,应该会出现一个文本框,我们可以在其中输入文本,文本出现在 canvas 上。 Once the text is submitted we should be able to edit it and also draw on top of it.提交文本后,我们应该能够对其进行编辑并在其上绘图。 Can someone please help me with this.有人可以帮我解决这个问题。

Thanks in advance!提前致谢!

Register a mousedown event on the <canvas> and make use of fillText to render the text.<canvas>上注册mousedown事件并使用fillText来呈现文本。 You may also register a keydown event to capture key input.您还可以注册一个keydown事件来捕获键输入。

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

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