I'm looking for a simple solution to be able to word wrap within a fixed rectangle in my canvas....
I thought this might work, but unless I make the wrap point longer than the text, it causes my canvas to go completely blank.
<canvas id="planner1" width="300" height="300" style="z-index:0;position:absolute;left:10px;top:10px;border:1px solid #000000;background-color:white;"></canvas>
var c1 = document.getElementById("planner1");
var ctx = c1.getContext("2d");
ctx.font = "16px Arial";
ctx.fillStyle = "red";
ctx.textAlign = "left";
ctx.fillText("<?php echo wordwrap("Sample Text", 10, "
", FALSE);?>",80 ,80);
Looking through the PHP manual, I don't see anything that would preclude this, but I know mixing PHP and javascript is fraught with peril.
I get the data used in the canvas from my db and echo it to draw the rectangle. I then would like echo text (easy via javascript) and wordwrap it (less easy in javascript). PHP has an easy way to do this which I tried, however it doesn't word wrap correctly within the javascript. This isn't a server side versus client side issue and that all works properly....this is formatting issue mainly tied to how javascript handles displaying text within the confines of the canvas tags.
Anybody ever try this and/or found a better way?