2012-12-23 7 views
5

मैं अगर वहाँ एक रास्ता एक लाइन (\ N) paper.js textItem में तोड़ने के लिए है समझने की कोशिश कर रहा हूँ: http://paperjs.org/reference/textitemमैं paper.js पुस्तकालय में LINEBREAK कर सकते हैं

शायद यह बॉक्स के लिए एक रास्ता है किसी भी तरह से? मुझे इसे वर्ग के किनारों पर तोड़ने की आवश्यकता है।

+0

यह सुनिश्चित नहीं है कि लोग इस तरह के वैध प्रश्नों को कम क्यों करते हैं, तटस्थ करने के लिए अपवित्र हैं। – sundar

उत्तर

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 के लिए काम करता है। मैं अभी तक पेपर बनाने के लिए नहीं देख सकता .textItem (बहुत अलग नहीं हो सकता है)

+0

यह स्वीकार्य उत्तर होना चाहिए। आपने मुझे घंटे बचाया :) – campsjos

+0

बस यह ध्यान रखना चाहते हैं कि paper.js के नए संस्करण '\ n' के साथ लाइन ब्रेक का समर्थन करते हैं, लेकिन बेन के समाधान के रूप में कोई शब्द-रैपिंग नहीं करता है। कुछ पीआर के खुले हैं ([# 1005] (https://github.com/paperjs/paper.js/pull/1005) और [# 1108] (https://github.com/paperjs/paper.js/ पुल/1108)) जो 'एरियाटेक्स्ट' सुविधा को लागू करता है ... बस उन्हें आधिकारिक रिलीज में शामिल करने का इंतजार कर रहा है। – plong0

संबंधित मुद्दे