I have a small function I found that takes a string from a textarea and then puts it into a canvas element and wraps the text when the line gets to
textarea
canvas
You should try detect the first line.
Then the:
if(n == 0){ line = words[n]+"\n"; }
I'm not sure, but maybe it helps.