Class Index | File Index

Classes


Namespace jamUtils


Version 4.5.

Defined in: jamUtils.jsxinc.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global object (used to simulate a namespace in JavaScript) containing a set of utility functions for scripts written with the JSON Action Manager engine.
Method Summary
Method Attributes Method Name and Description
<static>  
jamUtils.cloneData(data)
Get a clone (deep copy) of a Javascript data structure.
<static>  
jamUtils.dataToHexaString(dataString, lowercase)
Convert a raw byte data string into a hexadecimal string.
<static>  
jamUtils.eraseCustomOptions(signature)
Erase custom options associated with a unique signature [available in CS3 or later].
<static>  
jamUtils.fontExists(fontPostScriptName)
Test if a required font is available.
<static>  
jamUtils.fromDistanceUnit(amount, amountBasePerInch)
Convert a distance from "distanceUnit" units to pixels.
<static>  
jamUtils.getCustomOptions(signature, defaultOptions)
Retrieve custom options associated with a unique signature [available in CS3 or later].
<static>  
jamUtils.hexaToDataString(hexaString)
Convert a hexadecimal string into a raw byte data string.
<static>  
jamUtils.loadAction(action, actionSet, actionsFilePath)
Load an action if not currently available.
<static>  
jamUtils.loadActionSet(actionSet, actionsFilePath)
Load an action set if not currently available.
<static>  
jamUtils.loadPreset(presetProperty, presetName, presetFilePath)
Load a preset if not currently available.
<static>  
jamUtils.mergeData(data, defaultData)
Merge two Javascript literal object data structures, using the second one as default base.
<static>  
jamUtils.putCustomOptions(signature, customOptions, persistent)
Save custom options associated with a unique signature [available in CS3 or later].
<static>  
jamUtils.readJsonFile(jsonFile)
Convert a JSON text file into a JavaScript data structure.
<static>  
jamUtils.readTextFile(textFile)
Read a text file in UTF-8 encoding.
<static>  
jamUtils.toDistanceUnit(amount, amountBasePerInch)
Convert a distance in pixels to "distanceUnit" units.
<static>  
jamUtils.writeJsonFile(jsonFile, data, space)
Convert a JavaScript data structure into a JSON text file.
<static>  
jamUtils.writeTextFile(textFile, text)
Write a text file in UTF-8 encoding.
Namespace Detail
jamUtils
Global object (used to simulate a namespace in JavaScript) containing a set of utility functions for scripts written with the JSON Action Manager engine.
Author: Michel MARIANI.
Method Detail
<static> {Object|Array|String|Number|Boolean|Null} jamUtils.cloneData(data)
Get a clone (deep copy) of a Javascript data structure.
var customOptions;
var defaultOptions =
{
    dialog:
    {
        x: 0,
        y: 0,
        width: 1024,
        height: 768
    }
};
//
customOptions = jamUtils.cloneData (defaultOptions);
customOptions.dialog.width = 512;
alert (defaultOptions.dialog.width);   // -> 1024
//
customOptions = defaultOptions;
customOptions.dialog.width = 512;
alert (defaultOptions.dialog.width);   // -> 512
Parameters:
{Object|Array|String|Number|Boolean|Null} data
Javascript data structure
Returns:
{Object|Array|String|Number|Boolean|Null} Clone (deep copy) of a Javascript data structure

<static> {String} jamUtils.dataToHexaString(dataString, lowercase)
Convert a raw byte data string into a hexadecimal string.
var hexaString = jamUtils.dataToHexaString ("«Íï"); // -> "ABCDEF"
Parameters:
{String} dataString
Raw byte data string
{Boolean} lowercase Optional
Use lowercase hexadecimal digits (false by default)
Returns:
{String} Hexadecimal string
See:
jamUtils.hexaToDataString

<static> jamUtils.eraseCustomOptions(signature)
Erase custom options associated with a unique signature [available in CS3 or later].
var signature = "unique-signature-custom-options";
jamUtils.eraseCustomOptions (signature);
Parameters:
{String} signature
Unique signature string
See:
jamUtils.getCustomOptions
jamUtils.putCustomOptions

<static> {Boolean} jamUtils.fontExists(fontPostScriptName)
Test if a required font is available.
if (jamUtils.fontExists ("Apple-Chancery"))
{
    // Use the fancy Apple Chancery font...
}
Parameters:
{String} fontPostScriptName
Font PostScript name string
Returns:
{Boolean} Font found boolean

<static> {Number} jamUtils.fromDistanceUnit(amount, amountBasePerInch)
Convert a distance from "distanceUnit" units to pixels.
jamEngine.meaningfulIds = true;
var resultDescObj = jamEngine.jsonGet ([ { "document": { "<enumerated>": { "ordinal": "first" } } } ]);
var width = resultDescObj["width"]["<unitDouble>"]["distanceUnit"];
var height = resultDescObj["height"]["<unitDouble>"]["distanceUnit"];
var resolution = resultDescObj["resolution"]["<unitDouble>"]["densityUnit"];
var pixelsWidth = jamUtils.fromDistanceUnit (width, resolution);
var pixelsHeight = jamUtils.fromDistanceUnit (height, resolution);
Parameters:
{Number} amount
Distance in "distanceUnit" units (special pixels units at an absolute 72 dpi)
{Number} amountBasePerInch
Resolution of document in pixels per inch
Returns:
{Number} Distance in pixels
See:
jamUtils.toDistanceUnit

<static> {Object} jamUtils.getCustomOptions(signature, defaultOptions)
Retrieve custom options associated with a unique signature [available in CS3 or later].
var signature = "unique-signature-custom-options";
jamUtils.eraseCustomOptions (signature);
var customOptions = { name: "Rectangle" };
jamUtils.putCustomOptions (signature, customOptions, true);
var defaultOptions = { width: 1024, height: 768, name: "Untitled" };
customOptions = jamUtils.getCustomOptions (signature, defaultOptions);
if (customOptions.name !== "Untitled")
{
    alert (jamJSON.stringify (customOptions.name + "-" + customOptions.width + "x" + customOptions.height));
    // -> "Rectangle-1024x768"
}
Parameters:
{String} signature
Unique signature string
{Object} defaultOptions
Default options as a JavaScript literal object
Returns:
{Object} Custom options as a JavaScript literal object
See:
jamUtils.eraseCustomOptions
jamUtils.putCustomOptions

<static> {String} jamUtils.hexaToDataString(hexaString)
Convert a hexadecimal string into a raw byte data string.
var dataString = jamUtils.hexaToDataString ("00011E1F20217E7F80819E9FA0A1FEFF");
// -> "\u0000\u0001\u001E\u001F !~\u007F\u0080\u0081\u009E\u009F ¡þÿ"
Parameters:
{String} hexaString
Hexadecimal string
Returns:
{String} Raw byte data string
See:
jamUtils.dataToHexaString

<static> jamUtils.loadAction(action, actionSet, actionsFilePath)
Load an action if not currently available.
Folder.current = new Folder ("~/JSON Action Manager/tests/resources/");
jamUtils.loadAction ("Cross Process 2", "Cross Processing", "Cross Processing.atn");
Parameters:
{String} action
Action name string
{String} actionSet
Action set name string
{String} actionsFilePath
Actions file path string

<static> jamUtils.loadActionSet(actionSet, actionsFilePath)
Load an action set if not currently available.
Folder.current = new Folder ("~/JSON Action Manager/tests/resources/");
jamUtils.loadActionSet ("Cross Processing", "Cross Processing.atn");
Parameters:
{String} actionSet
Action set name string
{String} actionsFilePath
Actions file path string

<static> jamUtils.loadPreset(presetProperty, presetName, presetFilePath)
Load a preset if not currently available.
Folder.current = new Folder ("~/JSON Action Manager/tests/resources/");
jamUtils.loadPreset ("style", "Logo X-Aqua in Blue Glass (Button)", "Logo-X-Aqua.asl");
jamUtils.loadPreset ("toolPreset", "Brush Tool Soft Round 35 Red", "Brush-35-Red.tpl");
Parameters:
{String} presetProperty
Preset property string:
  • "brush"
  • "colors"
  • "gradientClassEvent"
  • "style"
  • "pattern"
  • "shapingCurve"
  • "customShape"
  • "toolPreset"
{String} presetName
Preset name string
{String} presetFilePath
Preset file path string

<static> {Object} jamUtils.mergeData(data, defaultData)
Merge two Javascript literal object data structures, using the second one as default base.
var customOptions =
{
    name: "foobar",
    active: true,
    dialog:
    {
        width: 512
    }
};
var defaultOptions =
{
    name: "untitled",
    enabled: false,
    active: false,
    dialog:
    {
        x: 0,
        y: 0,
        width: 1024,
        height: 768
    }
};
//
customOptions = jamUtils.mergeData (customOptions, defaultOptions);
alert (jamJSON.stringify (customOptions, '\t'));
// ->
// {
//     "name": "foobar",
//     "active": true,
//     "dialog":
//     {
//         "width": 512,
//         "x": 0,
//         "y": 0,
//         "height": 768
//     },
//     "enabled": false
// }
Parameters:
{Object} data
Javascript literal object data structure
{Object} defaultData
Javascript literal object data structure
Returns:
{Object} Merged Javascript literal object data structure

<static> jamUtils.putCustomOptions(signature, customOptions, persistent)
Save custom options associated with a unique signature [available in CS3 or later].
var signature = "unique-signature-custom-options";
var customOptions = { width: 512, height: 512, name: "Square" };
jamUtils.putCustomOptions (signature, customOptions, true);
Parameters:
{String} signature
Unique signature string
{Object} customOptions
Custom options as a JavaScript literal object
{Boolean} persistent Optional
Whether the options should persist once the script has finished
See:
jamUtils.eraseCustomOptions
jamUtils.getCustomOptions

<static> {Object|Array|String|Number|Boolean|Null} jamUtils.readJsonFile(jsonFile)
Convert a JSON text file into a JavaScript data structure.
var data = jamUtils.readJsonFile ("~/Desktop/test-data.json");
alert ("color: " + jamJSON.stringify (data["color"]));   // -> color: [ "RGBColor", [ 255, 0, 255 ] ]
Parameters:
{Object|String} jsonFile
JSON text file File object (or path string)
Returns:
{Object|Array|String|Number|Boolean|Null} JavaScript data structure (usually an object or array)
See:
jamUtils.writeJsonFile

<static> {String|Null} jamUtils.readTextFile(textFile)
Read a text file in UTF-8 encoding.
var text = jamUtils.readTextFile ("~/Desktop/test.txt");
Parameters:
{Object|String} textFile
Text file File object (or path string)
Returns:
{String|Null} Text string, or null if error
See:
jamUtils.writeTextFile

<static> {Number} jamUtils.toDistanceUnit(amount, amountBasePerInch)
Convert a distance in pixels to "distanceUnit" units.
jamEngine.jsonPlay
(
    "make",
    {
        "new":
        {
            "<object>":
            {
                "document":
                {
                    "name": { "<string>": "Polaroid 4x5 Inch (Print)" },
                    "mode": { "<class>": "RGBColorMode" },
                    "width":
                    {
                        "<unitDouble>":
                        {
                            "distanceUnit": jamUtils.toDistanceUnit (4 * 300, 300)
                        }
                    },
                    "height":
                    {
                        "<unitDouble>":
                        {
                            "distanceUnit": jamUtils.toDistanceUnit (5 * 300, 300)
                        }
                    },
                    "resolution": { "<unitDouble>": { "densityUnit": 300 } },
                    "depth": { "<integer>": 16 },
                    "fill": { "<enumerated>": { "fill": "white" } },
                    "profile": { "<string>": "Adobe RGB (1998)" }
                }
            }
        }
    }
);
Parameters:
{Number} amount
Distance in pixels
{Number} amountBasePerInch
Resolution of document in pixels per inch
Returns:
{Number} Distance in "distanceUnit" units (special pixels units at an absolute 72 dpi)
See:
jamUtils.fromDistanceUnit

<static> jamUtils.writeJsonFile(jsonFile, data, space)
Convert a JavaScript data structure into a JSON text file.
var magenta = [ "RGBColor", [ 255, 0, 255 ] ];
var data =
{
    "width": 640,
    "height": 480,
    "color": magenta,
    "title": "紅紫色" + "/" + "マゼンタ"
};
jamUtils.writeJsonFile ("~/Desktop/test-data.json", data);
Parameters:
{Object|String} jsonFile
JSON text file File object (or path string)
{Object|Array|String|Number|Boolean|Null} data
JavaScript data structure (usually an object or array)
{String|Number} space Optional
Indent space string (e.g. "\t") or number of spaces
See:
jamUtils.readJsonFile

<static> jamUtils.writeTextFile(textFile, text)
Write a text file in UTF-8 encoding.
jamUtils.writeTextFile ("~/Desktop/test.txt", "test");
Parameters:
{Object|String} textFile
Text file File object (or path string)
{String} text
Text string
See:
jamUtils.readTextFile

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 12 2016 23:32:44 GMT+0200 (CEST)