Javascript 我可以在paper.js库中使用换行符吗

Javascript 我可以在paper.js库中使用换行符吗,javascript,line-breaks,paperjs,Javascript,Line Breaks,Paperjs,我试图了解是否有方法在paper.js textItem中打断一行(\n): 也许有办法把它塞进盒子里? 我需要它在正方形的边缘画一条特征线 否,paper.js当前无法断线。它不是一个布局管理器…至少不是一个功能齐全的布局管理器。TextItem中有一条评论说,AreaText即将推出,可以满足您的需求 现在,您必须自己拆分字符串,创建多个点文本来保存字符串片段,并将这些文本堆叠起来。我现在能找到的最好的方法是将这些代码行打断并换行: paper.PointText.prototype.wo

我试图了解是否有方法在paper.js textItem中打断一行(\n):

也许有办法把它塞进盒子里?
我需要它在正方形的边缘画一条特征线

否,paper.js当前无法断线。它不是一个布局管理器…至少不是一个功能齐全的布局管理器。
TextItem
中有一条评论说,
AreaText
即将推出,可以满足您的需求


现在,您必须自己拆分字符串,创建多个
点文本
来保存字符串片段,并将这些文本堆叠起来。

我现在能找到的最好的方法是将这些代码行打断并换行:

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);
paper.PointText.prototype.wordwrap=function(txt,max){
var行=[];
var空间=-1;
次数=0;
函数割(){
对于(变量i=0;i=max){
(空格==-1 | | txt[i]='')和&(空格=i);
if(space>0){lines.push(txt.slice((txt[0]=''?1:0),space));}
txt=txt.slice(txt[0]=''(空格+1):空格);
空间=-1;
打破
}}check();}

函数check(){if(txt.length\n对于当前PaperJs版本的下一行非常有效

var text = new PointText(new Point(200, 50));
text.justification = 'center';
text.fillColor = 'black';
text.content = 'The contents \n of the point text';
生成以下输出。

不知道为什么人们会对这样的有效问题投否决票,而将其改为无效。这应该是可以接受的答案。你为我节省了几个小时:)只想注意,新版本的paper.js确实支持使用
\n
换行,但没有像Ben的解决方案那样进行换行。有几个PR是开放的(和)它实现了
AreaText
功能…只是在等待它们被包含在正式版本中。