2012-12-23 16 views

risposta

0

No, paper.js non può attualmente interrompere le linee. Non è un gestore di layout ... almeno non un gestore di layout con funzioni complete. C'è un commento nello TextItemreference che un "AreaText" sta per arrivare "che farebbe quello che vuoi.

Per ora, è necessario suddividere la stringa da soli, creare più PointText per contenere i pezzi della stringa e impilarli.

3

Questo codice interruzioni di riga e parola avvolge come meglio riesco a capire in questo momento:

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

sto cercando di migliorare questo, ma, funziona per pointText. Non riesco ancora a vedere come creare un paper.textItem (non può essere molto diverso)

+0

Questa dovrebbe essere la risposta accettata. Mi hai risparmiato ore :) – campsjos

+0

Voglio solo ricordare che le nuove versioni di paper.js supportano le interruzioni di riga con '\ n', ma non il word-wrapping come fa la soluzione di Ben. Sono disponibili un paio di PR ([# 1005] (https://github.com/paperjs/paper.js/pull/1005) e [# 1108] (https://github.com/paperjs/paper.js/ pull/1108)) che implementa la funzione 'AreaText' ... aspettando solo che siano inclusi in una versione ufficiale. – plong0

Problemi correlati