Use Font Style on HTML5 Canvas

只愿长相守 提交于 2019-12-11 04:24:47

问题


I am trying to add text on a canvas using kinetic JS library. Kinetic JS Provides the setFontStyle() method to support the styles on fonts.

http://kineticjs.com/docs/symbols/Kinetic.Text.php#setFontStyle

According to the documentation It supports 'normal', 'italic', or 'bold'. But what I do if I want to apply bold and Italic at once. Also I want to underline the text. How I can do in kinetic JS.

Isn't there anyone to tell me :'(


回答1:


Like EliteOctagon already mentioned, KineticJS does not support underlining text yet. This is mainly due to the fact that text-decoration (including underlining) isn't supported in the html canvas element.

To add (multiple) font styles, is relatively easy. The most recommended way is by defining it at the initiation, like this:

var text = new Kinetic.Text({
    x: 0,
    y: 0,
    fontSize: 20,
    fontStyle: 'bold italic'
    fill: 'black',
});

If you need to set the font style differently at another time then initiation, you can use the method setFontStyle() like you mentioned. For instance like this:

var text = new Kinetic.Text();
text.setFontStyle('bold italic');


来源:https://stackoverflow.com/questions/14535700/use-font-style-on-html5-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!