Copy link to clipboard
Copied
Let's say I create a text layer with 50pt font size, then I transform the layer to make it bigger. Is there a variable that saves the scale factor?
Thanks in advance.
Copy link to clipboard
Copied
I just tested in Photoshop CC and there the result of scaling a Type Layer seems to be a Type Layer with the correspondingly larger/smaller type size. (edited)
Copy link to clipboard
Copied
Thanks! That's right, and I'd like to know if there's a scale value inside the layer, accessible through scripting.
I'll explain the problem a bit: in CC, when you do what I explain in the opening post, you can see in the interface a bigger value for the text size, but when you get "layer.textItem.size" through scripting, the size is the original one, not the one you see in the interface (the bigger). That didn't happen in CS5.
So I was thinking if it might be possible to calculate the new text size of the layer with that original text size * the layer scale factor (in case there's a variable that has that value).
Copy link to clipboard
Copied
Does this help?
// get keys for type layer stuff;
// based on code by michael l hale;
// 2014, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
if (app.activeDocument.activeLayer.kind == LayerKind.TEXT) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
checkDesc2 (textDesc.getObjectValue(stringIDToTypeID("transform")));
}
};
//////
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
edited
Copy link to clipboard
Copied
Please note I edited the code, I had omitted a line.
Copy link to clipboard
Copied
There seems to be a problem with
textDesc.getObjectValue(stringIDToTypeID("transform"))
Copy link to clipboard
Copied
Has the Layer been transformed at all?
Otherwise there would be no need for the key, I guess; either using hasKey() or wrapping it in a try-clause should work.
Copy link to clipboard
Copied
Understood I'll just put it in a try
Copy link to clipboard
Copied
I should have thought of that …
Copy link to clipboard
Copied
Note that CC2014 works differently from CC2012 and I've not found a reliable way for CS6. This is the code I have for getting the paragraph text box extents.
getTextExtentsCC2014: function (text_item) { |
app.activeDocument.activeLayer = text_item.parent
var ref = new ActionReference()
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )
var action = executeActionGet(ref)
var textKey = action.getObjectValue(stringIDToTypeID('textKey'))
var bounds = textKey.getObjectValue(stringIDToTypeID('bounds'))
var width = bounds.getUnitDoubleValue (stringIDToTypeID('right'))
var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom'))
var x_scale = 1
var y_scale = 1
if (textKey.hasKey(stringIDToTypeID('transform'))) {
var transform = textKey.getObjectValue(stringIDToTypeID('transform'))
x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))
y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))
}
x_scale *= width / text_item.width
y_scale *= height / text_item.height
return {
x:Math.round(text_item.position[0]),
y:Math.round(text_item.position[1]),
width:Math.round(width*x_scale),
height:Math.round(height*y_scale) }
}, | |
getTextExtentsCC2012: function (text_item) { |
app.activeDocument.activeLayer = text_item.parent
var ref = new ActionReference()
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") )
var action = executeActionGet(ref)
var textKey = action.getObjectValue(stringIDToTypeID('textKey'))
var bounds = textKey.getObjectValue(stringIDToTypeID('bounds'))
var width = bounds.getUnitDoubleValue (stringIDToTypeID('right'))
var height = bounds.getUnitDoubleValue (stringIDToTypeID('bottom'))
var x_scale = 1
var y_scale = 1
if (textKey.hasKey(stringIDToTypeID('transform'))) {
var transform = textKey.getObjectValue(stringIDToTypeID('transform'))
x_scale = transform.getUnitDoubleValue (stringIDToTypeID('xx'))
y_scale = transform.getUnitDoubleValue (stringIDToTypeID('yy'))
}
return {
x:Math.round(text_item.position[0]),
y:Math.round(text_item.position[1]),
width:Math.round(width*x_scale),
height:Math.round(height*y_scale)
}
}, |
Copy link to clipboard
Copied
Thanks for the replies. I'll give it a go during the week