Class Index | File Index

Classes


Namespace jamShapes


Version 4.5.

Defined in: jamShapes.jsxinc.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Global object (used to simulate a namespace in JavaScript) containing a set of functions related to decoding custom shapes files into a format usable by scripts written with the JSON Action Manager engine.
Field Summary
Field Attributes Field Name and Description
<static>  
jamShapes.debugMode
Global option: if true, jamShapes.pathComponentsFromCustomShape () returns the path components of the shape's bounding box instead of the shape itself.
Method Summary
Method Attributes Method Name and Description
<static>  
jamShapes.dataFromCustomShapesFile(shapesFile, shapeIndex)
Convert a custom shapes file (*.csh or CustomShapes.psp) into a data structure in JSON format.
<static>  
jamShapes.isCustomShapesFile(file)
Test if a given file is a custom shapes file (*.csh).
<static>  
jamShapes.isCustomShapesPrefsFile(file)
Test if a given file is a custom shapes preferences file (CustomShapes.psp).
<static>  
jamShapes.pathComponentsFromCustomShape(customShape, shapeOperation, bounds, constrainProportions)
Get a JSON array of data (simplified path component values) and unit ID string for coordinates from a custom shape data structure obtained from a converted custom shapes file (*.csh).
Namespace Detail
jamShapes
Global object (used to simulate a namespace in JavaScript) containing a set of functions related to decoding custom shapes files into a format usable by scripts written with the JSON Action Manager engine.
Uses information found in the document Photoshop Custom Shapes File Format.
Author: Michel MARIANI.
Field Detail
<static> {Boolean} jamShapes.debugMode
Global option: if true, jamShapes.pathComponentsFromCustomShape () returns the path components of the shape's bounding box instead of the shape itself.
var fileData = jamShapes.dataFromCustomShapesFile ("~/JSON Action Manager/tests/resources/Logo-X-Aqua.csh");
if (typeof fileData === 'string')
{
    alert (fileData);
}
else
{
    var customShape = fileData["customShapes"][0];
    var bounds = [ [ 10, 10, 90, 90 ], "percentUnit" ];
    jamShapes.debugMode = true;
    pathComponents = jamShapes.pathComponentsFromCustomShape (customShape, "add", bounds, true);
    jamEngine.jsonPlay
    (
        "set",
        {
            "target": { "<reference>": [ { "path": { "<property>": "workPath" } } ] },
            "to": jamHelpers.toPathComponentList (pathComponents)
        }
    );
    jamEngine.jsonPlay
    (
        "fill",
        {
            "target": { "<reference>": [ { "path": { "<property>": "workPath" } } ] },
            "wholePath": { "<boolean>": true },
            "using": { "<enumerated>": { "fillContents": "color" } },
            "color": jamHelpers.nameToColorObject ("W3C", "Red"),
            "opacity": { "<unitDouble>": { "percentUnit": 50 } },
            "mode": { "<enumerated>": { "blendMode": "normal" } },
            "radius": { "<unitDouble>": { "pixelsUnit": 0.0 } },
            "antiAlias": { "<boolean>": true }
        }
    );
}
See:
jamShapes.pathComponentsFromCustomShape
Default Value:
false
Method Detail
<static> {Object|String} jamShapes.dataFromCustomShapesFile(shapesFile, shapeIndex)
Convert a custom shapes file (*.csh or CustomShapes.psp) into a data structure in JSON format.
function customShapesFileFilter (f)
{
    return (f instanceof Folder) || jamShapes.isCustomShapesFile (f);
}
var select = (File.fs === "Macintosh") ? customShapesFileFilter : "Custom Shapes Files:*.csh,All Files:*";
var customShapesFile = File.openDialog ("Select a custom shapes file:", select);
if (customShapesFile !== null)
{
    var fileData = jamShapes.dataFromCustomShapesFile (customShapesFile, -1);
    if (typeof fileData === 'string')
    {
        alert (fileData + "\n" + "Custom shapes file: “" + File.decode (customShapesFile.name) + "”");
    }
    else
    {
        alert ("Number of custom shapes: " + fileData["customShapes"].length);
    }
}
Parameters:
{String|Object} shapesFile
Custom shapes file path string or File object
{Number} shapeIndex Optional
If defined, the returned information for each custom shape is limited to its name and ID (no bounds, no path records) except for the shape located at this index; passing -1 will limit the information for all custom shapes
Returns:
{Object|String} Converted custom shapes file data structure in JSON format, or error message string

The custom shapes file data structure is defined as a JSON object { } with two members:
{ "fileVersion": fileVersion, "customShapes": customShapes }

fileVersion: number
customShapes: JSON array [ ] of customShape

customShape: JSON object { } with four members:
{ "name": name, "ID": ID, "bounds": bounds, "pathRecords": pathRecords }

name: string
ID: string
bounds: JSON array [ ] with four items: [ top, left, bottom, right ]

top: number
left: number
bottom: number
right: number

pathRecords: JSON array [ ] of pathRecord

pathRecord: JSON array [ ] with two items: [ selector, data }

selector data
"pathFill" null
"initialFill" number (0 or 1)
"closedLength" number
"closedLinked" JSON array [ ] with three items: [ backward, anchor, forward ]
"closedUnlinked" JSON array [ ] with three items: [ backward, anchor, forward ]
"openLength" number
"openLinked" JSON array [ ] with three items: [ backward, anchor, forward ]
"openUnlinked" JSON array [ ] with three items: [ backward, anchor, forward ]

backward: JSON array [ ] with two items: [ vertical, horizontal ]
anchor: JSON array [ ] with two items: [ vertical, horizontal ]
forward: JSON array [ ] with two items: [ vertical, horizontal ]

vertical: number
horizontal: number


<static> {Boolean} jamShapes.isCustomShapesFile(file)
Test if a given file is a custom shapes file (*.csh).
function customShapesFileFilter (f)
{
    return (f instanceof Folder) || jamShapes.isCustomShapesFile (f);
}
var select = (File.fs === "Macintosh") ? customShapesFileFilter : "Custom Shapes Files:*.csh,All Files:*";
var customShapesFile = File.openDialog ("Select a custom shapes file:", select);
if (customShapesFile !== null)
{
    alert ("OK!");
}
Parameters:
{Object} file
File object
Returns:
{Boolean} true if custom shapes file

<static> {Boolean} jamShapes.isCustomShapesPrefsFile(file)
Test if a given file is a custom shapes preferences file (CustomShapes.psp).
function customShapesPrefsFileFilter (f)
{
    return (f instanceof Folder) || jamShapes.isCustomShapesPrefsFile (f);
}
var select = (File.fs === "Macintosh") ?
                 customShapesPrefsFileFilter :
                 "Custom Shapes Preferences File:CustomShapes.psp,All Files:*.*";
var customShapesPrefsFile = File.openDialog ("Select a custom shapes preferences file:", select);
if (customShapesPrefsFile !== null)
{
    alert ("OK!");
}
Parameters:
{Object} file
File object
Returns:
{Boolean} true if custom shapes preferences file

<static> {Array} jamShapes.pathComponentsFromCustomShape(customShape, shapeOperation, bounds, constrainProportions)
Get a JSON array of data (simplified path component values) and unit ID string for coordinates from a custom shape data structure obtained from a converted custom shapes file (*.csh).
var fileData = jamShapes.dataFromCustomShapesFile ("~/JSON Action Manager/tests/resources/Logo-X-Aqua.csh");
if (typeof fileData === 'string')
{
    alert (fileData);
}
else
{
    var customShape = fileData["customShapes"][0];
    var bounds = [ [ 10, 10, 90, 90 ], "percentUnit" ];
    var pathComponents = jamShapes.pathComponentsFromCustomShape (customShape, "add", bounds, true);
    jamEngine.jsonPlay
    (
        "set",
        {
            "target": { "<reference>": [ { "path": { "<property>": "workPath" } } ] },
            "to": jamHelpers.toPathComponentList (pathComponents)
        }
    );
}
Parameters:
{Object} customShape
Custom shape data structure in JSON format, obtained from a converted custom shapes file (*.csh)
{String} shapeOperation
Shape operation:
  • "add"
  • "subtract"
  • "intersect"
  • "xor"
{Array} bounds
Path bounds rectangle with optional unit (either "distanceUnit" or "percentUnit" or "pixelsUnit"):
[ [ left, top, right, bottom ], unit ]
{Boolean} constrainProportions Optional
Constrain proportions using the custom shape aspect ratio (false by default)
Returns:
{Array} JSON array of data (simplified path component values) and unit ID string for coordinates (cf. Path Component List Simplified Format); if jamShapes.debugMode is true, returns the path components of the shape's bounding box instead of the shape itself
See:
jamShapes.dataFromCustomShapesFile
jamShapes.debugMode

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