Text can now be formatted

- Added black to the colors
- Fixed setStroke to be skipped when needed
This commit is contained in:
Unknown
2018-04-12 13:07:56 -04:00
parent 4bf7eca6b0
commit e90c491450
6 changed files with 156 additions and 10 deletions

View File

@@ -7,7 +7,7 @@ else
path = wScript.Arguments(0)
args = wScript.Arguments(1)
error = appRef.DoJavaScriptFile(path, Split(args, ","))
if Not error = "true" Then
if Not error = "true" and Not error = "[ActionDescriptor]" and Not error = "undefined" Then
Err.raise 1, "dojs.vbs", error
end if
end if

54
scripts/fmtText.jsx Normal file
View File

@@ -0,0 +1,54 @@
var start = parseInt(arguments[1]);
var end = parseInt(arguments[2]);
var fontName = arguments[3];
var fontStyle = arguments[4];
var colorArray = [0, 0, 0];
if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){
var activeLayer = app.activeDocument.activeLayer;
var fontSize = activeLayer.textItem.size;
if(activeLayer.kind == LayerKind.TEXT){
if((activeLayer.textItem.contents != "")&&(start >= 0)&&(end <= activeLayer.textItem.contents.length)){
var idsetd = app.charIDToTypeID( "setd" );
var action = new ActionDescriptor();
var idnull = app.charIDToTypeID( "null" );
var reference = new ActionReference();
var idTxLr = app.charIDToTypeID( "TxLr" );
var idOrdn = app.charIDToTypeID( "Ordn" );
var idTrgt = app.charIDToTypeID( "Trgt" );
reference.putEnumerated( idTxLr, idOrdn, idTrgt );
action.putReference( idnull, reference );
var idT = app.charIDToTypeID( "T " );
var textAction = new ActionDescriptor();
var idTxtt = app.charIDToTypeID( "Txtt" );
var actionList = new ActionList();
var textRange = new ActionDescriptor();
var idFrom = app.charIDToTypeID( "From" );
textRange.putInteger( idFrom, start );
textRange.putInteger( idT, end );
var idTxtS = app.charIDToTypeID( "TxtS" );
var formatting = new ActionDescriptor();
var idFntN = app.charIDToTypeID( "FntN" );
formatting.putString( idFntN, fontName );
var idFntS = app.charIDToTypeID( "FntS" );
formatting.putString( idFntS, fontStyle );
var idSz = app.charIDToTypeID( "Sz " );
var idPnt = app.charIDToTypeID( "#Pnt" );
formatting.putUnitDouble( idSz, idPnt, fontSize );
var idClr = app.charIDToTypeID( "Clr " );
var colorAction = new ActionDescriptor();
var idRd = app.charIDToTypeID( "Rd " );
colorAction.putDouble( idRd, colorArray[0] );
var idGrn = app.charIDToTypeID( "Grn " );
colorAction.putDouble( idGrn, colorArray[1]);
var idBl = app.charIDToTypeID( "Bl " );
colorAction.putDouble( idBl, colorArray[2] );
var idRGBC = app.charIDToTypeID( "RGBC" );
formatting.putObject( idClr, idRGBC, colorAction );
textRange.putObject( idTxtS, idTxtS, formatting );
actionList.putObject( idTxtt, textRange );
textAction.putList( idTxtt, actionList );
action.putObject( idT, idTxLr, textAction );
app.executeAction( idsetd, action, DialogModes.NO );
}
}
}

View File

@@ -17,4 +17,68 @@ function bounds(lyr) {
return ('"Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']]').replace(/ px/g, "");
}
/**
* The setFormatting function sets the font, font style, point size, and RGB color of specified
* characters in a Photoshop text layer.
*
* @param start (int) the index of the insertion point *before* the character you want.,
* @param end (int) the index of the insertion point following the character.
* @param fontName is a string for the font name.
* @param fontStyle is a string for the font style.
* @param fontSize (Number) the point size of the text.
* @param colorArray (Array) is the RGB color to be applied to the text.
*/
function setFormatting(start, end, fontName, fontStyle, fontSize, colorArray) {
if(app.activeDocument.activeLayer.kind == LayerKind.TEXT){
var activeLayer = app.activeDocument.activeLayer;
fontSize = activeLayer.textItem.size;
colorArray = [0, 0, 0];
if(activeLayer.kind == LayerKind.TEXT){
if((activeLayer.textItem.contents != "")&&(start >= 0)&&(end <= activeLayer.textItem.contents.length)){
var idsetd = app.charIDToTypeID( "setd" );
var action = new ActionDescriptor();
var idnull = app.charIDToTypeID( "null" );
var reference = new ActionReference();
var idTxLr = app.charIDToTypeID( "TxLr" );
var idOrdn = app.charIDToTypeID( "Ordn" );
var idTrgt = app.charIDToTypeID( "Trgt" );
reference.putEnumerated( idTxLr, idOrdn, idTrgt );
action.putReference( idnull, reference );
var idT = app.charIDToTypeID( "T " );
var textAction = new ActionDescriptor();
var idTxtt = app.charIDToTypeID( "Txtt" );
var actionList = new ActionList();
var textRange = new ActionDescriptor();
var idFrom = app.charIDToTypeID( "From" );
textRange.putInteger( idFrom, start );
textRange.putInteger( idT, end );
var idTxtS = app.charIDToTypeID( "TxtS" );
var formatting = new ActionDescriptor();
var idFntN = app.charIDToTypeID( "FntN" );
formatting.putString( idFntN, fontName );
var idFntS = app.charIDToTypeID( "FntS" );
formatting.putString( idFntS, fontStyle );
var idSz = app.charIDToTypeID( "Sz " );
var idPnt = app.charIDToTypeID( "#Pnt" );
formatting.putUnitDouble( idSz, idPnt, fontSize );
var idClr = app.charIDToTypeID( "Clr " );
var colorAction = new ActionDescriptor();
var idRd = app.charIDToTypeID( "Rd " );
colorAction.putDouble( idRd, colorArray[0] );
var idGrn = app.charIDToTypeID( "Grn " );
colorAction.putDouble( idGrn, colorArray[1]);
var idBl = app.charIDToTypeID( "Bl " );
colorAction.putDouble( idBl, colorArray[2] );
var idRGBC = app.charIDToTypeID( "RGBC" );
formatting.putObject( idClr, idRGBC, colorAction );
textRange.putObject( idTxtS, idTxtS, formatting );
actionList.putObject( idTxtt, textRange );
textAction.putList( idTxtt, actionList );
action.putObject( idT, idTxLr, textAction );
app.executeAction( idsetd, action, DialogModes.NO );
}
}
}
}

View File

@@ -1,3 +1,4 @@
#include lib.js
var saveFile = File(arguments[0]);
if(saveFile.exists)
saveFile.remove();
@@ -7,4 +8,5 @@ saveFile.open("e", "TEXT", "????");
for (var i = 0; i < arguments.length; i++) {
saveFile.writeln(arguments[i])
}
setFormatting(0,6, "Arial", "Bold");
saveFile.close();