HTML5 canvas ctx.fillText won't do line breaks?

前端 未结 17 1063
甜味超标
甜味超标 2020-11-28 01:37

I can\'t seem to be able to add text to a canvas if the text includes \"\\n\". I mean, the line breaks do not show/work.

ctxPaint.fillText(\"s  ome \\n \\\\n         


        
17条回答
  •  借酒劲吻你
    2020-11-28 02:18

    The code for word-wrapping (breaking at spaces) provided by @Gaby Petrioli is very helpful. I've extended his code to provide support for newline characters \n. Also, often times it's useful to have the dimensions of the bounding box, so multiMeasureText() returns both the width and the height.

    You can see the code here: http://jsfiddle.net/jeffchan/WHgaY/76/

提交回复
热议问题