Photoshop: Scripting: Extract kerning preceding first character

  • 1
  • Problem
  • Updated 1 year ago
  • (Edited)

this is a copy of my post from, one of the users told me there that it looks like a bug.

I need to extract a value of kerning, that precedes the first character in a text. Here is my script:
var psdFilePath = "C:/adobe/test.psd";  
var psdFile = File(psdFilePath);  
var document = open(psdFile);  
var layers = document.layers;  
var result = null;  
for (var i = 0; i < layers.length; ++i){  
    var layer = layers[i];  
    if (layer.kind == LayerKind.TEXT){  
        document.activeLayer = layer;  
        result = getKerningInfo().toSource();  
function getKerningInfo(){  
    var kerningInfo = new Array;  
    var layerReference = new ActionReference();  
    layerReference.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );  
    var layerDescriptor = executeActionGet(layerReference);  
    var textDescriptor = layerDescriptor.getObjectValue(stringIDToTypeID("textKey"));  
    var kerningRanges = textDescriptor.getList(stringIDToTypeID("kerningRange"));  
    for(var i = 0; i < kerningRanges.count; i++){  
        var kerningRange = kerningRanges.getObjectValue(i);  
        var from = kerningRange.getInteger(stringIDToTypeID("from"));  
        var to = kerningRange.getInteger(stringIDToTypeID("to"));  
        var kerning = kerningRange.getInteger(stringIDToTypeID("kerning"));  
        var kerningItem = {'from': from, 'to': to, 'kerning': kerning};  
    return kerningInfo;  

As a result, I get a list containing a single item:
{'from': 0, 'to': 1, 'kerning': -200}  
However, in the file, I have set the value of "kerning between two characters" to:

  • -1000 before the first character
  • -200 before the second character
Here is a screenshot showing it:

Is there something wrong with my code or is it a bug in Photoshop JavaScript API?
Photo of Wojtek Jeczalik

Wojtek Jeczalik

  • 1 Post
  • 0 Reply Likes

Posted 1 year ago

  • 1

Be the first to post a reply!