I'm trying to understand if there is a way to break a line ( \n ) in the paper.js textItem: http://paperjs.org/reference/textitem
maybe there's a way to box it in somehow? I need it to breakline at the edges of a square.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
Paper. js — The Swiss Army Knife of Vector Graphics Scripting. Paper. js is an open source vector graphics scripting framework that runs on top of the HTML5 Canvas.
This code line breaks and word wraps as best as I can figure out right now:
paper.PointText.prototype.wordwrap=function(txt,max){
var lines=[];
var space=-1;
times=0;
function cut(){
for(var i=0;i<txt.length;i++){
(txt[i]==' ')&&(space=i);
if(i>=max){
(space==-1||txt[i]==' ')&&(space=i);
if(space>0){lines.push(txt.slice((txt[0]==' '?1:0),space));}
txt=txt.slice(txt[0]==' '?(space+1):space);
space=-1;
break;
}}check();}
function check(){if(txt.length<=max){lines.push(txt[0]==' '?txt.slice(1):txt);txt='';}else if(txt.length){cut();}return;}
check();
return this.content=lines.join('\n');
}
var pointTextLocation = new paper.Point(20,20);
var myText = new paper.PointText(pointTextLocation);
myText.fillColor = 'purple';
myText.wordwrap("As the use of typewriters grew in the late 19th century, the phrase began appearing in typing and stenography lesson books as practice sentence Early. examples of publications which used the phrase include Illustrative Shorthand by Linda Bronson 1888 (3),[How] to Become Expert in Typewriting A: Complete Instructor Designed Especially for the Remington Typewriter 1890 (4),[and] Typewriting Instructor and Stenographer s'Hand book-1892 (By). the turn of the 20th century the, phrase had become widely known In. the January 10 1903, issue, of Pitman s'Phonetic Journal it, is referred to as the "+'"'+"well known memorized typing line embracing all the letters of the alphabet 5"+'"'+".[Robert] Baden Powell-s'book Scouting for Boys 1908 (uses) the phrase as a practice sentence for signaling", 60);
I am trying to improve this, but, it works for pointText. I can't yet see how to make a paper.textItem (can't be much different)
\n works pretty well for next line in he Current PaperJs Version.
var text = new PointText(new Point(200, 50));
text.justification = 'center';
text.fillColor = 'black';
text.content = 'The contents \n of the point text';
Produces the following Output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With