Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"))
};
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"));
}
};
Copy link to clipboard
Copied
Thanks, I need the content with respective font names for the same layer (See below screenshot).
What is that list intended to be used for?
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
We need this list for identify the content with its font name. So we will be change/modify the respective character attributes as user needs.
I hope this is clear my intension.
Thanks
Asuvath
Copy link to clipboard
Copied
I already added the code for the active Layer.
Copy link to clipboard
Copied
I'm not sure that there is an easy way to accomplish this. You would have to go through each text layer and check through all characters to see what font is used. You might want to ask on the InDesign forum about this, maybe you can import that files via script and identify fonts that way.
Copy link to clipboard
Copied
Thanks @Lumigraphics for understand my expectation as completely, you are very sharp and catch my expectation. Great.
I am 100% agree with your way of approach. Yes, we can able to get it easily in InDesign. But my expectation/task is in Photoshop.
Can you please do the needful.
Thanks
Asuvath
Copy link to clipboard
Copied
No, this forum is not "script on demand" where we write scripts to accomplish your needs. We can sometimes help, but you would need to either hire someone or write the script yourself if you have something custom like this that you need.. As I said, this may not be possible in Photoshop. I'm recommending that you look at other applications to see if they would work instead.
Copy link to clipboard
Copied
Hi @Lumigraphics ,
Yes, I am accept. Sorry, there is no way to change the application in my end. The reason, I put my problem here is to get any help from experts.
Dons of experts are alive here to help technically. I am really love this fourm to get the clarification. Thanks Adobe community.
I am eargly and confidently wait here for get resolution for my problem, I hope my wish maty be fullfil with some sweet hearts.
Let's see. Thanks for your help.
Thanks
Asuvath
Copy link to clipboard
Copied
Well good luck. You may not have a choice, you may HAVE TO use a different app to accomplish this.
Copy link to clipboard
Copied
And again: I already added the code for the active Layer.
Are you not viewing this Forum in the browser but relying on emails? Those naturally will not reflect edits.
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
Apologies. Actually I needed sometime to test your code with my document. So I took time for respond.
Wow, thanks your code is provide the list of fonts in the same text layer. Thank you so much. It is really helpful.
It is much appriciated if suppose I found the content with respective font.
I am weak in script listener coding. So I am unable to find which variable holding respective content and how to store that in new variable as my needs. Can you please?
Thanks
Asuvath
Copy link to clipboard
Copied
This will get the »from« and »to« for each font, how that relates to the letters in the text should not be to complicated to figure out.
And that’s it for me.
// based on code by michael l hale;
// 2023, use it at your own risk;
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 thisOne = rangeList.getObjectValue(m);
var aFont = thisOne.getObjectValue(stringIDToTypeID('textStyle')).getString(stringIDToTypeID('fontPostScriptName'));
var theFrom = thisOne.getInteger(stringIDToTypeID('from'));
var theTo = thisOne.getInteger(stringIDToTypeID('to'));
theFonts.push([aFont, theFrom, theTo]);
};
alert ("\n"+theFonts.join("\n"));
};
};
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
Thank you so much. Awesome, I think we reached almost 95% for the task.
I am poor in script listener, so I am unlucky to find the content (like, textItem.contents) even if we found the position where the font start and end.
Can you please advise where do I learn about "script listener".
Thanks
Asuvath
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
Are we able to get the layer name in this code as which layer have more than one fonts? When I test this tool, it is working for the whole document.
the task is to take the report which layer have more than one font.
Thanks
Asuvath
Copy link to clipboard
Copied
@Asuvath wrote:
Hi @c.pfaffenbichler ,
Are we able to get the layer name in this code as which layer have more than one fonts? When I test this tool, it is working for the whole document.
the task is to take the report which layer have more than one font.
Thanks
Asuvath
I posted three pieces of code
• one traverses all layers and gets the fonts for type layers
• one checks the active type layer and collects the fonts without multiples
• one checks the active type layer and collects the fonts for all rangeLists (this can lead to multiples, even when it are actually the size or other parameters that vary)
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
Thank you.
Yes, you are correct. I was struggling to get the respective type layer name from that code. Now I can able to get it.
Now I am trying to get the respective content with font name from that type layer if suppose that layer contain multiple fonts.
This shows I must to learn AM(Action Manager) code for get it if suppose we are not able to get it through DOM.
Thanks
Asuvath
Copy link to clipboard
Copied
The »to« and »from« properties from the last Script describe which letters in the String of text are affected by this particular setting.
Copy link to clipboard
Copied
Thanks @c.pfaffenbichler ,
Yes, you are correct. I am new to the action manager code, so I am not sure which code (syntex) is used to get that particular string from the content even if we have the start and end position.
var theFrom = thisOne.getInteger(stringIDToTypeID('from'));
var theTo = thisOne.getInteger(stringIDToTypeID('to'));
So I go through action manager related articles from forum, but still I am not get it. I am trying.
Thanks
Asuvath
Copy link to clipboard
Copied
You get the Text, then you can use the from/to-numbers to determine which letters are addressed.
var theText = textDesc.getString(stringIDToTypeID("textKey"));
Copy link to clipboard
Copied
@c.pfaffenbichler Thank you. I will use this code, I hope I will get the solution.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more