您当前的位置: 首页 > 

插件开发

暂无认证

  • 3浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

illustrator插件--常用功能开发--正则编辑文本--js脚本开发--AI插件

插件开发 发布时间:2022-03-01 08:16:23 ,浏览量:3

  illustrator是矢量编辑软件,画板是绘制处理的重要容器,在印刷方面的一个重要功能就是正则编辑文本,开发一个正则编辑文本功能,以下功能仅用于学习交流,请勿用于非法用途和商业用途,源代码如下所示:


var toZENKAKU = function(chara) {
    return String.fromCharCode(chara.charCodeAt(0) + 65248);
};
var toHANKAKU = function(chara) {
    return String.fromCharCode(chara.charCodeAt(0) - 65248);
};
var findreplacePattern = {
    "半角英数を全角英数へ": ["/[a-zA-Z0-9]/g", toZENKAKU],
    "全角英数を半角英数へ": ["/[a-zA-Z0-9]/g", toZENKAKU]
};

function textReplacePatterns(textFrame, pattern) {
    if (textFrame.constructor.name !== "TextFrame") {
        return false;
    }
    for (var i = 0; i >> 0; i >> 0;
                try {
                    if (typeof s === "string") {
                        s = doEx(s)
                    }
                    if ((s.length >>> 0) !== 0) {
                        s = Array.prototype.slice.call(s, 0);
                        for (var i = 0; i >> 0; i += 1) {
                            this[len + i] = s[i];
                        }
                        this.length = len + s.length;
                    } else {
                        this[len] = s;
                        this.length = len + 1;
                    }
                } catch (e) {
                    this[len] = s;
                    this.length++;
                    this.error.push("add_error : " + e);
                }
                this.log.push("length:" + this.length);
                return this;
            },
            toArray: function() {
                return Array.prototype.slice.call(this, 0);
            },
            saveDoc: function(path) {
                this.each(function() {
                    if (this.constructor.name == "Document") {
                        this.saveAs(File(path));
                    }
                });
                return this;
            },
            get: function(num) {
                if (typeof num == "number" && num = 0) {
                    return this[num];
                }
                return false;
            },
            now: function() {
                return this.get(this.position);
            },
            next: function() {
                return this.get(this.position++);
            },
            prev: function() {
                return this.get(--this.position);
            },
            loop: function() {
                if (this.position >= this.length) {
                    this.position = 0
                }
                return this.get(this.position++);
            },
            dofunc: function(func, arg) {
                if (func == undefined) {
                    return this;
                }
                var res = true;
                if (func.constructor.name == "Function") {
                    res = func.call(this)
                }
                if (res) {
                    return this;
                } else {
                    return {
                        each: function() {

                        }
                    };
                }
            },
            each: function(fnc, arg) {
                var l = this.length >>> 0;
                var i = -1;
                this.log.push("each : " + this.toArray().toString());
                var res = [];
                if (typeof fnc == "function") {
                    while (++i  0 ? doEx(res) : this;
            },
            eachReverse: function(fnc, arg) {
                var l = this.length;
                var res = [];
                if (typeof fnc == "function") {
                    for (var i = l; i > 0; i--) {
                        ret = fnc.call(this[i - 1], this[i - 1], arg);
                        typeof ret != "undefined" && res.push(ret);
                    }
                }
                if (res.length > 0) {
                    return doEx(res);
                } else {
                    return this;
                }
            },
            eachR: function(fnc, arg) {
                return this.eachReverse(fnc, arg);
            },
            filter: function() {
                this.log.push("filter : " + Array.prototype.slice.apply(arguments).toString());
                if ((arguments.length >>> 0) == 0) {
                    return this;
                }
                var s = {
                    TRUE: [],
                    FALSE: []
                };
                var caseBy = {
                    function: function(arg) {
                        while (x = this.next()) {
                            arg(x) ? s.TRUE.push(this) : s.FALSE.push(this);
                        }
                    },
                    string: function(arg) {
                        if (typeof this.objectShortName[arg] == "string") {
                            arg = this.objectShortName[arg]
                        }
                        if (typeof this.filters[arg] == "function") {
                            this.filters[arg].call(this, s);
                        } else {
                            var fd = this.attr(arg).toArray();
                            s.TRUE = s.TRUE.concat(fd);
                        }
                    }
                };
                var extractarg = function(args) {
                    for (var i = 0; i             
关注
打赏
1665481431
查看更多评论
0.1073s