I have this script that reads the selected text layer and adds a text layer to display the font info.
When it creates an new text layer to display font info, is possible to underline only a portion of the text that is displayed, an example is this:
Current Display Format:
(This line of text is a)
(if the script will)
(properly.)
Font: Arial-BoldMT
Size: 24px
Color: #000000
Justify: Left
Ideal Text Format:
(This line of text is a)
(if the script will)
(properly.)
Font: Arial-BoldMT
Size: 24px
Color: #000000
Justify: Left
Actual Code:
Code: Select allfunction multiselectfontreader() {
// by paul riggott; MULTI-SELECT Function
app.bringToFront();
main();
function main() {
if (!documents.length) return;
var selLayers = [];
selLayers = getSelectedLayersIdx();
for (var a in selLayers) {
makeActiveByIndex(selLayers[a], false);
//amend to suit.
readTextLayer()
}
}
function getSelectedLayersIdx() {
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
if (desc.hasKey(stringIDToTypeID('targetLayers'))) {
desc = desc.getList(stringIDToTypeID('targetLayers'));
var c = desc.count
var selectedLayers = new Array();
for (var i = 0; i < c; i++) {
try {
activeDocument.backgroundLayer;
selectedLayers.push(desc.getReference(i).getIndex());
} catch (e) {
selectedLayers.push(desc.getReference(i).getIndex() + 1);
}
}
} else {
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("ItmI"));
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
try {
activeDocument.backgroundLayer;
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1);
} catch (e) {
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")));
}
}
return selectedLayers;
};
function makeActiveByIndex(idx, visible) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), idx)
desc.putReference(charIDToTypeID("null"), ref);
desc.putBoolean(charIDToTypeID("MkVs"), visible);
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
};
};
// Read one or more selected fonts
function readTextLayer() {
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
var myLayer = myDoc.activeLayer;
if (myLayer.kind == LayerKind.TEXT) {
var thisText = myLayer.textItem;
// Renaming the Justifcation info from Justification.CENTER - > Center;
try {
var theJustification = String(thisText.justification).replace("Justification.", "")
} catch (e) {
var theJustification = "LEFT"
};
theJustification = theJustification[0] + theJustification.slice(1, theJustification.length).toLowerCase();
var fonts = getFonts(app.activeDocument.activeLayer);
for (var i = 0; i < fonts.length; i++) {
addTextLayer(
((fonts.length > 1) ? fonts.text + "\r" : '') +
"Font: " + fonts.font + "\r" +
"Size: " + fonts.size + "\r" +
"Color: #" + fonts.color + "\r" +
((i === 0 && fonts.leading !== '') ? "Leading: " + fonts.leading + "\r" : '') +
((i === 0) ? "Justify: " + theJustification + "\r" : ''),
"Font Info #" + (i + 1),
[myLayer.bounds[0] + i * 300, myLayer.bounds[3] + 15]
)
}
}
}
};
// Add's a text layer which contains the content of the read string above
function addTextLayer(theText, theName, thePosition) {
var aTextLayer = app.activeDocument.artLayers.add();
aTextLayer.kind = LayerKind.TEXT;
aTextLayer.name = theName;
var aTextLayerRef = aTextLayer.textItem;
aTextLayerRef.kind = TextType.POINTTEXT;
aTextLayerRef.size = 10;
aTextLayerRef.font = "Arial-BoldMT";
aTextLayerRef.color = app.foregroundColor;
aTextLayerRef.justification = Justification.LEFT;
aTextLayerRef.position = thePosition;
aTextLayer.blendMode = BlendMode.NORMAL;
aTextLayer.opacity = 100;
aTextLayer.fillOpacity = 100;
aTextLayerRef.useAutoLeading = true;
aTextLayerRef.leading = 0;
aTextLayerRef.horizontalScale = 100;
aTextLayerRef.verticalScale = 100;
aTextLayerRef.contents = theText;
aTextLayerRef.antiAliasMethod = AntiAlias.SHARP;
//Move the newly created font layers into the existing "Pixel Spec" folder
var doc = app.activeDocument;
var srcLayer = doc.activeLayer;
try
{
moveLayerToSet(doc, srcLayer, 'Pixel Specs');
}
catch(error)
{
false;
}
function moveLayerToSet(doc, srcLayer, toLayerName) {
var destLayer = doc.layers[toLayerName];
if(destLayer.layers) destLayer = destLayer.layers[0];
srcLayer.move(destLayer, ElementPlacement.PLACEBEFORE);
}
};
// get fonts and other parameters used in type layer
function getFonts(textLayer) {
function markReturnedContentText(text) {
if (font_content_detection_marks) {
return font_content_detection_symbols[0] + text + font_content_detection_symbols[1];
} else {
return text;
}
}
if (textLayer.kind == LayerKind.TEXT) {
app.activeDocument.activeLayer = textLayer;
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var layerDesc = executeActionGet(ref);
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
var fonts = [];
for (var m = 0; m < rangeList.count; m++) {
var styleDesc = rangeList.getObjectValue(m).getObjectValue(stringIDToTypeID('textStyle'));
var aFrom = rangeList.getObjectValue(m).getInteger(stringIDToTypeID('from'));
var aTo = rangeList.getObjectValue(m).getInteger(stringIDToTypeID('to'));
var theLetters = app.activeDocument.activeLayer.textItem.contents.slice(aFrom, aTo);
var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'));
try {
//var aSize = styleDesc.getUnitDoubleValue(stringIDToTypeID('size')) + " " + typeIDToCharID(styleDesc.getUnitDoubleType(stringIDToTypeID('size')));
var aSize = styleDesc.getUnitDoubleValue(stringIDToTypeID('size')) + "px";
} catch (e) {
var aSize = '';
};
try {
var Colour = new SolidColor;
Colour.rgb.red = styleDesc.getObjectValue(stringIDToTypeID('color')).getUnitDoubleValue(stringIDToTypeID('red'));
Colour.rgb.green = styleDesc.getObjectValue(stringIDToTypeID('color')).getUnitDoubleValue(stringIDToTypeID('green'));
Colour.rgb.blue = styleDesc.getObjectValue(stringIDToTypeID('color')).getUnitDoubleValue(stringIDToTypeID('blue'));
var aColor = Colour.rgb.hexValue;
} catch (e) {
var aColor = '';
};
try {
//var aLeading = styleDesc.getUnitDoubleValue(stringIDToTypeID('leading')) + " " +typeIDToCharID(styleDesc.getUnitDoubleType(stringIDToTypeID('leading')));
var aLeading = styleDesc.getUnitDoubleValue(stringIDToTypeID('leading')) + "px";
} catch (e) {
var aLeading = '';
};
var txt = theLetters.replace(/^\s+/, '').replace(/\s+$/, '');
var merged = false;
if (txt.length > 0) {
for (var x = 0; x < m; x++) {
try {
if (fonts[x].font === aFont && fonts[x].size === aSize && fonts[x].color === aColor && fonts[x].leading === aLeading) {
// It's a hack!!!
if (fonts[x].text !== txt) {
fonts[x].text += markReturnedContentText(txt) + "\r";
}
merged = true;
}
} catch (e) {}
}
if (!merged) {
fonts.push({
text: markReturnedContentText(txt) + "\r",
font: aFont,
size: aSize,
color: aColor,
leading: aLeading
});
}
}
};
return fonts;
}
};
Underlining Part of Text Via Script
-
pfaffenbichler
Underlining Part of Text Via Script
The following function can be used to create partially underlined text.
The Script uses an array of arrays to create a text layer with the text »ONE TWO THREE« where »TWO « is underlined and 15pt, while »ONE « and »THREE« are 12pt.
Code: Select allvar theArray = [
["ONE ", 12, "Arial", false],
["TWO ", 15, "Arial", true],
["THREE", 12, "Arial", false]
];
createPointTextMoreCompl (theArray, 30, 30);
////// create point text layer //////
function createPointTextMoreCompl (theArray, theX, theY) {
if (theArray[0].length > 0) {
// join the texts;
var theText = new String;
for (var m = 0; m < theArray.length; m++) {
theText = theText + theArray[m][0]
};
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idTxLr = charIDToTypeID( "TxLr" );
ref2.putClass( idTxLr );
desc4.putReference( idnull, ref2 );
var idUsng = charIDToTypeID( "Usng" );
var desc5 = new ActionDescriptor();
var idTxt = charIDToTypeID( "Txt " );
// text;
desc5.putString( idTxt, theText );
var idwarp = stringIDToTypeID( "warp" );
var desc6 = new ActionDescriptor();
var idwarpStyle = stringIDToTypeID( "warpStyle" );
var idwarpStyle = stringIDToTypeID( "warpStyle" );
var idwarpNone = stringIDToTypeID( "warpNone" );
desc6.putEnumerated( idwarpStyle, idwarpStyle, idwarpNone );
var idwarpValue = stringIDToTypeID( "warpValue" );
desc6.putDouble( idwarpValue, 0.000000 );
var idwarpPerspective = stringIDToTypeID( "warpPerspective" );
desc6.putDouble( idwarpPerspective, 0.000000 );
var idwarpPerspectiveOther = stringIDToTypeID( "warpPerspectiveOther" );
desc6.putDouble( idwarpPerspectiveOther, 0.000000 );
var idwarpRotate = stringIDToTypeID( "warpRotate" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc6.putEnumerated( idwarpRotate, idOrnt, idHrzn );
var idwarp = stringIDToTypeID( "warp" );
desc5.putObject( idwarp, idwarp, desc6 );
// position;
var idTxtC = charIDToTypeID( "TxtC" );
var desc7 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPrc = charIDToTypeID( "#Prc" );
desc7.putUnitDouble( idHrzn, idPrc, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPrc = charIDToTypeID( "#Prc" );
desc7.putUnitDouble( idVrtc, idPrc, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc5.putObject( idTxtC, idPnt, desc7 );
var idtextGridding = stringIDToTypeID( "textGridding" );
var idtextGridding = stringIDToTypeID( "textGridding" );
var idNone = charIDToTypeID( "None" );
desc5.putEnumerated( idtextGridding, idtextGridding, idNone );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc5.putEnumerated( idOrnt, idOrnt, idHrzn );
var idAntA = charIDToTypeID( "AntA" );
var idAnnt = charIDToTypeID( "Annt" );
var idantiAliasSharp = stringIDToTypeID( "antiAliasSharp" );
desc5.putEnumerated( idAntA, idAnnt, idantiAliasSharp );
var idtextShape = stringIDToTypeID( "textShape" );
var list1 = new ActionList();
var desc8 = new ActionDescriptor();
var idTEXT = charIDToTypeID( "TEXT" );
var idTEXT = charIDToTypeID( "TEXT" );
var idPnt = charIDToTypeID( "Pnt " );
desc8.putEnumerated( idTEXT, idTEXT, idPnt );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc8.putEnumerated( idOrnt, idOrnt, idHrzn );
var idTrnf = charIDToTypeID( "Trnf" );
var desc9 = new ActionDescriptor();
var idxx = stringIDToTypeID( "xx" );
desc9.putDouble( idxx, 1.000000 );
var idxy = stringIDToTypeID( "xy" );
desc9.putDouble( idxy, 0.000000 );
var idyx = stringIDToTypeID( "yx" );
desc9.putDouble( idyx, 0.000000 );
var idyy = stringIDToTypeID( "yy" );
desc9.putDouble( idyy, 1.000000 );
var idtx = stringIDToTypeID( "tx" );
desc9.putDouble( idtx, 0.000000 );
var idty = stringIDToTypeID( "ty" );
desc9.putDouble( idty, 0.000000 );
var idTrnf = charIDToTypeID( "Trnf" );
desc8.putObject( idTrnf, idTrnf, desc9 );
var idrowCount = stringIDToTypeID( "rowCount" );
desc8.putInteger( idrowCount, 1 );
var idcolumnCount = stringIDToTypeID( "columnCount" );
desc8.putInteger( idcolumnCount, 1 );
var idrowMajorOrder = stringIDToTypeID( "rowMajorOrder" );
desc8.putBoolean( idrowMajorOrder, true );
var idrowGutter = stringIDToTypeID( "rowGutter" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idrowGutter, idPnt, 0.000000 );
var idcolumnGutter = stringIDToTypeID( "columnGutter" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idcolumnGutter, idPnt, 0.000000 );
var idSpcn = charIDToTypeID( "Spcn" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idSpcn, idPnt, 0.000000 );
var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );
var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );
var idalignByAscent = stringIDToTypeID( "alignByAscent" );
desc8.putEnumerated( idframeBaselineAlignment, idframeBaselineAlignment, idalignByAscent );
var idfirstBaselineMinimum = stringIDToTypeID( "firstBaselineMinimum" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idfirstBaselineMinimum, idPnt, 0.000000 );
var idbase = stringIDToTypeID( "base" );
var desc10 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
desc10.putDouble( idHrzn, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
desc10.putDouble( idVrtc, 0.000000 );
var idPnt = charIDToTypeID( "Pnt " );
desc8.putObject( idbase, idPnt, desc10 );
var idtextShape = stringIDToTypeID( "textShape" );
list1.putObject( idtextShape, desc8 );
desc5.putList( idtextShape, list1 );
var idTxtt = charIDToTypeID( "Txtt" );
var list2 = new ActionList();
var desc11 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
// from;
desc11.putInteger( idFrom, 0 );
var idT = charIDToTypeID( "T " );
// to;
desc11.putInteger( idT, theArray[0][0].length);
var idTxtS = charIDToTypeID( "TxtS" );
var desc12 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc12.putBoolean( idstyleSheetHasParent, true );
var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
// font;
desc12.putString( idfontPostScriptName, theArray[0][2] );
var idScrp = charIDToTypeID( "Scrp" );
desc12.putInteger( idScrp, 0 );
var idFntT = charIDToTypeID( "FntT" );
desc12.putInteger( idFntT, 1 );
var idSz = charIDToTypeID( "Sz " );
var idPnt = charIDToTypeID( "#Pnt" );
// size;
desc12.putUnitDouble( idSz, idPnt, theArray[0][1] );
var idTrck = charIDToTypeID( "Trck" );
desc12.putInteger( idTrck, 15 );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddefaultDigits = stringIDToTypeID( "defaultDigits" );
desc12.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );
var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );
var idPnt = charIDToTypeID( "#Pnt" );
desc12.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );
// underline;
if (theArray[0][3] == true) {
var idUndl = charIDToTypeID( "Undl" );
var idUndl = charIDToTypeID( "Undl" );
var idunderlineOnLeftInVertical = stringIDToTypeID( "underlineOnLeftInVertical" );
desc12.putEnumerated( idUndl, idUndl, idunderlineOnLeftInVertical );
};
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );
desc12.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );
var idClr = charIDToTypeID( "Clr " );
var desc13 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc13.putDouble( idRd, 0 );
var idGrn = charIDToTypeID( "Grn " );
desc13.putDouble( idGrn, 0 );
var idBl = charIDToTypeID( "Bl " );
desc13.putDouble( idBl, 0 );
var idRGBC = charIDToTypeID( "RGBC" );
desc12.putObject( idClr, idRGBC, desc13 );
var idTxtS = charIDToTypeID( "TxtS" );
desc11.putObject( idTxtS, idTxtS, desc12 );
var idTxtt = charIDToTypeID( "Txtt" );
list2.putObject( idTxtt, desc11 );
// if more than one array;
// add the string’s lengths;
var theCounter = theArray[0][0].length;
for (var n = 1; n < theArray.length; n++) {
var desc14 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
// from;
desc14.putInteger( idFrom, theCounter );
var idT = charIDToTypeID( "T " );
theCounter = theCounter + theArray[n][0].length;
// to;
desc14.putInteger( idT, theCounter );
var idTxtS = charIDToTypeID( "TxtS" );
var desc15 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc15.putBoolean( idstyleSheetHasParent, true );
var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
// font;
desc15.putString( idfontPostScriptName, theArray[n][2] );
var idScrp = charIDToTypeID( "Scrp" );
desc15.putInteger( idScrp, 0 );
var idFntT = charIDToTypeID( "FntT" );
desc15.putInteger( idFntT, 0 );
var idSz = charIDToTypeID( "Sz " );
var idPnt = charIDToTypeID( "#Pnt" );
// size;
desc15.putUnitDouble( idSz, idPnt, theArray[n][1] );
var idTrck = charIDToTypeID( "Trck" );
desc15.putInteger( idTrck, 15 );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddefaultDigits = stringIDToTypeID( "defaultDigits" );
desc15.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );
var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );
var idPnt = charIDToTypeID( "#Pnt" );
desc15.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );
// underline;
if (theArray[n][3] == true) {
var idUndl = charIDToTypeID( "Undl" );
var idUndl = charIDToTypeID( "Undl" );
var idunderlineOnLeftInVertical = stringIDToTypeID( "underlineOnLeftInVertical" );
desc15.putEnumerated( idUndl, idUndl, idunderlineOnLeftInVertical );
};
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );
desc15.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );
var idClr = charIDToTypeID( "Clr " );
var desc16 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc16.putDouble( idRd, 0 );
var idGrn = charIDToTypeID( "Grn " );
desc16.putDouble( idGrn, 0 );
var idBl = charIDToTypeID( "Bl " );
desc16.putDouble( idBl, 0 );
var idRGBC = charIDToTypeID( "RGBC" );
desc15.putObject( idClr, idRGBC, desc16 );
var idTxtS = charIDToTypeID( "TxtS" );
desc14.putObject( idTxtS, idTxtS, desc15 );
var idTxtt = charIDToTypeID( "Txtt" );
list2.putObject( idTxtt, desc14 );
};
desc5.putList( idTxtt, list2 );
////////////////////////////////////
var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );
var list3 = new ActionList();
var desc17 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
desc17.putInteger( idFrom, 0 );
var idT = charIDToTypeID( "T " );
// to;
desc17.putInteger( idT, theText.length*2);
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
var desc18 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc18.putBoolean( idstyleSheetHasParent, true );
var idAlgn = charIDToTypeID( "Algn" );
var idAlg = charIDToTypeID( "Alg " );
var idCntr = charIDToTypeID( "Cntr" );
desc18.putEnumerated( idAlgn, idAlg, idCntr );
var idhyphenate = stringIDToTypeID( "hyphenate" );
desc18.putBoolean( idhyphenate, true );
var idhyphenateWordSize = stringIDToTypeID( "hyphenateWordSize" );
desc18.putInteger( idhyphenateWordSize, 8 );
var idhyphenatePreLength = stringIDToTypeID( "hyphenatePreLength" );
desc18.putInteger( idhyphenatePreLength, 3 );
var idhyphenatePostLength = stringIDToTypeID( "hyphenatePostLength" );
desc18.putInteger( idhyphenatePostLength, 3 );
var idhyphenateLimit = stringIDToTypeID( "hyphenateLimit" );
desc18.putInteger( idhyphenateLimit, 2 );
var idhyphenationZone = stringIDToTypeID( "hyphenationZone" );
desc18.putDouble( idhyphenationZone, 36.000000 );
var idhyphenateCapitalized = stringIDToTypeID( "hyphenateCapitalized" );
desc18.putBoolean( idhyphenateCapitalized, true );
var idburasagari = stringIDToTypeID( "burasagari" );
var idburasagari = stringIDToTypeID( "burasagari" );
var idburasagariStandard = stringIDToTypeID( "burasagariStandard" );
desc18.putEnumerated( idburasagari, idburasagari, idburasagariStandard );
var idtextEveryLineComposer = stringIDToTypeID( "textEveryLineComposer" );
desc18.putBoolean( idtextEveryLineComposer, true );
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
desc17.putObject( idparagraphStyle, idparagraphStyle, desc18 );
var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );
list3.putObject( idparagraphStyleRange, desc17 );
desc5.putList( idparagraphStyleRange, list3 );
var idkerningRange = stringIDToTypeID( "kerningRange" );
var list4 = new ActionList();
desc5.putList( idkerningRange, list4 );
var idTxLr = charIDToTypeID( "TxLr" );
desc4.putObject( idUsng, idTxLr, desc5 );
executeAction( idMk, desc4, DialogModes.NO );
}
};
The Script uses an array of arrays to create a text layer with the text »ONE TWO THREE« where »TWO « is underlined and 15pt, while »ONE « and »THREE« are 12pt.
Code: Select allvar theArray = [
["ONE ", 12, "Arial", false],
["TWO ", 15, "Arial", true],
["THREE", 12, "Arial", false]
];
createPointTextMoreCompl (theArray, 30, 30);
////// create point text layer //////
function createPointTextMoreCompl (theArray, theX, theY) {
if (theArray[0].length > 0) {
// join the texts;
var theText = new String;
for (var m = 0; m < theArray.length; m++) {
theText = theText + theArray[m][0]
};
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idTxLr = charIDToTypeID( "TxLr" );
ref2.putClass( idTxLr );
desc4.putReference( idnull, ref2 );
var idUsng = charIDToTypeID( "Usng" );
var desc5 = new ActionDescriptor();
var idTxt = charIDToTypeID( "Txt " );
// text;
desc5.putString( idTxt, theText );
var idwarp = stringIDToTypeID( "warp" );
var desc6 = new ActionDescriptor();
var idwarpStyle = stringIDToTypeID( "warpStyle" );
var idwarpStyle = stringIDToTypeID( "warpStyle" );
var idwarpNone = stringIDToTypeID( "warpNone" );
desc6.putEnumerated( idwarpStyle, idwarpStyle, idwarpNone );
var idwarpValue = stringIDToTypeID( "warpValue" );
desc6.putDouble( idwarpValue, 0.000000 );
var idwarpPerspective = stringIDToTypeID( "warpPerspective" );
desc6.putDouble( idwarpPerspective, 0.000000 );
var idwarpPerspectiveOther = stringIDToTypeID( "warpPerspectiveOther" );
desc6.putDouble( idwarpPerspectiveOther, 0.000000 );
var idwarpRotate = stringIDToTypeID( "warpRotate" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc6.putEnumerated( idwarpRotate, idOrnt, idHrzn );
var idwarp = stringIDToTypeID( "warp" );
desc5.putObject( idwarp, idwarp, desc6 );
// position;
var idTxtC = charIDToTypeID( "TxtC" );
var desc7 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPrc = charIDToTypeID( "#Prc" );
desc7.putUnitDouble( idHrzn, idPrc, theX );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPrc = charIDToTypeID( "#Prc" );
desc7.putUnitDouble( idVrtc, idPrc, theY );
var idPnt = charIDToTypeID( "Pnt " );
desc5.putObject( idTxtC, idPnt, desc7 );
var idtextGridding = stringIDToTypeID( "textGridding" );
var idtextGridding = stringIDToTypeID( "textGridding" );
var idNone = charIDToTypeID( "None" );
desc5.putEnumerated( idtextGridding, idtextGridding, idNone );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc5.putEnumerated( idOrnt, idOrnt, idHrzn );
var idAntA = charIDToTypeID( "AntA" );
var idAnnt = charIDToTypeID( "Annt" );
var idantiAliasSharp = stringIDToTypeID( "antiAliasSharp" );
desc5.putEnumerated( idAntA, idAnnt, idantiAliasSharp );
var idtextShape = stringIDToTypeID( "textShape" );
var list1 = new ActionList();
var desc8 = new ActionDescriptor();
var idTEXT = charIDToTypeID( "TEXT" );
var idTEXT = charIDToTypeID( "TEXT" );
var idPnt = charIDToTypeID( "Pnt " );
desc8.putEnumerated( idTEXT, idTEXT, idPnt );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc8.putEnumerated( idOrnt, idOrnt, idHrzn );
var idTrnf = charIDToTypeID( "Trnf" );
var desc9 = new ActionDescriptor();
var idxx = stringIDToTypeID( "xx" );
desc9.putDouble( idxx, 1.000000 );
var idxy = stringIDToTypeID( "xy" );
desc9.putDouble( idxy, 0.000000 );
var idyx = stringIDToTypeID( "yx" );
desc9.putDouble( idyx, 0.000000 );
var idyy = stringIDToTypeID( "yy" );
desc9.putDouble( idyy, 1.000000 );
var idtx = stringIDToTypeID( "tx" );
desc9.putDouble( idtx, 0.000000 );
var idty = stringIDToTypeID( "ty" );
desc9.putDouble( idty, 0.000000 );
var idTrnf = charIDToTypeID( "Trnf" );
desc8.putObject( idTrnf, idTrnf, desc9 );
var idrowCount = stringIDToTypeID( "rowCount" );
desc8.putInteger( idrowCount, 1 );
var idcolumnCount = stringIDToTypeID( "columnCount" );
desc8.putInteger( idcolumnCount, 1 );
var idrowMajorOrder = stringIDToTypeID( "rowMajorOrder" );
desc8.putBoolean( idrowMajorOrder, true );
var idrowGutter = stringIDToTypeID( "rowGutter" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idrowGutter, idPnt, 0.000000 );
var idcolumnGutter = stringIDToTypeID( "columnGutter" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idcolumnGutter, idPnt, 0.000000 );
var idSpcn = charIDToTypeID( "Spcn" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idSpcn, idPnt, 0.000000 );
var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );
var idframeBaselineAlignment = stringIDToTypeID( "frameBaselineAlignment" );
var idalignByAscent = stringIDToTypeID( "alignByAscent" );
desc8.putEnumerated( idframeBaselineAlignment, idframeBaselineAlignment, idalignByAscent );
var idfirstBaselineMinimum = stringIDToTypeID( "firstBaselineMinimum" );
var idPnt = charIDToTypeID( "#Pnt" );
desc8.putUnitDouble( idfirstBaselineMinimum, idPnt, 0.000000 );
var idbase = stringIDToTypeID( "base" );
var desc10 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
desc10.putDouble( idHrzn, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
desc10.putDouble( idVrtc, 0.000000 );
var idPnt = charIDToTypeID( "Pnt " );
desc8.putObject( idbase, idPnt, desc10 );
var idtextShape = stringIDToTypeID( "textShape" );
list1.putObject( idtextShape, desc8 );
desc5.putList( idtextShape, list1 );
var idTxtt = charIDToTypeID( "Txtt" );
var list2 = new ActionList();
var desc11 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
// from;
desc11.putInteger( idFrom, 0 );
var idT = charIDToTypeID( "T " );
// to;
desc11.putInteger( idT, theArray[0][0].length);
var idTxtS = charIDToTypeID( "TxtS" );
var desc12 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc12.putBoolean( idstyleSheetHasParent, true );
var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
// font;
desc12.putString( idfontPostScriptName, theArray[0][2] );
var idScrp = charIDToTypeID( "Scrp" );
desc12.putInteger( idScrp, 0 );
var idFntT = charIDToTypeID( "FntT" );
desc12.putInteger( idFntT, 1 );
var idSz = charIDToTypeID( "Sz " );
var idPnt = charIDToTypeID( "#Pnt" );
// size;
desc12.putUnitDouble( idSz, idPnt, theArray[0][1] );
var idTrck = charIDToTypeID( "Trck" );
desc12.putInteger( idTrck, 15 );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddefaultDigits = stringIDToTypeID( "defaultDigits" );
desc12.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );
var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );
var idPnt = charIDToTypeID( "#Pnt" );
desc12.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );
// underline;
if (theArray[0][3] == true) {
var idUndl = charIDToTypeID( "Undl" );
var idUndl = charIDToTypeID( "Undl" );
var idunderlineOnLeftInVertical = stringIDToTypeID( "underlineOnLeftInVertical" );
desc12.putEnumerated( idUndl, idUndl, idunderlineOnLeftInVertical );
};
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );
desc12.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );
var idClr = charIDToTypeID( "Clr " );
var desc13 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc13.putDouble( idRd, 0 );
var idGrn = charIDToTypeID( "Grn " );
desc13.putDouble( idGrn, 0 );
var idBl = charIDToTypeID( "Bl " );
desc13.putDouble( idBl, 0 );
var idRGBC = charIDToTypeID( "RGBC" );
desc12.putObject( idClr, idRGBC, desc13 );
var idTxtS = charIDToTypeID( "TxtS" );
desc11.putObject( idTxtS, idTxtS, desc12 );
var idTxtt = charIDToTypeID( "Txtt" );
list2.putObject( idTxtt, desc11 );
// if more than one array;
// add the string’s lengths;
var theCounter = theArray[0][0].length;
for (var n = 1; n < theArray.length; n++) {
var desc14 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
// from;
desc14.putInteger( idFrom, theCounter );
var idT = charIDToTypeID( "T " );
theCounter = theCounter + theArray[n][0].length;
// to;
desc14.putInteger( idT, theCounter );
var idTxtS = charIDToTypeID( "TxtS" );
var desc15 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc15.putBoolean( idstyleSheetHasParent, true );
var idfontPostScriptName = stringIDToTypeID( "fontPostScriptName" );
// font;
desc15.putString( idfontPostScriptName, theArray[n][2] );
var idScrp = charIDToTypeID( "Scrp" );
desc15.putInteger( idScrp, 0 );
var idFntT = charIDToTypeID( "FntT" );
desc15.putInteger( idFntT, 0 );
var idSz = charIDToTypeID( "Sz " );
var idPnt = charIDToTypeID( "#Pnt" );
// size;
desc15.putUnitDouble( idSz, idPnt, theArray[n][1] );
var idTrck = charIDToTypeID( "Trck" );
desc15.putInteger( idTrck, 15 );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddigitSet = stringIDToTypeID( "digitSet" );
var iddefaultDigits = stringIDToTypeID( "defaultDigits" );
desc15.putEnumerated( iddigitSet, iddigitSet, iddefaultDigits );
var idmarkYDistFromBaseline = stringIDToTypeID( "markYDistFromBaseline" );
var idPnt = charIDToTypeID( "#Pnt" );
desc15.putUnitDouble( idmarkYDistFromBaseline, idPnt, 5.760000 );
// underline;
if (theArray[n][3] == true) {
var idUndl = charIDToTypeID( "Undl" );
var idUndl = charIDToTypeID( "Undl" );
var idunderlineOnLeftInVertical = stringIDToTypeID( "underlineOnLeftInVertical" );
desc15.putEnumerated( idUndl, idUndl, idunderlineOnLeftInVertical );
};
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idtextLanguage = stringIDToTypeID( "textLanguage" );
var idgermanLanguageReformedonenineninesix = stringIDToTypeID( "germanLanguageReformed1996" );
desc15.putEnumerated( idtextLanguage, idtextLanguage, idgermanLanguageReformedonenineninesix );
var idClr = charIDToTypeID( "Clr " );
var desc16 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc16.putDouble( idRd, 0 );
var idGrn = charIDToTypeID( "Grn " );
desc16.putDouble( idGrn, 0 );
var idBl = charIDToTypeID( "Bl " );
desc16.putDouble( idBl, 0 );
var idRGBC = charIDToTypeID( "RGBC" );
desc15.putObject( idClr, idRGBC, desc16 );
var idTxtS = charIDToTypeID( "TxtS" );
desc14.putObject( idTxtS, idTxtS, desc15 );
var idTxtt = charIDToTypeID( "Txtt" );
list2.putObject( idTxtt, desc14 );
};
desc5.putList( idTxtt, list2 );
////////////////////////////////////
var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );
var list3 = new ActionList();
var desc17 = new ActionDescriptor();
var idFrom = charIDToTypeID( "From" );
desc17.putInteger( idFrom, 0 );
var idT = charIDToTypeID( "T " );
// to;
desc17.putInteger( idT, theText.length*2);
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
var desc18 = new ActionDescriptor();
var idstyleSheetHasParent = stringIDToTypeID( "styleSheetHasParent" );
desc18.putBoolean( idstyleSheetHasParent, true );
var idAlgn = charIDToTypeID( "Algn" );
var idAlg = charIDToTypeID( "Alg " );
var idCntr = charIDToTypeID( "Cntr" );
desc18.putEnumerated( idAlgn, idAlg, idCntr );
var idhyphenate = stringIDToTypeID( "hyphenate" );
desc18.putBoolean( idhyphenate, true );
var idhyphenateWordSize = stringIDToTypeID( "hyphenateWordSize" );
desc18.putInteger( idhyphenateWordSize, 8 );
var idhyphenatePreLength = stringIDToTypeID( "hyphenatePreLength" );
desc18.putInteger( idhyphenatePreLength, 3 );
var idhyphenatePostLength = stringIDToTypeID( "hyphenatePostLength" );
desc18.putInteger( idhyphenatePostLength, 3 );
var idhyphenateLimit = stringIDToTypeID( "hyphenateLimit" );
desc18.putInteger( idhyphenateLimit, 2 );
var idhyphenationZone = stringIDToTypeID( "hyphenationZone" );
desc18.putDouble( idhyphenationZone, 36.000000 );
var idhyphenateCapitalized = stringIDToTypeID( "hyphenateCapitalized" );
desc18.putBoolean( idhyphenateCapitalized, true );
var idburasagari = stringIDToTypeID( "burasagari" );
var idburasagari = stringIDToTypeID( "burasagari" );
var idburasagariStandard = stringIDToTypeID( "burasagariStandard" );
desc18.putEnumerated( idburasagari, idburasagari, idburasagariStandard );
var idtextEveryLineComposer = stringIDToTypeID( "textEveryLineComposer" );
desc18.putBoolean( idtextEveryLineComposer, true );
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
desc17.putObject( idparagraphStyle, idparagraphStyle, desc18 );
var idparagraphStyleRange = stringIDToTypeID( "paragraphStyleRange" );
list3.putObject( idparagraphStyleRange, desc17 );
desc5.putList( idparagraphStyleRange, list3 );
var idkerningRange = stringIDToTypeID( "kerningRange" );
var list4 = new ActionList();
desc5.putList( idkerningRange, list4 );
var idTxLr = charIDToTypeID( "TxLr" );
desc4.putObject( idUsng, idTxLr, desc5 );
executeAction( idMk, desc4, DialogModes.NO );
}
};
-
mycort
Underlining Part of Text Via Script
Great man, is it possible to do the same for making a part of the text string ALL CAPS too?
-
Mike Hale
Underlining Part of Text Via Script
At some point you should look at both a javascript language reference and the scripting references. You can convert text to all caps with String.toUpperCase().
-
mycort
Underlining Part of Text Via Script
But to convert only a part of the text, not all....isn't there a special code to do this?
-
Mike Hale
Underlining Part of Text Via Script
Using the code above, add an element to each range array.
Code: Select all var theArray = [
["One, ", 12, "Arial", false, false],
["two, ", 15, "Arial", true, true],
["three.", 12, "Arial", false, false]
];
Then below the code for underline add the following:
Code: Select all // all caps:
if (theArray[0][4] == true){
desc12.putEnumerated( stringIDToTypeID('fontCaps'), stringIDToTypeID('fontCaps'), stringIDToTypeID('allCaps') );
}else{
desc12.putEnumerated( stringIDToTypeID('fontCaps'), stringIDToTypeID('fontCaps'), charIDToTypeID('Nrml') );
}
Code: Select all var theArray = [
["One, ", 12, "Arial", false, false],
["two, ", 15, "Arial", true, true],
["three.", 12, "Arial", false, false]
];
Then below the code for underline add the following:
Code: Select all // all caps:
if (theArray[0][4] == true){
desc12.putEnumerated( stringIDToTypeID('fontCaps'), stringIDToTypeID('fontCaps'), stringIDToTypeID('allCaps') );
}else{
desc12.putEnumerated( stringIDToTypeID('fontCaps'), stringIDToTypeID('fontCaps'), charIDToTypeID('Nrml') );
}
-
pfaffenbichler
Underlining Part of Text Via Script
Please note that desc15 would also need the clause.
The function may be more clunky than necessary, but type features seem a somewhat convoluted issue to me.
The function may be more clunky than necessary, but type features seem a somewhat convoluted issue to me.
-
Mike Hale
Underlining Part of Text Via Script
Please note that desc15 would also need the clause.
That would be a good idea. I guess I didn't look closely enough at that code. I thought all the ranges were in one loop.
That would be a good idea. I guess I didn't look closely enough at that code. I thought all the ranges were in one loop.
-
mycort
Underlining Part of Text Via Script
Just got a question, I'm seeing code for One, Two, Three......does this specifically have to do with text string lines 1,2,3? What if the lines go beyond 3rd line, go to more like lines 4,5,6....etc? Hopefully I'm just not understanding this and is actually more scalable?