var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
app.activeDocument.suspendHistory("Resize Text", "fn()")
app.preferences.rulerUnits = old_units;
function fn()
{
var w0 = activeDocument.activeLayer.bounds[2].value - activeDocument.activeLayer.bounds[0].value;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("textKey"));
r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
try {
var xx = 1;
try { xx = executeActionGet(r).getObjectValue(stringIDToTypeID("textKey")).getObjectValue(stringIDToTypeID("transform")).getDouble(stringIDToTypeID("xx")); } catch(e) {}
var b = executeActionGet(r).getObjectValue(stringIDToTypeID("textKey")).getList(stringIDToTypeID("textShape")).getObjectValue(0).getObjectValue(stringIDToTypeID("bounds"))
var w = b.getDouble(stringIDToTypeID("right")) - b.getDouble(stringIDToTypeID("left"));
var w1 = w*xx;
}
catch(e) { alert("not a paragraph text"); return false; }
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("char"));
r.putEnumerated(stringIDToTypeID("textLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putEnumerated(stringIDToTypeID("to"), stringIDToTypeID("char"), stringIDToTypeID("point"));
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
//activeDocument.activeLayer.textItem.size *= (w1/w0);
transform(w1/w0*100, activeDocument.activeLayer.bounds[0].value, activeDocument.activeLayer.bounds[3].value);
return true;
}
function transform(pcn, x, y)
{
try
{
var d1 = new ActionDescriptor();
var r1 = new ActionReference();
r1.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
d1.putReference( charIDToTypeID( "null" ), r1 );
d1.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ), charIDToTypeID( "Qcsi" ) );
var d2 = new ActionDescriptor();
d2.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Pnt" ), x );
d2.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Pnt" ), y );
d1.putObject( charIDToTypeID( "Pstn" ), charIDToTypeID( "Pnt " ), d2 );
d1.putUnitDouble( charIDToTypeID( "Wdth" ), charIDToTypeID( "#Prc" ), pcn );
d1.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Prc" ), pcn );
executeAction( charIDToTypeID( "Trnf" ), d1, DialogModes.NO );
}
catch (e) { alert(e); }
}