2024-10-08 15:19:05 +00:00
|
|
|
|
// 日本語認識用
|
|
|
|
|
"object" != typeof JSON && (JSON = {}), function () { "use strict"; function f(t) { return 10 > t ? "0" + t : t } function this_value() { return this.valueOf() } function quote(t) { return rx_escapable.lastIndex = 0, rx_escapable.test(t) ? '"' + t.replace(rx_escapable, function (t) { var e = meta[t]; return "string" == typeof e ? e : "\\u" + ("0000" + t.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + t + '"' } function str(t, e) { var r, n, o, u, f, a = gap, i = e[t]; switch (i && "object" == typeof i && "function" == typeof i.toJSON && (i = i.toJSON(t)), "function" == typeof rep && (i = rep.call(e, t, i)), typeof i) { case "string": return quote(i); case "number": return isFinite(i) ? i + "" : "null"; case "boolean": case "null": return i + ""; case "object": if (!i) return "null"; if (gap += indent, f = [], "[object Array]" === Object.prototype.toString.apply(i)) { for (u = i.length, r = 0; u > r; r += 1)f[r] = str(r, i) || "null"; return o = 0 === f.length ? "[]" : gap ? "[\n" + gap + f.join(",\n" + gap) + "\n" + a + "]" : "[" + f.join(",") + "]", gap = a, o } if (rep && "object" == typeof rep) for (u = rep.length, r = 0; u > r; r += 1)"string" == typeof rep[r] && (n = rep[r], o = str(n, i), o && f.push(quote(n) + (gap ? ": " : ":") + o)); else for (n in i) Object.prototype.hasOwnProperty.call(i, n) && (o = str(n, i), o && f.push(quote(n) + (gap ? ": " : ":") + o)); return o = 0 === f.length ? "{}" : gap ? "{\n" + gap + f.join(",\n" + gap) + "\n" + a + "}" : "{" + f.join(",") + "}", gap = a, o } } var rx_one = /^[\],:{}\s]*$/, rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, rx_four = /(?:^|:|,)(?:\s*\[)+/g, rx_escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; "function" != typeof Date.prototype.toJSON && (Date.prototype.toJSON = function () { return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null }, Boolean.prototype.toJSON = this_value, Number.prototype.toJSON = this_value, String.prototype.toJSON = this_value); var gap, indent, meta, rep; "function" != typeof JSON.stringify && (meta = { "\b": "\\b", " ": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }, JSON.stringify = function (t, e, r) { var n; if (gap = "", indent = "", "number" == typeof r) for (n = 0; r > n; n += 1)indent += " "; else "string" == typeof r && (indent = r); if (rep = e, e && "function" != typeof e && ("object" != typeof e || "number" != typeof e.length)) throw Error("JSON.stringify"); return str("", { "": t }) }), "function" != typeof JSON.parse && (JSON.parse = function (text, reviver) { function walk(t, e) { var r, n, o = t[e]; if (o && "object" == typeof o) for (r in o) Object.prototype.hasOwnProperty.call(o, r) && (n = walk(o, r), void 0 !== n ? o[r] = n : delete o[r]); return reviver.call(t, e, o) } var j; if (text += "", rx_dangerous.lastIndex = 0, rx_dangerous.test(text) && (text = text.replace(rx_dangerous, function (t) { return "\\u" + ("0000" + t.charCodeAt(0).toString(16)).slice(-4) })), rx_one.test(text.replace(rx_two, "@").replace(rx_three, "]").replace(rx_four, ""))) return j = eval("(" + text + ")"), "function" == typeof reviver ? walk({ "": j }, "") : j; throw new SyntaxError("JSON.parse") }) }();
|
|
|
|
|
// Generated by CoffeeScript 1.12.7
|
|
|
|
|
|
|
|
|
|
//查看ps字段用
|
|
|
|
|
function checkDesc(desc) {
|
|
|
|
|
var c = desc.count,
|
|
|
|
|
str = '';
|
|
|
|
|
for (var i = 0; i < c; i++) {
|
|
|
|
|
str += 'Key ' + i + ' = ' + t2s(desc.getKey(i)) + ': ' + desc.getType(desc.getKey(i)) + ' = ' + getValues(desc, i) + '\n';
|
|
|
|
|
};
|
|
|
|
|
$.writeln(str);
|
|
|
|
|
alert(str);
|
|
|
|
|
};
|
|
|
|
|
function getValues(desc, keyNum) {
|
|
|
|
|
var kTypeID = desc.getKey(keyNum);
|
|
|
|
|
switch (desc.getType(kTypeID)) {
|
|
|
|
|
case DescValueType.OBJECTTYPE:
|
|
|
|
|
return (desc.getObjectValue(kTypeID) + "_" + t2s(desc.getObjectType(kTypeID)));
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.LISTTYPE:
|
|
|
|
|
|
|
|
|
|
return desc.getList(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.REFERENCETYPE:
|
|
|
|
|
return desc.getReference(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.BOOLEANTYPE:
|
|
|
|
|
return desc.getBoolean(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.STRINGTYPE:
|
|
|
|
|
return desc.getString(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.INTEGERTYPE:
|
|
|
|
|
return desc.getInteger(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.LARGEINTEGERTYPE:
|
|
|
|
|
return desc.getLargeInteger(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.DOUBLETYPE:
|
|
|
|
|
return desc.getDouble(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.ALIASTYPE:
|
|
|
|
|
return desc.getPath(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.CLASSTYPE:
|
|
|
|
|
return desc.getClass(kTypeID);
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.UNITDOUBLE:
|
|
|
|
|
return (desc.getUnitDoubleValue(kTypeID) + "_" + t2s(desc.getUnitDoubleType(kTypeID)));
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.ENUMERATEDTYPE:
|
|
|
|
|
return (t2s(desc.getEnumerationValue(kTypeID)) +
|
|
|
|
|
"_" + t2s(desc.getEnumerationType(kTypeID)));
|
|
|
|
|
break;
|
|
|
|
|
case DescValueType.RAWTYPE:
|
|
|
|
|
var tempStr = desc.getData(kTypeID);
|
|
|
|
|
var rawData = new Array();
|
|
|
|
|
for (var tempi = 0; tempi < tempStr.length; tempi++) {
|
|
|
|
|
rawData[tempi] = tempStr.charCodeAt(tempi);
|
|
|
|
|
}
|
|
|
|
|
return rawData;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
function t2s(t) { return typeIDToStringID(t) }
|
|
|
|
|
function s2t(t) { return stringIDToTypeID(t) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
var Baum, PsdToImage, PsdToJson, Util, baum, setup,
|
|
|
|
|
bind = function (fn, me) { return function () { return fn.apply(me, arguments); }; },
|
|
|
|
|
indexOf = [].indexOf || function (item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
|
|
|
|
|
|
Baum = (function () {
|
|
|
|
|
function Baum() {
|
|
|
|
|
this.runOneFile = bind(this.runOneFile, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Baum.version = '0.6.1';
|
|
|
|
|
Baum.maxLength = 2048;
|
|
|
|
|
|
|
|
|
|
Baum.prototype.run = function () {
|
|
|
|
|
var filePath, filePaths, j, len;
|
|
|
|
|
this.saveFolder = null;
|
|
|
|
|
if (app.documents.length === 0) {
|
|
|
|
|
filePaths = File.openDialog("Select a file", "*", true);
|
|
|
|
|
for (j = 0, len = filePaths.length; j < len; j++) {
|
|
|
|
|
filePath = filePaths[j];
|
|
|
|
|
app.activeDocument = app.open(File(filePath));
|
|
|
|
|
this.runOneFile(true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.runOneFile(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.runOneFile = function (after_close) {
|
|
|
|
|
var copiedDoc;
|
|
|
|
|
if (this.saveFolder === null) {
|
|
|
|
|
this.saveFolder = Folder.selectDialog("选择目标文件夹");
|
|
|
|
|
}
|
|
|
|
|
if (this.saveFolder === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.documentName = app.activeDocument.name.slice(0, -4);
|
|
|
|
|
copiedDoc = app.activeDocument.duplicate(app.activeDocument.name.slice(0, -4) + '.copy.psd');
|
|
|
|
|
copiedDoc.quickMaskMode = false;
|
|
|
|
|
Util.deselectLayers();
|
|
|
|
|
|
|
|
|
|
var legal = this.checkLayerName(copiedDoc);
|
|
|
|
|
if (!legal) {
|
|
|
|
|
copiedDoc.close(SaveOptions.DONOTSAVECHANGES);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this.removeUnvisibleLayers(copiedDoc)
|
|
|
|
|
// this.unlockAll(copiedDoc);
|
|
|
|
|
// this.rasterizeAll(copiedDoc);
|
|
|
|
|
this.unvisibleAll(copiedDoc);
|
|
|
|
|
this.layerBlendAll(copiedDoc, copiedDoc);
|
|
|
|
|
// this.removeCommentoutLayers(copiedDoc, copiedDoc);
|
|
|
|
|
this.cropLayers(copiedDoc);
|
|
|
|
|
this.resizePsd(copiedDoc);
|
|
|
|
|
this.selectDocumentArea(copiedDoc);
|
|
|
|
|
this.ungroupArtboard(copiedDoc);
|
|
|
|
|
this.clipping(copiedDoc, copiedDoc);
|
|
|
|
|
copiedDoc.selection.deselect();
|
|
|
|
|
this.psdToJson(copiedDoc);
|
|
|
|
|
this.psdToImage(copiedDoc);
|
|
|
|
|
copiedDoc.close(SaveOptions.DONOTSAVECHANGES);
|
|
|
|
|
if (after_close) {
|
|
|
|
|
return app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
|
|
|
|
|
}
|
|
|
|
|
return alert('导出完成!');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.selectDocumentArea = function (document) {
|
|
|
|
|
var selReg, x1, x2, y1, y2;
|
|
|
|
|
x1 = 0;
|
|
|
|
|
y1 = 0;
|
|
|
|
|
x2 = document.width.value;
|
|
|
|
|
y2 = document.height.value;
|
|
|
|
|
selReg = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]];
|
|
|
|
|
return document.selection.select(selReg);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.clipping = function (document, root) {
|
|
|
|
|
var h, w, x1, x2, y1, y2;
|
|
|
|
|
document.resizeImage(document.width, document.height, 72, ResampleMethod.BICUBICAUTOMATIC);
|
|
|
|
|
if (document.selection.bounds[0].value === 0 && document.selection.bounds[1].value === 0 && document.selection.bounds[2].value === document.width.value && document.selection.bounds[3].value === document.height.value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
document.selection.invert();
|
|
|
|
|
this.clearAll(document, root);
|
|
|
|
|
document.selection.invert();
|
|
|
|
|
x1 = document.selection.bounds[0];
|
|
|
|
|
y1 = document.selection.bounds[1];
|
|
|
|
|
x2 = document.selection.bounds[2];
|
|
|
|
|
y2 = document.selection.bounds[3];
|
|
|
|
|
document.resizeCanvas(x2, y2, AnchorPosition.TOPLEFT);
|
|
|
|
|
w = x2 - x1;
|
|
|
|
|
h = y2 - y1;
|
|
|
|
|
return activeDocument.resizeCanvas(w, h, AnchorPosition.BOTTOMRIGHT);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.clearAll = function (document, root) {
|
|
|
|
|
var j, layer, len, ref1, results;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
results.push(this.clearAll(document, layer));
|
|
|
|
|
} else if (layer.typename === 'ArtLayer') {
|
|
|
|
|
if (layer.kind !== LayerKind.TEXT) {
|
|
|
|
|
document.activeLayer = layer;
|
|
|
|
|
results.push(document.selection.clear());
|
|
|
|
|
} else {
|
|
|
|
|
results.push(void 0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
results.push(alert(layer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.resizePsd = function (doc) {
|
|
|
|
|
var height, tmp, width;
|
|
|
|
|
width = doc.width;
|
|
|
|
|
height = doc.height;
|
|
|
|
|
if (width < Baum.maxLength && height < Baum.maxLength) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
tmp = 0;
|
|
|
|
|
if (width > height) {
|
|
|
|
|
tmp = width / Baum.maxLength;
|
|
|
|
|
} else {
|
|
|
|
|
tmp = height / Baum.maxLength;
|
|
|
|
|
}
|
|
|
|
|
width = width / tmp;
|
|
|
|
|
height = height / tmp;
|
|
|
|
|
return doc.resizeImage(width, height, doc.resolution, ResampleMethod.BICUBICAUTOMATIC);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.removeUnvisibleLayers = function (root) {
|
|
|
|
|
var i, j, k, layer, len, ref1, ref2, removeLayers, results;
|
|
|
|
|
removeLayers = [];
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.visible === false) {
|
|
|
|
|
// layer.visible = true;
|
|
|
|
|
// 不可见的就push到移除layer中去
|
|
|
|
|
removeLayers.push(layer);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) {
|
|
|
|
|
removeLayers.push(layer);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
this.removeUnvisibleLayers(layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (removeLayers.length > 0) {
|
|
|
|
|
results = [];
|
|
|
|
|
for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) {
|
|
|
|
|
results.push(removeLayers[i].remove());
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.checkLayerName = function (root) {
|
|
|
|
|
//检查名字是否合规,同时移除不可见图层,同时解锁、光栅
|
|
|
|
|
var removeLayers = []
|
|
|
|
|
var ref1 = root.layers
|
|
|
|
|
for (var j = 0; j < ref1.length; j++) {
|
|
|
|
|
var layer = ref1[j];
|
|
|
|
|
var ss = layer.name.split("@");
|
|
|
|
|
//忽略但保留父节点宽高影响,则不移除
|
|
|
|
|
if (Util.isInferiorIgnoreByName(ss[0])) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//移除不可见图层
|
|
|
|
|
if (layer.visible === false || Util.isIgnoreByName(ss[0])) {
|
|
|
|
|
// 不可见的就push到移除layer中去
|
|
|
|
|
removeLayers.push(layer)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (layer.bounds[0].value === 0 && layer.bounds[1].value === 0 && layer.bounds[2].value === 0 && layer.bounds[3].value === 0) {
|
|
|
|
|
removeLayers.push(layer)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//解锁所有图层
|
|
|
|
|
if (layer.allLocked)
|
|
|
|
|
layer.allLocked = false
|
|
|
|
|
|
|
|
|
|
//光栅所有图层
|
|
|
|
|
if (layer.typename === 'ArtLayer') {
|
|
|
|
|
if (layer.kind !== LayerKind.TEXT) {
|
|
|
|
|
this.rasterize(layer)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
opt = Util.parseOption(ss[1]);
|
|
|
|
|
|
|
|
|
|
//检查大小命名格式
|
|
|
|
|
if (opt['高度']) {
|
|
|
|
|
var s = opt['高度']
|
|
|
|
|
for (var i = 0; i < s.length; i++) {
|
|
|
|
|
if (isNaN(s[i])) {
|
|
|
|
|
alert(layer.name + " 高度数值错误")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (opt['宽度']) {
|
|
|
|
|
var s = opt['宽度']
|
|
|
|
|
for (var i = 0; i < s.length; i++) {
|
|
|
|
|
if (isNaN(s[i])) {
|
|
|
|
|
alert(layer.name + " 宽度数值错误")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检查九宫格命名格式
|
|
|
|
|
if (opt['九宫格'] && opt['九宫格'] != 'true') {
|
|
|
|
|
var param = opt['九宫格']
|
|
|
|
|
var nums = param.toString().split("|");
|
|
|
|
|
if (nums.length == 1 || nums.length == 4) {
|
|
|
|
|
for (var i = 0; i < nums.length; i++) {
|
|
|
|
|
if (!isNumber(nums[i])) {
|
|
|
|
|
alert(layer.name + " 九宫格格式不对")
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
alert(layer.name + " 九宫格格式不对")
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//文件名合规检测
|
|
|
|
|
var reg = /^[0-9a-zA-Z"_""\-"]*$/g;
|
|
|
|
|
if (!reg.test(ss[0])) {
|
|
|
|
|
alert("\"" + layer.name + "\" 名字不合法,只能含有英文、数字、-、_")
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//递归检测
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
if (!this.checkLayerName(layer))
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (removeLayers.length > 0) {
|
|
|
|
|
for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) {
|
|
|
|
|
removeLayers[i].remove()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isChinese(temp) {
|
|
|
|
|
var re = /[^\u4E00-\u9FA5]/;
|
|
|
|
|
if (re.test(temp)) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isNumber(val) {
|
|
|
|
|
var regPos = /^\d+(\.\d+)?$/; //非负浮点数
|
|
|
|
|
var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
|
|
|
|
|
if (regPos.test(val) || regNeg.test(val)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Baum.prototype.removeCommentoutLayers = function (document, root) {
|
|
|
|
|
var i, j, k, layer, len, ref1, ref2, removeLayers, results;
|
|
|
|
|
removeLayers = [];
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (Util.isIgnoreByName(layer.name)) {
|
|
|
|
|
removeLayers.push(layer);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
this.removeCommentoutLayers(document, layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (root.typename === 'LayerSet') {
|
|
|
|
|
document.activeLayer = root;
|
|
|
|
|
}
|
|
|
|
|
if (removeLayers.length > 0) {
|
|
|
|
|
results = [];
|
|
|
|
|
for (i = k = ref2 = removeLayers.length - 1; ref2 <= 0 ? k <= 0 : k >= 0; i = ref2 <= 0 ? ++k : --k) {
|
|
|
|
|
results.push(removeLayers[i].remove());
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.cropLayers = function (root) {
|
|
|
|
|
var bounds;
|
|
|
|
|
bounds = [0, 0, root.width, root.height];
|
|
|
|
|
return root.crop(bounds);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.rasterizeAll = function (root) {
|
|
|
|
|
var j, layer, len, ref1, results, t;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.name.startsWith('*')) {
|
|
|
|
|
layer.name = layer.name.slice(1).strip();
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
Util.mergeGroup(layer);
|
|
|
|
|
} else {
|
|
|
|
|
this.rasterize(layer);
|
|
|
|
|
}
|
|
|
|
|
} else if (layer.typename === 'LayerSet') {
|
|
|
|
|
this.rasterizeAll(layer);
|
|
|
|
|
} else if (layer.typename === 'ArtLayer') {
|
|
|
|
|
if (layer.kind !== LayerKind.TEXT) {
|
|
|
|
|
this.rasterize(layer);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
alert(layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
t = 0;
|
|
|
|
|
results = [];
|
|
|
|
|
while (t < root.layers.length) {
|
|
|
|
|
if (root.layers[t].visible && root.layers[t].grouped) {
|
|
|
|
|
results.push(root.layers[t].merge());
|
|
|
|
|
} else {
|
|
|
|
|
results.push(t += 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.rasterize = function (layer) {
|
|
|
|
|
var tmp;
|
|
|
|
|
tmp = app.activeDocument.activeLayer;
|
|
|
|
|
app.activeDocument.activeLayer = layer;
|
|
|
|
|
if (layer.blendMode !== BlendMode.OVERLAY && layer.kind !== LayerKind.HUESATURATION && layer.opacity > 1) {
|
|
|
|
|
Util.rasterizeLayerStyle(layer);
|
|
|
|
|
}
|
|
|
|
|
layer.rasterize(RasterizeType.ENTIRELAYER);
|
|
|
|
|
Util.rasterizeLayerMask(layer);
|
|
|
|
|
return app.activeDocument.activeLayer = tmp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.ungroupArtboard = function (document) {
|
|
|
|
|
var j, layer, len, ref1, results;
|
|
|
|
|
ref1 = document.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.name.startsWith('Artboard') && layer.typename === 'LayerSet') {
|
|
|
|
|
results.push(this.ungroup(layer));
|
|
|
|
|
} else {
|
|
|
|
|
results.push(void 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.ungroup = function (root) {
|
|
|
|
|
var i, j, layer, layers, ref1;
|
|
|
|
|
layers = (function () {
|
|
|
|
|
var j, len, ref1, results;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
results.push(layer);
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
})();
|
|
|
|
|
for (i = j = 0, ref1 = layers.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
|
|
|
|
|
layers[i].moveBefore(root);
|
|
|
|
|
}
|
|
|
|
|
return root.remove();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.unlockAll = function (root) {
|
|
|
|
|
var j, layer, len, ref1, results;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
results.push(this.unlockAll(layer));
|
|
|
|
|
} else {
|
|
|
|
|
if (layer.allLocked) {
|
|
|
|
|
results.push(layer.allLocked = false);
|
|
|
|
|
} else {
|
|
|
|
|
results.push(void 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.unvisibleAll = function (root) {
|
|
|
|
|
var j, layer, len, ref1, results;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
results.push(this.unvisibleAll(layer));
|
|
|
|
|
} else {
|
|
|
|
|
results.push(layer.visible = false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.layerBlendAll = function (document, root) {
|
|
|
|
|
var i, j, layer, newLayer, ref1, results;
|
|
|
|
|
if (root.layers.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
results = [];
|
|
|
|
|
for (i = j = ref1 = root.layers.length - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) {
|
|
|
|
|
layer = root.layers[i];
|
|
|
|
|
if (layer.typename === 'LayerSet') {
|
|
|
|
|
results.push(this.layerBlendAll(document, layer));
|
|
|
|
|
} else {
|
|
|
|
|
layer.visible = true;
|
|
|
|
|
if (layer.blendMode !== BlendMode.OVERLAY && layer.kind !== LayerKind.HUESATURATION) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
document.activeLayer = layer;
|
|
|
|
|
try {
|
|
|
|
|
Util.selectTransparency();
|
|
|
|
|
document.selection.bounds;
|
|
|
|
|
document.selection.copy(true);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
layer.copy(true);
|
|
|
|
|
}
|
|
|
|
|
document.paste();
|
|
|
|
|
newLayer = document.activeLayer;
|
|
|
|
|
newLayer.name = layer.name;
|
|
|
|
|
document.activeLayer = layer;
|
|
|
|
|
Util.selectTransparency();
|
|
|
|
|
document.selection.invert();
|
|
|
|
|
document.activeLayer = newLayer;
|
|
|
|
|
try {
|
|
|
|
|
document.selection.bounds;
|
|
|
|
|
document.selection.cut();
|
|
|
|
|
} catch (error) { }
|
|
|
|
|
results.push(layer.remove());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.psdToJson = function (targetDocument) {
|
|
|
|
|
var json, toJson;
|
|
|
|
|
toJson = new PsdToJson();
|
|
|
|
|
json = toJson.run(targetDocument, this.documentName);
|
|
|
|
|
return Util.saveText(this.saveFolder + "/" + this.documentName + ".layout.txt", json);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Baum.prototype.psdToImage = function (targetDocument) {
|
|
|
|
|
var json, toImage;
|
|
|
|
|
toImage = new PsdToImage();
|
|
|
|
|
return json = toImage.run(targetDocument, this.saveFolder, this.documentName);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Baum;
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
PsdToJson = (function () {
|
|
|
|
|
function PsdToJson() { }
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.run = function (document, documentName) {
|
|
|
|
|
var bounds, canvasBase, canvasLayer, canvasSize, imageSize, json, layers;
|
|
|
|
|
layers = this.allLayers(document, document);
|
|
|
|
|
imageSize = [document.width.value, document.height.value];
|
|
|
|
|
canvasSize = [document.width.value, document.height.value];
|
|
|
|
|
canvasBase = [document.width.value / 2, document.height.value / 2];
|
|
|
|
|
canvasLayer = this.findLayer(document, '#Canvas');
|
|
|
|
|
if (canvasLayer) {
|
|
|
|
|
bounds = canvasLayer.bounds;
|
|
|
|
|
canvasSize = [bounds[2].value - bounds[0].value, bounds[3].value - bounds[1].value];
|
|
|
|
|
canvasBase = [(bounds[2].value + bounds[0].value) / 2, (bounds[3].value + bounds[1].value) / 2];
|
|
|
|
|
}
|
|
|
|
|
json = JSON.stringify({
|
|
|
|
|
info: {
|
|
|
|
|
version: Baum.version,
|
|
|
|
|
canvas: {
|
|
|
|
|
image: {
|
|
|
|
|
w: imageSize[0],
|
|
|
|
|
h: imageSize[1]
|
|
|
|
|
},
|
|
|
|
|
size: {
|
|
|
|
|
w: canvasSize[0],
|
|
|
|
|
h: canvasSize[1]
|
|
|
|
|
},
|
|
|
|
|
base: {
|
|
|
|
|
x: canvasBase[0],
|
|
|
|
|
y: canvasBase[1]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
root: {
|
|
|
|
|
type: 'Root',
|
|
|
|
|
name: documentName,
|
|
|
|
|
elements: layers
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return json;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.findLayer = function (root, name) {
|
|
|
|
|
var j, layer, len, ref1;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.name === name) {
|
|
|
|
|
return layer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.allLayers = function (document, root) {
|
|
|
|
|
var hash, j, layer, layers, len, name, opt, ref1;
|
|
|
|
|
layers = [];
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (!layer.visible || Util.isIgnoreByName(layer.name)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
hash = null;
|
|
|
|
|
name = layer.name.split("@")[0];
|
|
|
|
|
opt = Util.parseOption(layer.name.split("@")[1]);
|
|
|
|
|
if (layer.typename === 'ArtLayer') {
|
|
|
|
|
hash = this.layerToHash(document, name, opt, layer);
|
|
|
|
|
} else {
|
|
|
|
|
hash = this.groupToHash(document, name, opt, layer);
|
|
|
|
|
}
|
|
|
|
|
if (hash) {
|
|
|
|
|
hash['name'] = name;
|
|
|
|
|
layers.push(hash);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return layers;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.parseOption = function (text) {
|
|
|
|
|
var elements, j, len, opt, optText, ref1;
|
|
|
|
|
if (!text) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
opt = {};
|
|
|
|
|
ref1 = text.split(",");
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
optText = ref1[j];
|
|
|
|
|
elements = optText.split("=");
|
|
|
|
|
if (elements.length === 1) {
|
|
|
|
|
elements[1] = 'true';
|
|
|
|
|
}
|
|
|
|
|
opt[elements[0].toLowerCase()] = elements[1].toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
return opt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.opt2hash = function (opt, hash, name, layer) {
|
|
|
|
|
// 一些中文快捷参数
|
|
|
|
|
if (opt['上']) { hash['pivot'] = "top"; }
|
|
|
|
|
if (opt['左']) { hash['pivot'] = "left"; }
|
|
|
|
|
if (opt['右']) { hash['pivot'] = "right"; }
|
|
|
|
|
if (opt['下']) { hash['pivot'] = "bottom"; }
|
|
|
|
|
if (opt['左上']) { hash['pivot'] = "topleft"; }
|
|
|
|
|
if (opt['右上']) { hash['pivot'] = "topright"; }
|
|
|
|
|
if (opt['左下']) { hash['pivot'] = "bottomleft"; }
|
|
|
|
|
if (opt['右下']) { hash['pivot'] = "bottomright"; }
|
|
|
|
|
if (opt['水平伸展']) { hash['stretchx'] = "True"; }
|
|
|
|
|
if (opt['竖直伸展']) { hash['stretchy'] = "True"; }
|
|
|
|
|
if (opt['全屏']) { hash['full'] = "True"; hash['stretchxy'] = "True"; }
|
|
|
|
|
if (opt['竖直列表']) { hash['type'] = "List"; hash['scroll'] = "vertical"; }
|
|
|
|
|
if (opt['水平列表']) { hash['type'] = "List"; hash['scroll'] = "horizontal"; }
|
|
|
|
|
if (opt['图片']) { hash['imageName'] = opt['图片']; } else { hash['imageName'] = name; }
|
|
|
|
|
if (opt['遮罩']) { hash['type'] = "Mask"; hash['mask'] = "hard" }
|
|
|
|
|
//按钮可以覆盖遮罩,并在按钮上用遮罩组件
|
|
|
|
|
if (opt['按钮']) { hash['type'] = "Button"; }
|
|
|
|
|
//自定义了大小需要在unity端setnative
|
|
|
|
|
if (opt['高度'] || opt['宽度']) { hash['native'] = "True" }
|
|
|
|
|
if (opt['列表']) { hash['type'] = "List"; }
|
|
|
|
|
if (opt['进度条']) { hash['type'] = "Slider"; }
|
|
|
|
|
if (opt['滚动条']) { hash['type'] = "Scrollbar"; }
|
|
|
|
|
if (opt['开关']) { hash['type'] = "Toggle"; }
|
|
|
|
|
if (opt['预制体']) {
|
|
|
|
|
hash['type'] = "Prefab";
|
|
|
|
|
if (layer.typename !== 'ArtLayer') {
|
|
|
|
|
var x = layer.bounds[0].value
|
|
|
|
|
var y = layer.bounds[1].value
|
|
|
|
|
var w = layer.bounds[2].value - layer.bounds[0].value
|
|
|
|
|
var h = layer.bounds[3].value - layer.bounds[1].value
|
|
|
|
|
Util.UpdateHash(hash, {
|
|
|
|
|
x: x,
|
|
|
|
|
y: y,
|
|
|
|
|
w: w,
|
|
|
|
|
h: h,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
hash['prefabName'] = opt['预制体'];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.layerToHash = function (document, name, opt, layer) {
|
|
|
|
|
var align, bounds, e, hash, hh, originalText, pos, scale, text, textCenterOffset, textColor, textSize, textType, vh, vx, vy, ww, font;
|
|
|
|
|
document.activeLayer = layer;
|
|
|
|
|
hash = {};
|
|
|
|
|
var x = layer.bounds[0].value
|
|
|
|
|
var y = layer.bounds[1].value
|
|
|
|
|
var w = layer.bounds[2].value - layer.bounds[0].value
|
|
|
|
|
var h = layer.bounds[3].value - layer.bounds[1].value
|
|
|
|
|
if (layer.kind === LayerKind.TEXT) {
|
|
|
|
|
text = layer.textItem;
|
|
|
|
|
textSize = parseFloat(this.getTextSize());
|
|
|
|
|
originalText = '';
|
|
|
|
|
align = '';
|
|
|
|
|
//默认字体
|
|
|
|
|
font = 'AdobeHeitiStd-Regular';
|
|
|
|
|
textColor = 0x000000;
|
|
|
|
|
try {
|
|
|
|
|
originalText = text.contents.replace(/\r\n/g, '__CRLF__').replace(/\r/g, '__CRLF__').replace(/\n/g, '__CRLF__').replace(/__CRLF__/g, '\r\n');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
originalText = '';
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
font = text.font;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
font = 'AdobeHeitiStd-Regular';
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
textColor = text.color.rgb.hexValue;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
textColor = 0x000000;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
align = text.justification.toString().slice(14).toLowerCase();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
align = 'left';
|
|
|
|
|
}
|
|
|
|
|
hash = {
|
|
|
|
|
type: 'Text',
|
|
|
|
|
text: originalText,
|
|
|
|
|
font: font,
|
|
|
|
|
size: textSize,
|
|
|
|
|
color: textColor,
|
|
|
|
|
align: align,
|
|
|
|
|
x: x,
|
|
|
|
|
y: y,
|
|
|
|
|
w: w,
|
|
|
|
|
h: h,
|
|
|
|
|
opacity: Math.round(layer.opacity * 10.0) / 10.0
|
|
|
|
|
};
|
|
|
|
|
if (Util.hasStroke(document, layer)) {
|
|
|
|
|
hash['strokeSize'] = Util.getStrokeSize(document, layer);
|
|
|
|
|
hash['strokeColor'] = Util.getStrokeColor(document, layer).rgb.hexValue;
|
|
|
|
|
}
|
|
|
|
|
if (Util.hasShadow(document, layer)) {
|
|
|
|
|
hash['shadowColor'] = Util.getShadowColor(document, layer).rgb.hexValue
|
|
|
|
|
hash['shadowDis'] = Util.getShadowDis(document, layer)
|
|
|
|
|
hash['shadowBlur'] = Util.getShadowBlur(document, layer)
|
|
|
|
|
hash['shadowAngle'] = Util.getShadowAngle(document, layer)
|
|
|
|
|
}
|
|
|
|
|
if (Util.isVertical(document, layer)) {
|
|
|
|
|
hash['vertical'] = 'True'
|
|
|
|
|
}
|
|
|
|
|
if (Util.isItalic(document, layer)) {
|
|
|
|
|
hash['isItalic'] = 'True'
|
|
|
|
|
}
|
|
|
|
|
if (Util.hasGradient(document, layer)) {
|
|
|
|
|
hash['gradientAngle'] = Util.getGradientAngle(document, layer)
|
|
|
|
|
hash['gradientColor0'] = Util.getGradientColor(document, layer, 0).rgb.hexValue
|
|
|
|
|
hash['gradientColor1'] = Util.getGradientColor(document, layer, 1).rgb.hexValue
|
|
|
|
|
//渐变反向
|
|
|
|
|
if (Util.isGradientReverse(document, layer)) {
|
|
|
|
|
var tmp = hash['gradientColor0']
|
|
|
|
|
hash['gradientColor0'] = hash['gradientColor1']
|
|
|
|
|
hash['gradientColor1'] = tmp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
hash = {
|
|
|
|
|
type: 'Image',
|
|
|
|
|
image: Util.layerToImageName(layer),
|
|
|
|
|
x: x,
|
|
|
|
|
y: y,
|
|
|
|
|
w: w,
|
|
|
|
|
h: h,
|
|
|
|
|
opacity: Math.round(layer.opacity * 10.0) / 10.0
|
|
|
|
|
};
|
|
|
|
|
if (opt['九宫格']) {
|
|
|
|
|
hash['slice'] = opt['九宫格'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.opt2hash(opt, hash, name, layer);
|
|
|
|
|
return hash;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.angleFromMatrix = function (yy, xy) {
|
|
|
|
|
var toDegs;
|
|
|
|
|
toDegs = 180 / Math.PI;
|
|
|
|
|
return Math.atan2(yy, xy) * toDegs - 90;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.getActiveLayerTransform = function () {
|
|
|
|
|
var desc, ref, xx, xy, yx, yy;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
|
|
|
|
|
if (desc.hasKey(stringIDToTypeID('transform'))) {
|
|
|
|
|
desc = desc.getObjectValue(stringIDToTypeID('transform'));
|
|
|
|
|
xx = desc.getDouble(stringIDToTypeID('xx'));
|
|
|
|
|
xy = desc.getDouble(stringIDToTypeID('xy'));
|
|
|
|
|
yy = desc.getDouble(stringIDToTypeID('yy'));
|
|
|
|
|
yx = desc.getDouble(stringIDToTypeID('yx'));
|
|
|
|
|
return {
|
|
|
|
|
xx: xx,
|
|
|
|
|
xy: xy,
|
|
|
|
|
yy: yy,
|
|
|
|
|
yx: yx
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
xx: 0,
|
|
|
|
|
xy: 0,
|
|
|
|
|
yy: 0,
|
|
|
|
|
yx: 0
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.getTextSize = function () {
|
|
|
|
|
var desc, mFactor, ref, textSize;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
|
|
|
|
|
textSize = desc.getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle')).getDouble(stringIDToTypeID('size'));
|
|
|
|
|
if (desc.hasKey(stringIDToTypeID('transform'))) {
|
|
|
|
|
mFactor = desc.getObjectValue(stringIDToTypeID('transform')).getUnitDoubleValue(stringIDToTypeID("yy"));
|
|
|
|
|
textSize = (textSize * mFactor).toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
return textSize;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToJson.prototype.groupToHash = function (document, name, opt, layer) {
|
|
|
|
|
var hash;
|
|
|
|
|
hash = {
|
|
|
|
|
type: 'Group',
|
|
|
|
|
};
|
|
|
|
|
hash['elements'] = this.allLayers(document, layer);
|
|
|
|
|
|
|
|
|
|
this.opt2hash(opt, hash, name, layer);
|
|
|
|
|
return hash;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return PsdToJson;
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PsdToImage = (function () {
|
|
|
|
|
var baseFolder, fileNames;
|
|
|
|
|
|
|
|
|
|
function PsdToImage() { }
|
|
|
|
|
|
|
|
|
|
baseFolder = null;
|
|
|
|
|
|
|
|
|
|
fileNames = [];
|
|
|
|
|
|
|
|
|
|
var outputDoc
|
|
|
|
|
|
|
|
|
|
PsdToImage.prototype.run = function (document, saveFolder, documentName) {
|
|
|
|
|
var i, j, k, len, ref1, removeFiles, results, snapShotId, target, targets;
|
|
|
|
|
this.baseFolder = Folder(saveFolder + "/" + documentName);
|
|
|
|
|
if (this.baseFolder.exists) {
|
|
|
|
|
removeFiles = this.baseFolder.getFiles();
|
|
|
|
|
for (i = j = 0, ref1 = removeFiles.length; 0 <= ref1 ? j < ref1 : j > ref1; i = 0 <= ref1 ? ++j : --j) {
|
|
|
|
|
if (removeFiles[i].name.startsWith(documentName) && removeFiles[i].name.endsWith('.png')) {
|
|
|
|
|
removeFiles[i].remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.baseFolder.remove();
|
|
|
|
|
}
|
|
|
|
|
this.baseFolder.create();
|
|
|
|
|
targets = this.allLayers(document);
|
|
|
|
|
//snapShotId = Util.takeSnapshot(document);
|
|
|
|
|
results = [];
|
|
|
|
|
for (k = 0, len = targets.length; k < len; k++) {
|
|
|
|
|
target = targets[k];
|
|
|
|
|
target.visible = true;
|
|
|
|
|
this.outputLayer(document, target);
|
|
|
|
|
target.visible = false
|
|
|
|
|
// results.push(Util.revertToSnapshot(document, snapShotId));
|
|
|
|
|
}
|
|
|
|
|
outputDoc.close(SaveOptions.DONOTSAVECHANGES)
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToImage.prototype.allLayers = function (root) {
|
|
|
|
|
var j, layer, len, list, ref1;
|
|
|
|
|
ref1 = root.layers;
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
layer = ref1[j];
|
|
|
|
|
if (layer.kind === LayerKind.TEXT) {
|
|
|
|
|
layer.visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list = (function () {
|
|
|
|
|
var k, len1, ref2, results;
|
|
|
|
|
ref2 = root.layers;
|
|
|
|
|
results = [];
|
|
|
|
|
for (k = 0, len1 = ref2.length; k < len1; k++) {
|
|
|
|
|
layer = ref2[k];
|
|
|
|
|
if (layer.visible || Util.isIgnoreByName(layer.name)) {
|
|
|
|
|
if (layer.typename === 'ArtLayer') {
|
|
|
|
|
layer.visible = false;
|
|
|
|
|
results.push(layer);
|
|
|
|
|
} else {
|
|
|
|
|
results.push(this.allLayers(layer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}).call(this);
|
|
|
|
|
return Array.prototype.concat.apply([], list);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToImage.prototype.outputLayer = function (doc, layer) {
|
|
|
|
|
var fileName, layerName, opt, options, saveFile;
|
|
|
|
|
layer.opacity = 100.0;
|
|
|
|
|
fileName = Util.layerToImageName(layer);
|
|
|
|
|
var ss = layer.name.split("@");
|
|
|
|
|
layerName = ss[0];
|
|
|
|
|
opt = Util.parseOption(ss[1]);
|
|
|
|
|
|
|
|
|
|
//重名图片不覆盖不切图
|
|
|
|
|
if (indexOf.call(fileNames, fileName) >= 0) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//预制体不切图
|
|
|
|
|
if (opt['预制体']) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fileNames.push(fileName);
|
|
|
|
|
|
|
|
|
|
if (outputDoc == null)
|
|
|
|
|
outputDoc = app.documents.add(doc.width, doc.height, doc.resolution, doc.name + 'output.psd')
|
|
|
|
|
app.activeDocument = doc
|
|
|
|
|
layer.duplicate(outputDoc)
|
|
|
|
|
app.activeDocument = outputDoc
|
|
|
|
|
outputDoc.layers[1].remove()
|
|
|
|
|
layer = outputDoc.layers[0]
|
|
|
|
|
|
2024-10-21 16:20:39 +00:00
|
|
|
|
// if (opt['九宫格']) {
|
|
|
|
|
// if (!layer.isBackgroundLayer) {
|
|
|
|
|
// var param;
|
|
|
|
|
// if (opt['九宫格']) {
|
|
|
|
|
// param = opt['九宫格'];
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (opt['九宫格'] === "true") {
|
|
|
|
|
// this.snipImage(outputDoc, layer, opt);
|
|
|
|
|
// fileName += "-slice";
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// outputDoc = this.sliceCutImg(outputDoc, layerName, param);
|
|
|
|
|
// fileName += "-noslice";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// fileName += "-noslice";
|
|
|
|
|
// if (!layer.isBackgroundLayer) {
|
|
|
|
|
// this.snipImage(outputDoc, layer, opt);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (!layer.isBackgroundLayer) {
|
|
|
|
|
this.snipImage(outputDoc, layer, opt);
|
2024-10-08 15:19:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveFile = new File(this.baseFolder.fsName + "/" + fileName + ".png");
|
|
|
|
|
options = new ExportOptionsSaveForWeb();
|
|
|
|
|
options.format = SaveDocumentType.PNG;
|
|
|
|
|
options.PNG8 = false;
|
|
|
|
|
options.optimized = true;
|
|
|
|
|
options.interlaced = false;
|
|
|
|
|
outputDoc.exportDocument(saveFile, ExportType.SAVEFORWEB, options);
|
|
|
|
|
|
|
|
|
|
app.activeDocument = doc
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PsdToImage.prototype.snipImage = function (doc, layer, opt) {
|
|
|
|
|
layer.translate(-layer.bounds[0], -layer.bounds[1]);
|
|
|
|
|
var canvasWidth = layer.bounds[2] - layer.bounds[0]
|
|
|
|
|
var canvasHeight = layer.bounds[3] - layer.bounds[1]
|
|
|
|
|
var doTrim = true
|
|
|
|
|
if (opt['宽度']) {
|
|
|
|
|
canvasWidth = parseInt(opt['宽度'])
|
|
|
|
|
//摆到中间
|
|
|
|
|
layer.translate(-(canvasWidth - layer.bounds[2]) / 2, 0)
|
|
|
|
|
doTrim = false
|
|
|
|
|
}
|
|
|
|
|
if (opt['高度']) {
|
|
|
|
|
canvasHeight = parseInt(opt['高度'])
|
|
|
|
|
//摆到中间
|
|
|
|
|
layer.translate(0, (-(canvasHeight - layer.bounds[3]) / 2))
|
|
|
|
|
doTrim = false
|
|
|
|
|
}
|
|
|
|
|
doc.resizeCanvas(canvasWidth, canvasHeight, AnchorPosition.TOPLEFT);
|
|
|
|
|
if (doTrim)
|
|
|
|
|
doc.trim(TrimType.TRANSPARENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PsdToImage.prototype.sliceCutImg = function (doc, layerName, param) {
|
|
|
|
|
// 创建图层组
|
|
|
|
|
var _obj = doc.activeLayer
|
|
|
|
|
var stemGroup = doc.layerSets.add();
|
|
|
|
|
stemGroup.name = layerName
|
|
|
|
|
// _obj.move(stemGroup,ElementPlacement.PLACEATEND)
|
|
|
|
|
doc.mergeVisibleLayers();
|
|
|
|
|
doc.trim(TrimType.TRANSPARENT, true, true, true, true);
|
|
|
|
|
var width = doc.width;
|
|
|
|
|
var height = doc.height;
|
|
|
|
|
|
|
|
|
|
var nums = param.toString().split("|");
|
|
|
|
|
var sliceArr = new Array(0, 0, 0, 0);
|
|
|
|
|
if (nums.length == 1) {
|
|
|
|
|
for (var j = 0; j < sliceArr.length; j++) {
|
|
|
|
|
sliceArr[j] = parseInt(nums[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (nums.length == 4) {
|
|
|
|
|
for (var j = 0; j < sliceArr.length; j++) {
|
|
|
|
|
var num = parseInt(nums[j])
|
|
|
|
|
if (num == 0) {
|
|
|
|
|
if ((j) % 2 == 0) {
|
|
|
|
|
var symNumber = parseInt(nums[2 - j]);
|
|
|
|
|
num = height - symNumber;
|
|
|
|
|
} else {
|
|
|
|
|
var symNumber = parseInt(nums[4 - j]);
|
|
|
|
|
num = width - symNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sliceArr[j] = num;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
alert("图层名为:" + layerName + "的九宫格格式不对!应为name@九宫格=xx或name@九宫格=xx|xx|xx|xx");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _obj = doc.activeLayer
|
|
|
|
|
//左下左上,右上右下
|
|
|
|
|
var selRegion = Array(
|
|
|
|
|
Array(Array(0, sliceArr[1]), Array(0, 0), Array(sliceArr[0], 0), Array(sliceArr[0], sliceArr[1])),
|
|
|
|
|
Array(Array(width - sliceArr[2], sliceArr[1]), Array(width - sliceArr[2], 0), Array(width, 0), Array(width, sliceArr[1])),
|
|
|
|
|
Array(Array(0, height), Array(0, height - sliceArr[3]), Array(sliceArr[0], height - sliceArr[3]), Array(sliceArr[0], height)),
|
|
|
|
|
Array(Array(width - sliceArr[2], height), Array(width - sliceArr[2], height - sliceArr[3]), Array(width, height - sliceArr[3]), Array(width, height)),
|
|
|
|
|
);
|
|
|
|
|
for (var i = 0; i < selRegion.length; i++) {
|
|
|
|
|
doc.activeLayer = _obj;
|
|
|
|
|
doc.selection.select(selRegion[i]);
|
|
|
|
|
// doc.selection.copy();
|
|
|
|
|
executeAction(charIDToTypeID("CpTL"));
|
|
|
|
|
// var newStem = doc.paste();
|
|
|
|
|
var newStem = doc.activeLayer;
|
|
|
|
|
newStem.name = layerName + "_";
|
|
|
|
|
var deltaX = 0;
|
|
|
|
|
var deltaY = 0;
|
|
|
|
|
if (selRegion[i][0][0] != 0) {
|
|
|
|
|
deltaX = - (width - sliceArr[0] - sliceArr[2]);
|
|
|
|
|
}
|
|
|
|
|
if (selRegion[i][1][1] != 0) {
|
|
|
|
|
deltaY = - (height - sliceArr[1] - sliceArr[3]);
|
|
|
|
|
}
|
|
|
|
|
newStem.translate(deltaX, deltaY);
|
|
|
|
|
}
|
|
|
|
|
_obj.visible = false;
|
|
|
|
|
doc.mergeVisibleLayers();
|
|
|
|
|
doc.trim(TrimType.TRANSPARENT, true, true, true, true);
|
|
|
|
|
return doc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PsdToImage;
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
Util = (function () {
|
|
|
|
|
function Util() { }
|
|
|
|
|
|
|
|
|
|
Util.saveText = function (filePath, text) {
|
|
|
|
|
var file;
|
|
|
|
|
file = File(filePath);
|
|
|
|
|
file.encoding = "UTF8";
|
|
|
|
|
file.open("w", "TEXT");
|
|
|
|
|
file.write(text);
|
|
|
|
|
return file.close();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.layerToImageName = function (layer) {
|
|
|
|
|
return layer.name.split("@")[0];//encodeURI(Util.layerToImageNameLoop(layer)).replace(/%/g, '');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.layerToImageNameLoop = function (layer) {
|
|
|
|
|
var image, imageName;
|
|
|
|
|
if (layer instanceof Document) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
image = Util.layerToImageName(layer.parent);
|
|
|
|
|
imageName = image;
|
|
|
|
|
if (imageName !== "") {
|
|
|
|
|
imageName = imageName + "_";
|
|
|
|
|
}
|
|
|
|
|
return imageName + layer.name.split("@")[0].replace('_', '').replace(' ', '-').toLowerCase();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getLastSnapshotID = function (doc) {
|
|
|
|
|
var hsLength, hsObj, i, j, ref1;
|
|
|
|
|
hsObj = doc.historyStates;
|
|
|
|
|
hsLength = hsObj.length;
|
|
|
|
|
for (i = j = ref1 = hsLength - 1; ref1 <= -1 ? j <= -1 : j >= -1; i = ref1 <= -1 ? ++j : --j) {
|
|
|
|
|
if (hsObj[i].snapshot) {
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.takeSnapshot = function (doc) {
|
|
|
|
|
var desc153, ref119, ref120;
|
|
|
|
|
desc153 = new ActionDescriptor();
|
|
|
|
|
ref119 = new ActionReference();
|
|
|
|
|
ref119.putClass(charIDToTypeID("SnpS"));
|
|
|
|
|
desc153.putReference(charIDToTypeID("null"), ref119);
|
|
|
|
|
ref120 = new ActionReference();
|
|
|
|
|
ref120.putProperty(charIDToTypeID("HstS"), charIDToTypeID("CrnH"));
|
|
|
|
|
desc153.putReference(charIDToTypeID("From"), ref120);
|
|
|
|
|
executeAction(charIDToTypeID("Mk "), desc153, DialogModes.NO);
|
|
|
|
|
return Util.getLastSnapshotID(doc);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.revertToSnapshot = function (doc, snapshotID) {
|
|
|
|
|
return doc.activeHistoryState = doc.historyStates[snapshotID];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.hasStroke = function (doc, layer) {
|
|
|
|
|
var desc1, desc2, hasFX, hasStroke, ref, res;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
res = false;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects'));
|
|
|
|
|
if (hasFX) {
|
|
|
|
|
hasStroke = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('frameFX'));
|
|
|
|
|
if (hasStroke) {
|
|
|
|
|
desc1 = executeActionGet(ref);
|
|
|
|
|
desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX'));
|
|
|
|
|
if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) {
|
|
|
|
|
res = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.hasShadow = function (doc, layer) {
|
|
|
|
|
var desc1, desc2, hasFX, hasShadow, ref, res;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
res = false;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects'));
|
|
|
|
|
if (hasFX) {
|
|
|
|
|
hasShadow = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('dropShadow'));
|
|
|
|
|
if (hasShadow) {
|
|
|
|
|
desc1 = executeActionGet(ref);
|
|
|
|
|
desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
|
|
|
|
|
if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) {
|
|
|
|
|
res = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.isItalic = function (doc, layer) {
|
|
|
|
|
var desc1, desc2, hasFX, hasShadow, ref, res;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
res = false;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
var l = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')).getList(stringIDToTypeID('textStyleRange')).getObjectValue(0).getObjectValue(stringIDToTypeID('textStyle'))
|
|
|
|
|
var flag = l.hasKey(stringIDToTypeID('syntheticItalic')) && l.getBoolean(stringIDToTypeID('syntheticItalic'))
|
|
|
|
|
return flag
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.isVertical = function (doc, layer) {
|
|
|
|
|
var desc1, desc2, hasFX, hasShadow, ref, res;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
res = false;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
var hType = typeIDToStringID(executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey')).getEnumerationValue(stringIDToTypeID('orientation')))
|
|
|
|
|
return hType == "vertical"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.hasGradient = function (doc, layer) {
|
|
|
|
|
var desc1, desc2, hasFX, hasGradient, ref, res;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
res = false;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
hasFX = executeActionGet(ref).hasKey(stringIDToTypeID('layerEffects'));
|
|
|
|
|
if (hasFX) {
|
|
|
|
|
hasGradient = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).hasKey(stringIDToTypeID('gradientFill'));
|
|
|
|
|
if (hasGradient) {
|
|
|
|
|
desc1 = executeActionGet(ref);
|
|
|
|
|
desc2 = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill'));
|
|
|
|
|
if (desc1.getBoolean(stringIDToTypeID('layerFXVisible')) && desc2.getBoolean(stringIDToTypeID('enabled'))) {
|
|
|
|
|
res = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getStrokeSize = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX'));
|
|
|
|
|
return desc.getUnitDoubleValue(stringIDToTypeID('size'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getGradientColor = function (doc, layer, index) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
|
|
|
|
|
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill'))
|
|
|
|
|
var color = desc.getObjectValue(stringIDToTypeID('gradient')).getList(stringIDToTypeID('colors')).getObjectValue(index)
|
|
|
|
|
return Util.getColorFromDescriptor(color.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(color.getClass(stringIDToTypeID("color"))))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.isGradientReverse = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
|
|
|
|
|
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill'))
|
|
|
|
|
return desc.getBoolean(stringIDToTypeID('reverse'))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getGradientAngle = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
|
|
|
|
|
var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('gradientFill'))
|
|
|
|
|
return desc.getUnitDoubleValue(stringIDToTypeID('angle'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getShadowColor = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
|
|
|
|
|
//alert(Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color")))))
|
|
|
|
|
return Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color"))));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getShadowDis = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
|
|
|
|
|
//alert(desc.getUnitDoubleValue(stringIDToTypeID('distance')))
|
|
|
|
|
return desc.getUnitDoubleValue(stringIDToTypeID('distance'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getShadowBlur = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
|
|
|
|
|
//alert(desc.getUnitDoubleValue(stringIDToTypeID('blur')))
|
|
|
|
|
return desc.getUnitDoubleValue(stringIDToTypeID('blur'));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getShadowAngle = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('dropShadow'));
|
|
|
|
|
return desc.getBoolean(stringIDToTypeID('useGlobalAngle')) ? executeActionGet(ref).getUnitDoubleValue(stringIDToTypeID('globalAngle')) : desc.getUnitDoubleValue(stringIDToTypeID('localLightingAngle'))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getStrokeColor = function (doc, layer) {
|
|
|
|
|
var desc, ref;
|
|
|
|
|
doc.activeLayer = layer;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('layerEffects')).getObjectValue(stringIDToTypeID('frameFX'));
|
|
|
|
|
return Util.getColorFromDescriptor(desc.getObjectValue(stringIDToTypeID("color")), typeIDToCharID(desc.getClass(stringIDToTypeID("color"))));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getColorFromDescriptor = function (colorDesc, keyClass) {
|
|
|
|
|
var colorObject;
|
|
|
|
|
colorObject = new SolidColor();
|
|
|
|
|
if (keyClass === "Grsc") {
|
|
|
|
|
colorObject.grey.grey = color.getDouble(charIDToTypeID('Gry '));
|
|
|
|
|
}
|
|
|
|
|
if (keyClass === "RGBC") {
|
|
|
|
|
colorObject.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd '));
|
|
|
|
|
colorObject.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
|
|
|
|
|
colorObject.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl '));
|
|
|
|
|
}
|
|
|
|
|
if (keyClass === "CMYC") {
|
|
|
|
|
colorObject.cmyk.cyan = colorDesc.getDouble(charIDToTypeID('Cyn '));
|
|
|
|
|
colorObject.cmyk.magenta = colorDesc.getDouble(charIDToTypeID('Mgnt'));
|
|
|
|
|
colorObject.cmyk.yellow = colorDesc.getDouble(charIDToTypeID('Ylw '));
|
|
|
|
|
colorObject.cmyk.black = colorDesc.getDouble(charIDToTypeID('Blck'));
|
|
|
|
|
}
|
|
|
|
|
if (keyClass === "LbCl") {
|
|
|
|
|
colorObject.lab.l = colorDesc.getDouble(charIDToTypeID('Lmnc'));
|
|
|
|
|
colorObject.lab.a = colorDesc.getDouble(charIDToTypeID('A '));
|
|
|
|
|
colorObject.lab.b = colorDesc.getDouble(charIDToTypeID('B '));
|
|
|
|
|
}
|
|
|
|
|
return colorObject;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.deselectLayers = function () {
|
|
|
|
|
var desc01, ref01;
|
|
|
|
|
desc01 = new ActionDescriptor();
|
|
|
|
|
ref01 = new ActionReference();
|
|
|
|
|
ref01.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
|
|
|
|
|
desc01.putReference(charIDToTypeID('null'), ref01);
|
|
|
|
|
return executeAction(stringIDToTypeID('selectNoLayers'), desc01, DialogModes.NO);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.selectTransparency = function () {
|
|
|
|
|
var actionDesc, actionSelect, actionTransparent, idChnl;
|
|
|
|
|
idChnl = charIDToTypeID("Chnl");
|
|
|
|
|
actionSelect = new ActionReference();
|
|
|
|
|
actionSelect.putProperty(idChnl, charIDToTypeID("fsel"));
|
|
|
|
|
actionTransparent = new ActionReference();
|
|
|
|
|
actionTransparent.putEnumerated(idChnl, idChnl, charIDToTypeID("Trsp"));
|
|
|
|
|
actionDesc = new ActionDescriptor();
|
|
|
|
|
actionDesc.putReference(charIDToTypeID("null"), actionSelect);
|
|
|
|
|
actionDesc.putReference(charIDToTypeID("T "), actionTransparent);
|
|
|
|
|
return executeAction(charIDToTypeID("setd"), actionDesc, DialogModes.NO);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.getTextYScale = function (text_item) {
|
|
|
|
|
var bounds, desc, height, ref, transform, width, x_scale, y_scale;
|
|
|
|
|
app.activeDocument.activeLayer = text_item.parent;
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
|
|
|
|
|
desc = executeActionGet(ref).getObjectValue(stringIDToTypeID('textKey'));
|
|
|
|
|
bounds = desc.getObjectValue(stringIDToTypeID('bounds'));
|
|
|
|
|
width = bounds.getUnitDoubleValue(stringIDToTypeID('right'));
|
|
|
|
|
height = bounds.getUnitDoubleValue(stringIDToTypeID('bottom'));
|
|
|
|
|
x_scale = 1;
|
|
|
|
|
y_scale = 1;
|
|
|
|
|
if (desc.hasKey(stringIDToTypeID('transform'))) {
|
|
|
|
|
transform = desc.getObjectValue(stringIDToTypeID('transform'));
|
|
|
|
|
x_scale = transform.getUnitDoubleValue(stringIDToTypeID('xx'));
|
|
|
|
|
y_scale = transform.getUnitDoubleValue(stringIDToTypeID('yy'));
|
|
|
|
|
}
|
|
|
|
|
return y_scale;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.rasterizeLayerStyle = function (layer) {
|
|
|
|
|
var desc5, idLyr, idOrdn, idTrgt, idWhat, idlayerStyle, idnull, idrasterizeItem, idrasterizeLayer, ref4;
|
|
|
|
|
app.activeDocument.activeLayer = layer;
|
|
|
|
|
idrasterizeLayer = stringIDToTypeID("rasterizeLayer");
|
|
|
|
|
desc5 = new ActionDescriptor();
|
|
|
|
|
idnull = charIDToTypeID("null");
|
|
|
|
|
ref4 = new ActionReference();
|
|
|
|
|
idLyr = charIDToTypeID("Lyr ");
|
|
|
|
|
idOrdn = charIDToTypeID("Ordn");
|
|
|
|
|
idTrgt = charIDToTypeID("Trgt");
|
|
|
|
|
ref4.putEnumerated(idLyr, idOrdn, idTrgt);
|
|
|
|
|
desc5.putReference(idnull, ref4);
|
|
|
|
|
idWhat = charIDToTypeID("What");
|
|
|
|
|
idrasterizeItem = stringIDToTypeID("rasterizeItem");
|
|
|
|
|
idlayerStyle = stringIDToTypeID("layerStyle");
|
|
|
|
|
desc5.putEnumerated(idWhat, idrasterizeItem, idlayerStyle);
|
|
|
|
|
return executeAction(idrasterizeLayer, desc5, DialogModes.NO);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.rasterizeLayerMask = function (layer) {
|
|
|
|
|
app.activeDocument.activeLayer = layer;
|
|
|
|
|
if (Util.hasVectorMask()) {
|
|
|
|
|
Util.rasterizeLayer();
|
|
|
|
|
Util.selectVectorMask();
|
|
|
|
|
Util.rasterizeVectorMask();
|
|
|
|
|
Util.applyLayerMask();
|
|
|
|
|
}
|
|
|
|
|
if (Util.hasLayerMask()) {
|
|
|
|
|
Util.rasterizeLayer();
|
|
|
|
|
Util.selectLayerMask();
|
|
|
|
|
return Util.applyLayerMask();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 忽略
|
|
|
|
|
Util.isIgnoreByName = function (name) {
|
|
|
|
|
return name.startsWith('#') || Util.isInferiorIgnoreByName(name)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 忽略,但保留父节点宽高影响
|
|
|
|
|
Util.isInferiorIgnoreByName = function (name) {
|
|
|
|
|
return name.startsWith('$')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.UpdateHash = function (hashTarget, hashRes) {
|
|
|
|
|
for (var key in hashRes) {
|
|
|
|
|
hashTarget[key] = hashRes[key];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.hasVectorMask = function () {
|
|
|
|
|
var desc, e, hasVectorMask, keyKind, keyVectorMaskEnabled, kindValue, ref;
|
|
|
|
|
hasVectorMask = false;
|
|
|
|
|
try {
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
keyVectorMaskEnabled = app.stringIDToTypeID('vectorMask');
|
|
|
|
|
keyKind = app.charIDToTypeID('Knd ');
|
|
|
|
|
ref.putEnumerated(app.charIDToTypeID('Path'), app.charIDToTypeID('Ordn'), keyVectorMaskEnabled);
|
|
|
|
|
desc = executeActionGet(ref);
|
|
|
|
|
if (desc.hasKey(keyKind)) {
|
|
|
|
|
kindValue = desc.getEnumerationValue(keyKind);
|
|
|
|
|
if (kindValue === keyVectorMaskEnabled) {
|
|
|
|
|
hasVectorMask = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
hasVectorMask = false;
|
|
|
|
|
}
|
|
|
|
|
return hasVectorMask;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.hasLayerMask = function () {
|
|
|
|
|
var desc, e, hasLayerMask, keyUserMaskEnabled, ref;
|
|
|
|
|
hasLayerMask = false;
|
|
|
|
|
try {
|
|
|
|
|
ref = new ActionReference();
|
|
|
|
|
keyUserMaskEnabled = app.charIDToTypeID('UsrM');
|
|
|
|
|
ref.putProperty(app.charIDToTypeID('Prpr'), keyUserMaskEnabled);
|
|
|
|
|
ref.putEnumerated(app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt'));
|
|
|
|
|
desc = executeActionGet(ref);
|
|
|
|
|
if (desc.hasKey(keyUserMaskEnabled)) {
|
|
|
|
|
hasLayerMask = true;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
hasLayerMask = false;
|
|
|
|
|
}
|
|
|
|
|
return hasLayerMask;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.rasterizeLayer = function () {
|
|
|
|
|
var desc245, id1242, id1243, id1244, id1245, id1246, ref184;
|
|
|
|
|
try {
|
|
|
|
|
id1242 = stringIDToTypeID("rasterizeLayer");
|
|
|
|
|
desc245 = new ActionDescriptor();
|
|
|
|
|
id1243 = charIDToTypeID("null");
|
|
|
|
|
ref184 = new ActionReference();
|
|
|
|
|
id1244 = charIDToTypeID("Lyr ");
|
|
|
|
|
id1245 = charIDToTypeID("Ordn");
|
|
|
|
|
id1246 = charIDToTypeID("Trgt");
|
|
|
|
|
ref184.putEnumerated(id1244, id1245, id1246);
|
|
|
|
|
desc245.putReference(id1243, ref184);
|
|
|
|
|
return executeAction(id1242, desc245, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.selectVectorMask = function () {
|
|
|
|
|
var desc15, e, id55, id56, id57, id58, id59, id60, id61, id62, ref13;
|
|
|
|
|
try {
|
|
|
|
|
id55 = charIDToTypeID("slct");
|
|
|
|
|
desc15 = new ActionDescriptor();
|
|
|
|
|
id56 = charIDToTypeID("null");
|
|
|
|
|
ref13 = new ActionReference();
|
|
|
|
|
id57 = charIDToTypeID("Path");
|
|
|
|
|
id58 = charIDToTypeID("Path");
|
|
|
|
|
id59 = stringIDToTypeID("vectorMask");
|
|
|
|
|
ref13.putEnumerated(id57, id58, id59);
|
|
|
|
|
id60 = charIDToTypeID("Lyr ");
|
|
|
|
|
id61 = charIDToTypeID("Ordn");
|
|
|
|
|
id62 = charIDToTypeID("Trgt");
|
|
|
|
|
ref13.putEnumerated(id60, id61, id62);
|
|
|
|
|
desc15.putReference(id56, ref13);
|
|
|
|
|
return executeAction(id55, desc15, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.selectLayerMask = function () {
|
|
|
|
|
var desc153, e, id759, id760, id761, id762, id763, id764, ref92;
|
|
|
|
|
try {
|
|
|
|
|
id759 = charIDToTypeID("slct");
|
|
|
|
|
desc153 = new ActionDescriptor();
|
|
|
|
|
id760 = charIDToTypeID("null");
|
|
|
|
|
ref92 = new ActionReference();
|
|
|
|
|
id761 = charIDToTypeID("Chnl");
|
|
|
|
|
id762 = charIDToTypeID("Chnl");
|
|
|
|
|
id763 = charIDToTypeID("Msk ");
|
|
|
|
|
ref92.putEnumerated(id761, id762, id763);
|
|
|
|
|
desc153.putReference(id760, ref92);
|
|
|
|
|
id764 = charIDToTypeID("MkVs");
|
|
|
|
|
desc153.putBoolean(id764, false);
|
|
|
|
|
return executeAction(id759, desc153, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.rasterizeVectorMask = function () {
|
|
|
|
|
var desc44, e, id488, id489, id490, id491, id492, id493, id494, id495, ref29;
|
|
|
|
|
try {
|
|
|
|
|
id488 = stringIDToTypeID("rasterizeLayer");
|
|
|
|
|
desc44 = new ActionDescriptor();
|
|
|
|
|
id489 = charIDToTypeID("null");
|
|
|
|
|
ref29 = new ActionReference();
|
|
|
|
|
id490 = charIDToTypeID("Lyr ");
|
|
|
|
|
id491 = charIDToTypeID("Ordn");
|
|
|
|
|
id492 = charIDToTypeID("Trgt");
|
|
|
|
|
ref29.putEnumerated(id490, id491, id492);
|
|
|
|
|
desc44.putReference(id489, ref29);
|
|
|
|
|
id493 = charIDToTypeID("What");
|
|
|
|
|
id494 = stringIDToTypeID("rasterizeItem");
|
|
|
|
|
id495 = stringIDToTypeID("vectorMask");
|
|
|
|
|
desc44.putEnumerated(id493, id494, id495);
|
|
|
|
|
return executeAction(id488, desc44, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.applyLayerMask = function () {
|
|
|
|
|
var desc154, e, id765, id766, id767, id768, id769, id770, ref93;
|
|
|
|
|
try {
|
|
|
|
|
id765 = charIDToTypeID("Dlt ");
|
|
|
|
|
desc154 = new ActionDescriptor();
|
|
|
|
|
id766 = charIDToTypeID("null");
|
|
|
|
|
ref93 = new ActionReference();
|
|
|
|
|
id767 = charIDToTypeID("Chnl");
|
|
|
|
|
id768 = charIDToTypeID("Ordn");
|
|
|
|
|
id769 = charIDToTypeID("Trgt");
|
|
|
|
|
ref93.putEnumerated(id767, id768, id769);
|
|
|
|
|
desc154.putReference(id766, ref93);
|
|
|
|
|
id770 = charIDToTypeID("Aply");
|
|
|
|
|
desc154.putBoolean(id770, true);
|
|
|
|
|
return executeAction(id765, desc154, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.mergeGroup = function (layer) {
|
|
|
|
|
var desc15, e, idMrgtwo;
|
|
|
|
|
app.activeDocument.activeLayer = layer;
|
|
|
|
|
try {
|
|
|
|
|
idMrgtwo = charIDToTypeID("Mrg2");
|
|
|
|
|
desc15 = new ActionDescriptor();
|
|
|
|
|
return executeAction(idMrgtwo, desc15, DialogModes.NO);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
e = error;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Util.parseOption = function (text) {
|
|
|
|
|
var elements, j, len, opt, optText, ref1;
|
|
|
|
|
if (!text) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
opt = {};
|
|
|
|
|
ref1 = text.split(",");
|
|
|
|
|
for (j = 0, len = ref1.length; j < len; j++) {
|
|
|
|
|
optText = ref1[j];
|
|
|
|
|
elements = optText.split("=");
|
|
|
|
|
if (elements.length === 1) {
|
|
|
|
|
elements[1] = 'true';
|
|
|
|
|
}
|
|
|
|
|
opt[elements[0].toLowerCase()] = elements[1].toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
return opt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Util;
|
|
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
String.prototype.startsWith = function (str) {
|
|
|
|
|
return this.slice(0, str.length) === str;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
String.prototype.endsWith = function (suffix) {
|
|
|
|
|
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
String.prototype.strip = function () {
|
|
|
|
|
if (String.prototype.trim != null) {
|
|
|
|
|
return this.trim();
|
|
|
|
|
} else {
|
|
|
|
|
return this.replace(/^\s+|\s+$/g, "");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setup = function () {
|
|
|
|
|
preferences.rulerUnits = Units.PIXELS;
|
|
|
|
|
return preferences.typeUnits = TypeUnits.PIXELS;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setup();
|
|
|
|
|
|
|
|
|
|
baum = new Baum();
|
|
|
|
|
|
|
|
|
|
baum.run();
|
|
|
|
|
|
|
|
|
|
}).call(this);
|