346 lines
56 KiB
JavaScript
346 lines
56 KiB
JavaScript
|
|
/*
|
||
|
|
|
||
|
|
<javascriptresource>
|
||
|
|
<name>Get Patterns File Info...</name>
|
||
|
|
<about>"Get Patterns File Info" v1.1
|
||
|
|
|
||
|
|
Get basic information from a patterns file (.pat) or a patterns preferences file (Patterns.psp).
|
||
|
|
|
||
|
|
Utility script using the "JSON Action Manager" scripting library.
|
||
|
|
© 2015 Michel MARIANI.
|
||
|
|
</about>
|
||
|
|
<menu>automate</menu>
|
||
|
|
<category>JSON Action Manager Patterns Utility</category>
|
||
|
|
</javascriptresource>
|
||
|
|
|
||
|
|
*/
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// File: Get Patterns File Info.js
|
||
|
|
// Version: 1.1
|
||
|
|
// Release Date: 2015-11-27
|
||
|
|
// Copyright: © 2015 Michel MARIANI <http://www.tonton-pixel.com/blog/>
|
||
|
|
// Licence: GPL <http://www.gnu.org/licenses/gpl.html>
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// This program is free software: you can redistribute it and/or modify
|
||
|
|
// it under the terms of the GNU General Public License as published by
|
||
|
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
|
// (at your option) any later version.
|
||
|
|
//
|
||
|
|
// This program is distributed in the hope that it will be useful,
|
||
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
// GNU General Public License for more details.
|
||
|
|
//
|
||
|
|
// You should have received a copy of the GNU General Public License
|
||
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
// Version History:
|
||
|
|
// 1.1:
|
||
|
|
// - Used new version 4.4.4 of jamEngine scripting library module.
|
||
|
|
// 1.0:
|
||
|
|
// - Initial release.
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
// jamEngine.jsxinc v4.4.4 (minified)
|
||
|
|
if(typeof jamEngine!=='object') {var jamEngine={};(function() {var that;jamEngine.meaningfulIds=false;jamEngine.parseFriendly=false;jamEngine.displayDialogs=DialogModes.ERROR;var conflictingStringIdStrs={"'Algn'":["align","alignment"],"'AntA'":["antiAlias","antiAliasedPICTAcquire"],"'BckL'":["backgroundLayer","backgroundLevel"],"'BlcG'":["blackGenerationType","blackGenerationCurve"],"'BlcL'":["blackLevel","blackLimit"],"'Blks'":["blacks","blocks"],"'BlrM'":["blurMethod","blurMore"],"'BrgC'":["brightnessEvent","brightnessContrast"],"'BrsD'":["brushDetail","brushesDefine"],"'Brsh'":["brush","brushes"],"'Clcl'":["calculation","calculations"],"'ClrP'":["colorPalette","coloredPencil"],"'Cnst'":["constant","constrain"],"'CntC'":["centerCropMarks","conteCrayon"],"'Cntr'":["center","contrast"],"'CrtD'":["createDroplet","createDuplicate"],"'CstP'":["customPalette","customPhosphors"],"'Cstm'":["custom","customPattern"],"'Drkn'":["darken","darkness"],"'Dstr'":["distort","distortion","distribute","distribution"],"'Dstt'":["desaturate","destWhiteMax"],"'FlIn'":["fileInfo","fillInverse"],"'Gd '":["good","guide"],"'GnrP'":["generalPreferences","generalPrefs","preferencesClass"],"'GrSt'":["grainStippled","graySetup"],"'Grdn'":["gradientClassEvent","gridMinor"],"'Grn '":["grain","green"],"'Grns'":["graininess","greens"],"'HstP'":["historyPreferences","historyPrefs"],"'HstS'":["historyState","historyStateSourceType"],"'ImgP'":["imageCachePreferences","imagePoint"],"'In '":["in","stampIn"],"'IntW'":["interfaceWhite","intersectWith"],"'Intr'":["interfaceIconFrameDimmed","interlace","interpolation","intersect"],"'JPEG'":["JPEG","JPEGFormat"],"'LghD'":["lightDirection","lightDirectional"],"'LghO'":["lightOmni","lightenOnly"],"'LghS'":["lightSource","lightSpot"],"'Lns '":["lens","lines"],"'Mgnt'":["magenta","magentas"],"'MrgL'":["mergeLayers","mergedLayers"],"'Mxm '":["maximum","maximumQuality"],"'NTSC'":["NTSC","NTSCColors"],"'NmbL'":["numberOfLayers","numberOfLevels"],"'PlgP'":["pluginPicker","pluginPrefs"],"'Pncl'":["pencilEraser","pencilWidth"],"'Pnt '":["paint","point"],"'Prsp'":["perspective","perspectiveIndex"],"'PrvM'":["previewMacThumbnail","previewMagenta"],"'Pstr'":["posterization","posterize"],"'RGBS'":["RGBSetup","RGBSetupSource"],"'Rds '":["radius","reds"],"'ScrD'":["scratchDisks","screenDot"],"'ShdI'":["shadingIntensity","shadowIntensity"],"'ShpC'":["shapeCurveType","shapingCurve"],"'ShrE'":["sharpenEdges","shearEd"],"'Shrp'":["sharpen","sharpness"],"'SplC'":["splitChannels","supplementalCategories"],"'Spot'":["spot","spotColor"],"'SprS'":["separationSetup","sprayedStrokes"],"'StrL'":["strokeLength","strokeLocation"],"'Strt'":["saturation","start"],"'TEXT'":["char","textType"],"'TIFF'":["TIFF","TIFFFormat"],"'TglO'":["toggleOptionsPalette","toggleOthers"],"'TrnG'":["transparencyGamutPreferences","transparencyGrid","transparencyGridSize"],"'TrnS'":["transferSpec","transparencyShape","transparencyStop"],"'Trns'":["transparency","transparent"],"'TxtC'":["textClickPoint","textureCoverage"],"'TxtF'":["textureFile","textureFill"],"'UsrM'":["userMaskEnabled","userMaskOptions"],"'c@#^'":["inherits","pInherits"],"'comp'":["comp","sInt64"],"'doub'":["floatType","IEEE64BitFloatingPoint","longFloat"],"'long'":["integer","longInteger","sInt32"],"'magn'":["magnitude","uInt32"],"'null'":["null","target"],"'shor'":["sInt16","sMInt","shortInteger"],"'sing'":["IEEE32BitFloatingPoint","sMFloat","shortFloat"]};jamEngine.getConflictingStringIdStrs=function(charIdStr) {return conflictingStringIdStrs[charIdStr]||null;};jamEngine.uniIdStrToId=function(uniIdStr) {var id=0;if(typeof uniIdStr==='string') {if((uniIdStr.length===(1+4+1))&&(uniIdStr.charAt(0)==="'")&&(uniIdStr.charAt(5)==="'")) {id=app.charIDToTypeID(uniIdStr.substring(1,5));} else {id=app.stringIDToTypeID(uniIdStr);}} return id;};var smallestHashValue=app.charIDToTypeID(" ");jamEngine.idToUniIdStrs=function(id) {var charIdStr="";var stringIdStr=app.typeIDToStringID(id);if(id>=smallestHashValue) {charIdStr="'"+app.typeIDToCharID(id)+"'";if(stringIdStr!=="") {if(charIdStr in conflicting
|
||
|
|
// jamJSON.jsxinc v4.4 (minified)
|
||
|
|
if(typeof jamJSON!=='object') {var jamJSON={};(function() {var state;var stack;var container;var key;var value;var escapes={'\\':'\\','"':'"','/':'/','t':'\t','n':'\n','r':'\r','f':'\f','b':'\b'};var action={'{':{go:function() {stack.push({state:'ok'});container={};state='firstokey';},ovalue:function() {stack.push({container:container,state:'ocomma',key:key});container={};state='firstokey';},firstavalue:function() {stack.push({container:container,state:'acomma'});container={};state='firstokey';},avalue:function() {stack.push({container:container,state:'acomma'});container={};state='firstokey';}},'}':{firstokey:function() {var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state;},ocomma:function() {var pop=stack.pop();container[key]=value;value=container;container=pop.container;key=pop.key;state=pop.state;}},'[':{go:function() {stack.push({state:'ok'});container=[];state='firstavalue';},ovalue:function() {stack.push({container:container,state:'ocomma',key:key});container=[];state='firstavalue';},firstavalue:function() {stack.push({container:container,state:'acomma'});container=[];state='firstavalue';},avalue:function() {stack.push({container:container,state:'acomma'});container=[];state='firstavalue';}},']':{firstavalue:function() {var pop=stack.pop();value=container;container=pop.container;key=pop.key;state=pop.state;},acomma:function() {var pop=stack.pop();container.push(value);value=container;container=pop.container;key=pop.key;state=pop.state;}},':':{colon:function() {if(container.hasOwnProperty(key)) {throw new SyntaxError("[jamJSON.parse] Duplicate key: “"+key+"”");} state='ovalue';}},',':{ocomma:function() {container[key]=value;state='okey';},acomma:function() {container.push(value);state='avalue';}},'true':{go:function() {value=true;state='ok';},ovalue:function() {value=true;state='ocomma';},firstavalue:function() {value=true;state='acomma';},avalue:function() {value=true;state='acomma';}},'false':{go:function() {value=false;state='ok';},ovalue:function() {value=false;state='ocomma';},firstavalue:function() {value=false;state='acomma';},avalue:function() {value=false;state='acomma';}},'null':{go:function() {value=null;state='ok';},ovalue:function() {value=null;state='ocomma';},firstavalue:function() {value=null;state='acomma';},avalue:function() {value=null;state='acomma';}}};var number={go:function() {state='ok';},ovalue:function() {state='ocomma';},firstavalue:function() {state='acomma';},avalue:function() {state='acomma';}};var string={go:function() {state='ok';},firstokey:function() {key=value;state='colon';},okey:function() {key=value;state='colon';},ovalue:function() {state='ocomma';},firstavalue:function() {state='acomma';},avalue:function() {state='acomma';}};var commentFunc=function(){};function debackslashify(text) {return text.replace(/\\(?:u(.{4})|([^u]))/g,function(a,b,c){return(b)?String.fromCharCode(parseInt(b,16)):escapes[c];});} jamJSON.parse=function(text,validate,allowComments) {if(validate) {var tx=/^[\x20\t\n\r]*(?:([,:\[\]{}]|true|false|null)|(-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+\-]?[0-9]+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/;var txc=/^[\x20\t\n\r]*(?:(\/(?:\/.*|\*(?:.|[\r\n])*?\*\/))|([,:\[\]{}]|true|false|null)|(-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+\-]?[0-9]+)?)|"((?:[^\r\n\t\\\"]|\\(?:["\\\/trnfb]|u[0-9a-fA-F]{4}))*)")/;var r;var i;var actionFunc;state='go';stack=[];try {while(true) {i=(allowComments)?1:0;r=(allowComments)?txc.exec(text):tx.exec(text);if(!r) {break;} if(allowComments&&r[1]) {actionFunc=commentFunc;} else if(r[i+1]) {actionFunc=action[r[i+1]][state];} else if(r[i+2]) {value=+r[i+2];actionFunc=number[state];} else {value=debackslashify(r[i+3]);actionFunc=string[state];} if(actionFunc) {actionFunc();text=text.slice(r[0].length);} else {break;}}} catch(e) {state=e;} if(state!=='ok'||/[^\x20\t\n\r]/.test(text)) {throw state instanceof SyntaxError?state:new SyntaxError("[jamJSON.parse] Invalid JSON");} return value;} else {return eval('('+text+')');}};var escapable=/[\\\"\x00-\x1F\x7F-\x9F\u00AD\u0600-\u0604
|
||
|
|
// jamUtils.jsxinc v4.4 (minified)
|
||
|
|
if(typeof jamUtils!=='object') {var jamUtils={};(function() {jamUtils.toDistanceUnit=function(amount,amountBasePerInch) {return(amount/amountBasePerInch)*72.0;};jamUtils.fromDistanceUnit=function(amount,amountBasePerInch) {return(amount/72.0)*amountBasePerInch;};jamUtils.fontExists=function(fontPostScriptName) {var useDOM=true;var found=false;if(useDOM) {for(var i=0;i<app.fonts.length;i++) {if(app.fonts[i].postScriptName===fontPostScriptName) {found=true;break;}}} else {var saveMeaningfulIds=jamEngine.meaningfulIds;var saveParseFriendly=jamEngine.parseFriendly;jamEngine.meaningfulIds=true;jamEngine.parseFriendly=true;var resultDescriptorObj=jamEngine.jsonGet ([["property",["<property>","fontList"]],["application",["<enumerated>",["ordinal","targetEnum"]]]]);var fontPostScriptNameArr=resultDescriptorObj["fontList"][1][1]["fontPostScriptName"][1];for(var i=0;i<fontPostScriptNameArr.length;i++) {if(fontPostScriptNameArr[i][1]===fontPostScriptName) {found=true;break;}} jamEngine.meaningfulIds=saveMeaningfulIds;jamEngine.parseFriendly=saveParseFriendly;} return found;};jamUtils.loadAction=function(action,actionSet,actionsFilePath) {try {jamEngine.jsonGet([["action",["<name>",action]],["actionSet",["<name>",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["<path>",actionsFilePath]});}};jamUtils.loadActionSet=function(actionSet,actionsFilePath) {try {jamEngine.jsonGet([["actionSet",["<name>",actionSet]]]);var found=true;} catch(e) {var found=false;} if(!found) {jamEngine.jsonPlay("open",{"target":["<path>",actionsFilePath]});}};jamUtils.loadPreset=function(presetProperty,presetName,presetFilePath) {var useDOM=false;var useOpen=true;var classes={"brush":"brush","colors":"color","gradientClassEvent":"gradientClassEvent","style":"styleClass","pattern":"'PttR'","shapingCurve":"shapingCurve","customShape":"customShape","toolPreset":"toolPreset"};var presetClass=classes[presetProperty];var saveMeaningfulIds=jamEngine.meaningfulIds;var saveParseFriendly=jamEngine.parseFriendly;jamEngine.meaningfulIds=true;jamEngine.parseFriendly=true;var found=false;var resultDescriptorObj=jamEngine.jsonGet ([["property",["<property>","presetManager"]],["application",["<enumerated>",["ordinal","targetEnum"]]]]);var presetManagerArr=resultDescriptorObj["presetManager"][1];for(var i=0;i<presetManagerArr.length;i++) {var presets=presetManagerArr[i][1];if(presets[0]===presetClass) {var presetsArr=presets[1]["name"][1];for(var j=0;j<presetsArr.length;j++) {if(presetsArr[j][1]===presetName) {found=true;break;}} break;}} if(!found) {if(useDOM) {app.load(new File(presetFilePath));} else if(useOpen) {jamEngine.jsonPlay("open",{"target":["<path>",presetFilePath]});} else {jamEngine.jsonPlay ("set",{"target":["<reference>",[["property",["<property>",presetProperty]],["application",["<enumerated>",["ordinal","targetEnum"]]]]],"to":["<path>",presetFilePath],"append":["<boolean>",true]});}} jamEngine.meaningfulIds=saveMeaningfulIds;jamEngine.parseFriendly=saveParseFriendly;};function getFileObject(file) {var fileObject;if(file instanceof File) {fileObject=file;} else if(typeof file==='string') {fileObject=new File(file);} else {throw new Error('[jamUtils getFileObject] Invalid argument');} return fileObject;} jamUtils.readTextFile=function(textFile) {var text=null;var file=getFileObject(textFile);if(file.open("r")) {text=file.read();file.close();} return text;};jamUtils.readJsonFile=function(jsonFile) {return jamJSON.parse(this.readTextFile(jsonFile),true);};jamUtils.writeTextFile=function(textFile,text) {var file=getFileObject(textFile);if(file.open('w','TEXT')) {file.encoding='UTF-8';file.lineFeed='unix';file.write('\uFEFF');file.write(text);file.close();}};jamUtils.writeJsonFile=function(jsonFile,data,space) {this.writeTextFile(jsonFile,jamJSON.stringify(data,space));};jamUtils.cloneData=function(data) {var clone;if(data===null) {clone=data;} else if(data.constructor===Object) {clone={};for(var k in data) {if(data.hasOwnProperty(k)) {clone[k]=this.cloneData(data[k]);}}} else if(data.constructor===Array)
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
var signature = "json-action-manager-get-patterns-file-info-options";
|
||
|
|
|
||
|
|
var defaultOptions =
|
||
|
|
{
|
||
|
|
defaultInFolder: "~/Desktop",
|
||
|
|
defaultOutputFile: "~/Desktop/patterns-file-info.json",
|
||
|
|
dialogWidth: 600,
|
||
|
|
dialogHeight: 800,
|
||
|
|
dialogX: 0,
|
||
|
|
dialogY: 0
|
||
|
|
};
|
||
|
|
var customOptions;
|
||
|
|
|
||
|
|
var defaultOutputFile = new File (defaultOptions.defaultOutputFile);
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function getPatternsFileInfo ()
|
||
|
|
{
|
||
|
|
var info = null;
|
||
|
|
function isPatFile (f)
|
||
|
|
{
|
||
|
|
return ((f.type === '8BPT') || f.name.match (/\.pat$/i)) || f.name.match (/^Patterns.psp$/i);
|
||
|
|
}
|
||
|
|
var patFilter =
|
||
|
|
(File.fs === "Macintosh") ?
|
||
|
|
function (f) { return (f instanceof Folder) || isPatFile (f) } :
|
||
|
|
"Patterns Files:*.pat,Patterns Preferences File:Patterns.psp,All Files:*.*";
|
||
|
|
var defaultInFolder = new Folder (customOptions.defaultInFolder);
|
||
|
|
var inFile = defaultInFolder.openDlg ("Open patterns file:", patFilter);
|
||
|
|
if (inFile)
|
||
|
|
{
|
||
|
|
customOptions.defaultInFolder = inFile.parent.fsName;
|
||
|
|
if (inFile.open ('r'))
|
||
|
|
{
|
||
|
|
function readBEInt (file, byteCount)
|
||
|
|
{
|
||
|
|
var bytes = file.read (byteCount);
|
||
|
|
var intValue = 0;
|
||
|
|
for (var index = 0; index < byteCount; index++)
|
||
|
|
{
|
||
|
|
intValue = (intValue << 8) + bytes.charCodeAt (index);
|
||
|
|
}
|
||
|
|
return intValue;
|
||
|
|
}
|
||
|
|
function readUnicodeString (file)
|
||
|
|
{
|
||
|
|
var unicodeString = "";
|
||
|
|
var unicodeLength = readBEInt (file, 4); // Includes terminating null
|
||
|
|
for (var index = 0; index < unicodeLength; index++)
|
||
|
|
{
|
||
|
|
var unicodeChar = readBEInt (file, 2);
|
||
|
|
if (unicodeChar !== 0)
|
||
|
|
{
|
||
|
|
unicodeString += String.fromCharCode (unicodeChar);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return unicodeString;
|
||
|
|
}
|
||
|
|
function readBytes (file, byteCount)
|
||
|
|
{
|
||
|
|
return file.read (byteCount);
|
||
|
|
}
|
||
|
|
function readPascalString (file)
|
||
|
|
{
|
||
|
|
var stringLength = readBEInt (file, 1);
|
||
|
|
return readBytes (file, stringLength);
|
||
|
|
}
|
||
|
|
function skipBytes (file, byteCount)
|
||
|
|
{
|
||
|
|
file.seek (byteCount, 1);
|
||
|
|
}
|
||
|
|
//
|
||
|
|
info = { };
|
||
|
|
inFile.encoding = 'BINARY';
|
||
|
|
var magicNumber = readBytes (inFile, 4);
|
||
|
|
if (magicNumber === '8BPT')
|
||
|
|
{
|
||
|
|
var formatVersion = readBEInt (inFile, 2);
|
||
|
|
if (formatVersion === 1)
|
||
|
|
{
|
||
|
|
var imageModes = [ "Bitmap", "Grayscale", "Indexed", "RGB", "CMYK", null, null, "Multichannel", "Duotone", "Lab" ];
|
||
|
|
var patterns = [ ];
|
||
|
|
var patternCount = readBEInt (inFile, 4);
|
||
|
|
for (var index = 0; index < patternCount; index++)
|
||
|
|
{
|
||
|
|
var pattern = { };
|
||
|
|
var patternVersion = readBEInt (inFile, 4);
|
||
|
|
if (patternVersion === 1)
|
||
|
|
{
|
||
|
|
pattern["version"] = patternVersion;
|
||
|
|
pattern["imageMode"] = imageModes[readBEInt (inFile, 4)];
|
||
|
|
pattern["height"] = readBEInt (inFile, 2);
|
||
|
|
pattern["width"] = readBEInt (inFile, 2);
|
||
|
|
pattern["name"] = localize (readUnicodeString (inFile));
|
||
|
|
pattern["ID"] = readPascalString (inFile);
|
||
|
|
if (pattern["imageMode"] === "Indexed")
|
||
|
|
{
|
||
|
|
skipBytes (inFile, 256 * 3); // Color table
|
||
|
|
skipBytes (inFile, 4); // ??
|
||
|
|
}
|
||
|
|
// Virtual Memory Array List
|
||
|
|
var vmalVersion = readBEInt (inFile, 4);
|
||
|
|
if (vmalVersion === 3)
|
||
|
|
{
|
||
|
|
var vmalLength = readBEInt (inFile, 4);
|
||
|
|
skipBytes (inFile, vmalLength);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
pattern["error"] = "Unsupported VMAL version: " + vmalVersion;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
pattern["error"] = "Unsupported pattern version: " + patternVersion;
|
||
|
|
}
|
||
|
|
patterns.push (pattern);
|
||
|
|
if ("error" in pattern)
|
||
|
|
{
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
info["patterns"] = patterns;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
info["error"] = "Unsupported patterns file format version: " + formatVersion;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
inFile.close ();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
alert ("Error: cannot open patterns file.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return info;
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function displayDialog (info)
|
||
|
|
{
|
||
|
|
// Get an available UI font among a list of favorites
|
||
|
|
function getAvailableUIFont (fontsArray)
|
||
|
|
{
|
||
|
|
// List all fonts available in Photoshop in JSON format
|
||
|
|
var fontsObj = { };
|
||
|
|
for (var i = 0; i < app.fonts.length; i++)
|
||
|
|
{
|
||
|
|
var family = app.fonts[i].family;
|
||
|
|
if (!(family in fontsObj))
|
||
|
|
{
|
||
|
|
fontsObj[family] = { };
|
||
|
|
}
|
||
|
|
fontsObj[family][app.fonts[i].style] =
|
||
|
|
{
|
||
|
|
"name": app.fonts[i].name
|
||
|
|
};
|
||
|
|
}
|
||
|
|
var availableFont;
|
||
|
|
var fontFamily;
|
||
|
|
var fontStyle;
|
||
|
|
var fontSize;
|
||
|
|
for (var i = 0; i < fontsArray.length; i++)
|
||
|
|
{
|
||
|
|
fontFamily = fontsArray[i][0];
|
||
|
|
if (fontFamily in fontsObj)
|
||
|
|
{
|
||
|
|
fontStyle = fontsArray[i][1];
|
||
|
|
if (fontStyle in fontsObj[fontFamily])
|
||
|
|
{
|
||
|
|
fontSize = fontsArray[i][2];
|
||
|
|
availableFont = ScriptUI.newFont (fontFamily, fontStyle, fontSize)
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return availableFont;
|
||
|
|
}
|
||
|
|
var monospacedFont =
|
||
|
|
getAvailableUIFont
|
||
|
|
(
|
||
|
|
[
|
||
|
|
[ "Monaco", "Regular", 12 ],
|
||
|
|
[ "Lucida Sans Typewriter", "Regular", 14 ],
|
||
|
|
[ "Courier", "Regular", 16 ],
|
||
|
|
[ "Courier New", "Regular", 14 ]
|
||
|
|
]
|
||
|
|
);
|
||
|
|
defaultOutputFile = new File (customOptions.defaultOutputFile);
|
||
|
|
var dialog = new Window ('dialog', "Get Patterns File Info", undefined, { resizeable: true });
|
||
|
|
dialog.preferredSize.width = customOptions.dialogWidth;;
|
||
|
|
dialog.preferredSize.height = customOptions.dialogHeight;;
|
||
|
|
dialog.onResizing = function ()
|
||
|
|
{
|
||
|
|
this.layout.resize ();
|
||
|
|
};
|
||
|
|
dialog.onShow = function ()
|
||
|
|
{
|
||
|
|
var x = customOptions.dialogX;
|
||
|
|
var y = customOptions.dialogY;
|
||
|
|
if ((x !== 0) || (y !== 0))
|
||
|
|
{
|
||
|
|
this.location.x = x;
|
||
|
|
this.location.y = y;
|
||
|
|
}
|
||
|
|
infoArea.text = jamJSON.stringify (info, '\t');
|
||
|
|
};
|
||
|
|
var infoGroup = dialog.add ('group');
|
||
|
|
infoGroup.orientation = "column";
|
||
|
|
infoGroup.alignment = [ "fill", "fill" ];
|
||
|
|
var infoArea = infoGroup.add ('edittext', undefined, "", { multiline: true, readonly: true });
|
||
|
|
infoArea.alignment = [ "fill", "fill" ];
|
||
|
|
infoArea.minimumSize = [ -1, 64 ];
|
||
|
|
if (monospacedFont)
|
||
|
|
{
|
||
|
|
infoArea.graphics.font = monospacedFont;
|
||
|
|
}
|
||
|
|
var actionButtonsGroup = infoGroup.add ('group');
|
||
|
|
actionButtonsGroup.alignment = [ "center", "bottom" ];
|
||
|
|
actionButtonsGroup.orientation = "row";
|
||
|
|
actionButtonsGroup.alignChildren = "fill";
|
||
|
|
var outFile;
|
||
|
|
var saveButton = actionButtonsGroup.add ('button', undefined, 'Save...');
|
||
|
|
saveButton.onClick = function ()
|
||
|
|
{
|
||
|
|
outFile = defaultOutputFile.saveDlg ("Save to JSON text file:");
|
||
|
|
if (outFile)
|
||
|
|
{
|
||
|
|
jamUtils.writeTextFile (outFile, infoArea.text);
|
||
|
|
defaultOutputFile = outFile;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
var buttonsGroup = dialog.add ('group');
|
||
|
|
buttonsGroup.alignment = [ "right", "bottom" ];
|
||
|
|
buttonsGroup.orientation = "row";
|
||
|
|
buttonsGroup.alignChildren = "fill";
|
||
|
|
var cancelButton = buttonsGroup.add ('button', undefined, 'Cancel', { name: "cancel" });
|
||
|
|
cancelButton.onClick = function ()
|
||
|
|
{
|
||
|
|
dialog.close (false);
|
||
|
|
};
|
||
|
|
var okButton = buttonsGroup.add ('button', undefined, 'OK', { name: "ok" });
|
||
|
|
okButton.onClick = function ()
|
||
|
|
{
|
||
|
|
customOptions.defaultOutputFile = defaultOutputFile.fsName;
|
||
|
|
customOptions.dialogWidth = dialog.size.width;
|
||
|
|
customOptions.dialogHeight = dialog.size.height;
|
||
|
|
customOptions.dialogX = dialog.location.x;
|
||
|
|
customOptions.dialogY = dialog.location.y;
|
||
|
|
dialog.close (true);
|
||
|
|
};
|
||
|
|
return dialog.show ();
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
function main ()
|
||
|
|
{
|
||
|
|
var appVersion = parseInt (app.version);
|
||
|
|
if (appVersion >= 10) // CS3
|
||
|
|
{
|
||
|
|
customOptions = jamUtils.getCustomOptions (signature, defaultOptions);
|
||
|
|
var info = getPatternsFileInfo ();
|
||
|
|
if (info)
|
||
|
|
{
|
||
|
|
if (displayDialog (info))
|
||
|
|
{
|
||
|
|
jamUtils.putCustomOptions (signature, customOptions, true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
alert ("Sorry, this script requires Photoshop CS3 or later.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
main ();
|
||
|
|
}
|
||
|
|
catch (e)
|
||
|
|
{
|
||
|
|
alert (e);
|
||
|
|
}
|
||
|
|
|
||
|
|
//------------------------------------------------------------------------------
|
||
|
|
|