首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以在paper.js库中换行吗

问我可以在paper.js库中换行吗
EN

Stack Overflow用户
提问于 2012-12-23 22:43:05
回答 3查看 1.6K关注 0票数 7

我正在尝试理解是否有一种方法可以在paper.js textItem中换行( \n ):http://paperjs.org/reference/textitem

也许有一种方法可以把它包装起来?我需要它在正方形的边上划出一条线。

EN

回答 3

Stack Overflow用户

发布于 2015-04-28 22:17:07

这段代码换行和换行是我现在所能想到的最好的方式:

代码语言:javascript
复制
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 (不能有太大的不同)

票数 5
EN

Stack Overflow用户

发布于 2021-03-12 13:44:24

\n适用于当前PaperJs版本中的下一行。

代码语言:javascript
复制
var text = new PointText(new Point(200, 50));
text.justification = 'center';
text.fillColor = 'black';
text.content = 'The contents \n of the point text';

生成以下输出。

​

票数 1
EN

Stack Overflow用户

发布于 2013-08-06 10:59:57

不能,paper.js当前不能换行。它不是一个布局manager...at,至少不是一个全功能的布局管理器。TextItem reference中有一条评论说,AreaText“很快就会出现”,它会做你想做的事情。

现在,您必须自己拆分字符串,创建多个PointText来保存字符串的片段,然后堆叠这些文本。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14011859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档