Skip to main content
Known Participant
March 20, 2023
Question

Photoshop script to generate the report with the content and its Font name

  • March 20, 2023
  • 1 reply
  • 2208 views

Hi,


In Photoshop document, there are many layers with different fonts. My task is to generate the report with content and its font name.

I am unable to find the respective content with font name, if suppose that text layer contain 2 or more fonts (see below screenshot).

I explore many places in our forum community (link), but on that I can able to get the font name which is applied for first charter/word if suppose that text layer contain more than 2 fonts. I am unable to find next font applied in the same text layer.

Can any one help to generate the report as shown above screenshot?

Thanks
Asuvath

 

This topic has been closed for replies.

1 reply

c.pfaffenbichler
Community Expert
Community Expert
March 20, 2023

What is the point of the task? 

 

This collects the fonts in a document: 

// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
//
main ();
};
////////////////////////////////////
function main () {
var theFonts = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
//////
for (var m = theNumber; m >= 0; m--) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
var theName = layerDesc.getString(stringIDToTypeID('name'));
// if not layer group collect values;
if (layerSet != "layerSectionEnd" && layerSet != "layerSectionStart" && isBackground != true) {
var hasText = layerDesc.hasKey(stringIDToTypeID("textKey"));
if (hasText == true) {
var textDesc = layerDesc.getObjectValue(stringIDToTypeID('textKey'));
var paragraphRangeList = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));
var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
for (var o = 0; o < rangeList.count; o++) {
var styleDesc = rangeList.getObjectValue(o).getObjectValue(stringIDToTypeID('textStyle'));
// check for default font;
if (styleDesc.hasKey(stringIDToTypeID('fontPostScriptName')) == true) {var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'))}
else {
	var theDefault = styleDesc.getObjectValue(stringIDToTypeID('baseParentStyle'));
	var aFont = theDefault.getString(stringIDToTypeID('fontPostScriptName'));
	};
// add to array;
var theCheck = true;
for (var n = 0; n < theFonts.length; n++) {
if (theFonts[n] == aFont) {theCheck = false}
};
if (theCheck  == true) {theFonts.push(aFont)}
}
}
}
}
catch (e) {};
}
alert ("the result:"+"\n"+theFonts.join("\n"))
};

 

AsuvathAuthor
Known Participant
March 20, 2023

Hi @c.pfaffenbichler ,


Thanks, I need the content with respective font names for the same layer (See below screenshot). Sorry, I am not need to collect all the fonts.

My problem is unable to get the 2nd font name and content from the same layer. Please do the needful.


Thanks
Asuvath

 

c.pfaffenbichler
Community Expert
Community Expert
March 20, 2023

Have you looked at the Script I posted? 

The functionality that evaluates the Fonts of each Type Layer (in the for-clause

for (var m = theNumber; m >= 0; m--) {

) can be adapted to evaluate one Layer. 

Please take an effort to do your own adaption. 

 

Edit: 

// get keys for type layer’s style;
// 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'));
var paragraphStyle = textDesc.getList(stringIDToTypeID('paragraphStyleRange'));
var kernRange = textDesc.getList(stringIDToTypeID('kerningRange'));
var rangeList = textDesc.getList(stringIDToTypeID('textStyleRange'));
var theFonts = new Array;
for (var m = 0; m < rangeList.count; m++) {
var styleDesc = rangeList.getObjectValue(m).getObjectValue(stringIDToTypeID('textStyle'));
var aFont = styleDesc.getString(stringIDToTypeID('fontPostScriptName'));
// check if font is already in array;
var theCheck = true;
for (var n = 0; n < theFonts.length; n++) {
if (theFonts[n] == aFont) {theCheck = false}
};
if (theCheck  == true) {theFonts.push(aFont)}
};
alert (theFonts.join("\n"));
}
};