When setting an array of kerningRange in batchPlay, only the last one is applied.
For example, this is an array that puts kerning on insertion points between 0 and 1 and insertion points between 1 and 2. If it is set, only insertion points between 1 and 2 will be applied.
[
{
"_obj": "kerningRange",
"from": 0,
"kerning": 500,
"to": 1
},
{
"_obj": "kerningRange",
"from": 1,
"kerning": 500,
"to": 2
}
]
Ideally, it should succeed without any special tricks.
Environment
- macOS 11.6.5
- Photoshop 2022 (v23.3.2)
Expected result
Kerning 500 will be applied to both insertion points between 0 and 1 and insertion points between 1 and 2.
Actual result
Only insertion points between 1 and 2 have kerning 500.
Workaround
Sort the kerningRange starting with the end and then set it.
Code
/**
* set kerningRange via batchPlay
* @param {layer} aLayer target text layer
* @return {}
*/
const setKerningRange = async (aLayer) => {
const layerID = aLayer._id ;
const dstKerningRange = [
{
"_obj": "kerningRange",
"from": 0,
"kerning": 500,
"to": 1
},
{
"_obj": "kerningRange",
"from": 1,
"kerning": 500,
"to": 2
}
] ;
await batchPlay([
// select layer specified by id
{
"_obj": "select",
"_target": [
{
"_ref": "layer",
"_id": layerID
}
],
"layerID": [layerID],
"makeVisible": false,
"selectionModifier": {
"_enum": "selectionModifierType",
"_value": "addToSelectionContinuous"
}
},
// set kerningRange to selected layer
{
"_obj": "set",
"_target": [
{
"_enum": "ordinal",
"_ref": "textLayer"
},
],
"to": {
"_obj": "textLayer",
"kerningRange": dstKerningRange // wrong result
//"kerningRange": dstKerningRange.sort((a, b) => {return b.from - a.from}) // right result
}
}
],
{},
) ;
} ;