2012-12-23 17 views

Odpowiedz

0

Nie, plik paper.js nie może obecnie rozdzielać wierszy. To nie jest menedżer układu ... przynajmniej nie w pełni funkcjonalny menedżer układu. W pliku TextItemreference znajduje się komentarz, że "nadchodzi wkrótce", co przydałoby się, jak chcesz.

Na razie musisz sam rozdzielić strunę, utworzyć wiele PointText, aby przytrzymać kawałki struny i ułożyć te teksty.

3

Ten kod przerwy i słowo linia owija najlepiej jak mogę zorientować się teraz:

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

staram się poprawić, ale to działa na pointText. Nie mogę jeszcze zobaczyć, jak zrobić paper.textItem (nie może być wiele różny)

+0

To powinna być zaakceptowana odpowiedź. Uratowałeś mi godziny :) – campsjos

+0

Zwróćmy uwagę, że nowe wersje pliku paper.js obsługują podział wiersza za pomocą '\ n', ale bez zawijania słów, jak to robi rozwiązanie Bena. Istnieje kilka PR's open ([# 1005] (https://github.com/paperjs/paper.js/pull/1005) i [# 1108] (https://github.com/paperjs/paper.js/ pull/1108), które implementują funkcję 'AreaText' ... tylko czekają, aż zostaną włączone do oficjalnego wydania. – plong0

Powiązane problemy