Letter spacing in canvas element

前端 未结 10 2387
攒了一身酷
攒了一身酷 2020-12-24 06:46

The question says it all pretty much. I\'ve been searching around and starting to worry that it\'s impossible.

I\'ve got this canvas element that I\'m drawing text t

10条回答
  •  渐次进展
    2020-12-24 07:05

    You can't set letter-spacing as a property of the Canvas context. You can only achieve the effect by doing manual spacing, sorry. (As in, drawing each letter manually increasing the x by some pixel amount on each)

    For the record, you can set a few text properties by using ctx.font but letter-spacing is not one of them. The ones you can set are: "font-style font-variant font-weight font-size/line-height font-family"

    For instance you can technically write ctx.font = "bold normal normal 12px/normal Verdana" (or any omission of any of those) and it will parse correctly.

提交回复
热议问题