2012-12-23 3 views

Antwort

0

Nein, paper.js kann derzeit keine Zeilen unterbrechen. Es ist kein Layout-Manager ... zumindest kein voll funktionsfähiger Layout-Manager. Es gibt einen Kommentar in der TextItemreference, dass eine AreaText "kommt bald", die tun würde, was Sie wollen.

Für jetzt müssen Sie die Zeichenfolge selbst aufteilen, erstellen Sie mehrere PointText, um die Teile der Zeichenfolge zu halten, und stapeln Sie diese Texte.

3

Dieser Code Zeilenumbrüche und Wort als beste hüllt wie ich jetzt herausfinden können:

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

Ich versuche, dies zu verbessern, aber es funktioniert für pointText. Ich kann noch nicht sehen, wie man ein paper.textItem (kann nicht viel anders sein)

+0

Dies sollte die akzeptierte Antwort sein. Du hast mir Stunden gespart :) – campsjos

+0

Ich möchte nur darauf hinweisen, dass neue Versionen von paper.js Zeilenumbrüche mit '\ n' unterstützen, aber kein Word-Wrapping wie Bens Lösung. Es gibt ein paar PR's ([# 1005] (https://github.com/paperjs/paper.js/pull/1005) und [# 1108] (https://github.com/paperjs/paper.js/ pull/1108)), die die "AreaText" -Funktion implementieren ... warten nur darauf, dass sie in einer offiziellen Version enthalten sind. – plong0

Verwandte Themen