我试图了解是否有办法在paper.js textItem中打破一行(\ n): http://paperjs.org/reference/textitem
也许有办法以某种方式将其装箱? 我需要它在广场的边缘断裂。
答案 0 :(得分:4)
这段代码行打破了,并且我现在可以理解为最好的词汇:
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(不能有太大的不同)
答案 1 :(得分: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';
答案 2 :(得分:0)
不,paper.js目前无法破线。它不是布局管理器......至少不是一个功能齐全的布局管理器。 TextItem
reference中有一条评论AreaText
即将“即将推出”,可以满足您的需求。
现在,您必须自己拆分字符串,创建多个PointText
来保存字符串,并堆叠这些文本。