7

我试图了解是否有办法在 paper.js 文本项中换行( \n ):http: //paperjs.org/reference/textitem

也许有办法以某种方式将其装箱?我需要它在正方形的边缘划线。

4

3 回答 3

5

这个代码换行符和自动换行是我现在能想到的最好的:

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);

我正在尝试改进这一点,但是,它适用于 pointText。我还看不到如何制作 paper.textItem (差别不大)

于 2015-04-28T14:17:07.300 回答
1

\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';

产生以下输出。 换行输出

于 2021-03-12T05:44:23.587 回答
0

不,paper.js 目前不能换行。它不是一个布局管理器……至少不是一个功能齐全的布局管理器。TextItem 参考文献中有一条评论说AreaText“即将推出”可以满足您的需求。

现在,您必须自己拆分字符串,创建多个PointText来保存字符串的片段,然后堆叠这些文本。

于 2013-08-06T02:59:56.680 回答