2012-12-23 1 views

답변

0

아니요, paper.js는 현재 줄 바꿈을 할 수 없습니다. 그것은 레이아웃 매니저가 아닙니다. 적어도 완전한 기능을 갖춘 레이아웃 매니저는 아닙니다. TextItemreference에는 AreaText이 "곧 출시 될 예정"이라고하는 의견이 있으며 원하는대로 할 수 있습니다.

지금은 문자열을 직접 나눠야하고, 문자열의 조각을 보유하기 위해 복수의 PointText을 만들고 그 텍스트를 쌓아야합니다.

3

줄 바꿈과 단어가 최선 내가 지금 알아낼 수있는 랩이 코드 :

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을 만드는 방법을 아직 볼 수 없다. (많이 다를 수는 없다)

+0

이것은 받아 들여진 대답이어야합니다. 시간을 절약 해주었습니다 :) – campsjos

+0

새 버전의 paper.js는'\ n'을 사용하여 줄 바꿈을 지원하지만 Ben의 해결책처럼 단어 줄 바꿈을 지원하지 않습니다. 몇 가지 홍보 ([# 1005] (https://github.com/paperjs/paper.js/pull/1005)와 [# 1108] (https://github.com/paperjs/paper.js/) pull/1108))'AreaText' 기능을 구현합니다 ... 공식 릴리스에 포함되기를 기다리고 있습니다. – plong0