empty postscript name in extendscript

Community Beginner ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Hello fine folks

 

I am using the script appended at the end of the post.

My expectation is that the JSX will allow me to read the postscript name and other attributes of a text layer

When I run the script, the read operation results in a empty string '' for the postscript name!

At the same time, the Indesign tool, detects and presents the missing items prefectly

 

Here is the script

 

//get unique Array elements
Array.prototype.unique = function (){
    var r = new Array();
    o:for(var i = 0, n = this.length; i < n; i++){
        for(var x = 0, y = r.length; x < y; x++){
            if(r[x]==this[i]) continue o;}
        r[r.length] = this[i];}
    return r;
}

//search inside array
Array.prototype.findIn = function(search){
    var r = Array();
    for (var i=0; i<this.length; i++)
        if (this[i].indexOf(search) != -1){
            r.push(this[i].substr(this[i].indexOf("\t") + 1, this[i].length));
        }
    return r;
}

var usedFonts = app.activeDocument.fonts;

var sysFonts = app.fonts.everyItem();
sysFontsList = sysFonts.fontFamily.unique();
sysFontsList.unshift("- Select Font Family -");

var fontsWin = new Window('dialog', 'Document Fonts');
fontsWin.alignChildren = 'center';

var allFonts = fontsWin.add('listbox', undefined, undefined, {numberOfColumns: 5, showHeaders: true, columnTitles: ['Font Name', 'Font Style', 'Font PS Name', 'Font Type', 'Chr count']});
allFonts.minimumSize = [600,150];

var myGrp = fontsWin.add('group');
myGrp.alignChildren = 'center';

var availableFonts = myGrp.add('dropdownlist',undefined,sysFontsList);
var availableStyles = myGrp.add('dropdownlist');
var okButton = myGrp.add('button',undefined,'OK');
var okButton = myGrp.add('button',undefined,'Cancel');

availableStyles.minimumSize = [180,25];
availableFonts.selection = 0;
availableFonts.onChange = function(){
    availableStyles.removeAll();
    var sysFontAvailableStyles = sysFonts.name.findIn(availableFonts.selection);
    for(var i = 0; i < sysFontAvailableStyles.length; i++)availableStyles.add('item',sysFontAvailableStyles[i]);
    availableStyles.selection = 0;
}

//// SHOW JUST MISSING FONTS //// [START]

for(var i = 0; i < usedFonts.length; i++){
    if(usedFonts[i].status != FontStatus.INSTALLED){
        allFonts.add('item',usedFonts[i].fontFamily);
        allFonts.items[allFonts.items.length-1].image = 'SystemWarningIcon';
        allFonts.items[allFonts.items.length-1].subItems[3].text = findCharacters(usedFonts[i].name);

        try {
            allFonts.items[allFonts.items.length-1].subItems[0].text = usedFonts[i].fontStyleName;
        } catch (error) {
            allFonts.items[allFonts.items.length-1].subItems[0].text = 'NA';
        }
        try {
            allFonts.items[allFonts.items.length-1].subItems[1].text = usedFonts[i].postscriptName; // ''
        } catch (error) {
            allFonts.items[allFonts.items.length-1].subItems[1].text = 'NA';
        }
        try {
            allFonts.items[allFonts.items.length-1].subItems[2].text = usedFonts[i].fontType;
        } catch (error) {
            allFonts.items[allFonts.items.length-1].subItems[2].text = 'NA';
        }
    }
}

//// SHOW JUST MISSING FONTS //// [END]

allFonts.selection = 0;

fontsWin.center();

var fontAnswer = fontsWin.show();

if(fontAnswer == true && availableFonts.selection != 0){
    var sourceFont = allFonts.selection.text + "\t" + allFonts.selection.subItems[0].text;
    var destFont = availableFonts.selection.text + "\t" + availableStyles.selection.text;
    changeFont(sourceFont,destFont);
}else{
    alert('No Actions taken!');
}

function findCharacters(findFont){
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = ".";
    app.findGrepPreferences.appliedFont = findFont;
    var result = Number(app.activeDocument.findGrep().length);

    return result;
}
TOPICS
Scripting

Views

79

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Scripted font access hides a lot of complexity – under a thick layer of duct tape.

 

At the plug-in side I've observed a similar problem (missing postscript name) with a cross platform (Mac/Windows) document. Postscript names can differ across platforms, and consequently InDesign also stores them in different places. Could be that you're looking at the  other one …

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Hi RdMax,

your question is hard to answer. It depends on the particular situation your active document is in.

 

From my experience:

Could be that some properties of a used font are not avaialble by scripting when the font is "installed" in a Document fonts folder. Such a font can even "block" the same font installed in the system.

 

What is your situation in your case?

What's your operating system

How accesses the document needed fonts?

 

My experience is this:

When on Windows 10, you can get only valid information, if the font is installed for All Users and if the font is not stored at the same time in a Document fonts folder or the Fonts folder of the InDesign application.

 

That aside, what do you mean with "attributes of a text layer" in "My expectation is that the JSX will allow me to read the postscript name and other attributes of a text layer" ?

 

What does your test documents show?

Is there a PostScript name visible for a used font in menu Type > Find fonts… ?

If yes, you should be able to get the name by exporting the document to IDML and access the Fonts.xml file inside the IDML container. Just to give you an idea what could be found inside the Fonts.xml file, below an excerpt from a real world IDML file's Fonts.xml file:

 

<FontFamily Self="difd" Name="Helvetica">
		<Font Self="difdFontnHelvetica Narrow" FontFamily="Helvetica" Name="Helvetica Narrow" PostScriptName="Helvetica-Narrow" Status="Substituted" FontStyleName="Narrow" FontType="Type1" WritingScript="0" FullName="Helvetica Narrow" FullNameNative="Helvetica Narrow" FontStyleNameNative="$ID/Narrow" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Narrow Oblique" FontFamily="Helvetica" Name="Helvetica Narrow Oblique" PostScriptName="Helvetica-Narrow-Oblique" Status="Substituted" FontStyleName="Narrow Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Narrow Oblique" FullNameNative="Helvetica Narrow Oblique" FontStyleNameNative="$ID/Narrow Oblique" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold Narrow" FontFamily="Helvetica" Name="Helvetica Bold Narrow" PostScriptName="Helvetica-Narrow-Bold" Status="Substituted" FontStyleName="Bold Narrow" FontType="Type1" WritingScript="0" FullName="Helvetica Narrow Bold" FullNameNative="Helvetica Narrow Bold" FontStyleNameNative="$ID/Bold Narrow" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold Narrow Oblique" FontFamily="Helvetica" Name="Helvetica Bold Narrow Oblique" PostScriptName="Helvetica-Narrow-BoldOblique" Status="Substituted" FontStyleName="Bold Narrow Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Narrow Bold Oblique" FullNameNative="Helvetica Narrow Bold Oblique" FontStyleNameNative="$ID/Bold Narrow Oblique" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Medium" FontFamily="Helvetica" Name="Helvetica Medium" PostScriptName="Helvetica" Status="Substituted" FontStyleName="Medium" FontType="Type1" WritingScript="0" FullName="Helvetica" FullNameNative="Helvetica" FontStyleNameNative="$ID/Medium" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Oblique" FontFamily="Helvetica" Name="Helvetica Oblique" PostScriptName="Helvetica-Oblique" Status="Substituted" FontStyleName="Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Oblique" FullNameNative="Helvetica Oblique" FontStyleNameNative="$ID/Oblique" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold" FontFamily="Helvetica" Name="Helvetica Bold" PostScriptName="Helvetica-Bold" Status="Substituted" FontStyleName="Bold" FontType="Type1" WritingScript="0" FullName="Helvetica Bold" FullNameNative="Helvetica Bold" FontStyleNameNative="$ID/Bold" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Light Condensed" FontFamily="Helvetica" Name="Helvetica Light Condensed" PostScriptName="Helvetica-Condensed-Light" Status="Substituted" FontStyleName="Light Condensed" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Light" FullNameNative="Helvetica Condensed Light" FontStyleNameNative="$ID/Light Condensed" PlatformName="$ID/" Version="001.002" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Light Condensed Oblique" FontFamily="Helvetica" Name="Helvetica Light Condensed Oblique" PostScriptName="Helvetica-Condensed-LightObl" Status="Substituted" FontStyleName="Light Condensed Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Light Oblique" FullNameNative="Helvetica Condensed Light Oblique" FontStyleNameNative="$ID/Light Condensed Oblique" PlatformName="$ID/" Version="001.002" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Medium Condensed" FontFamily="Helvetica" Name="Helvetica Medium Condensed" PostScriptName="Helvetica-Condensed" Status="Substituted" FontStyleName="Medium Condensed" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Medium" FullNameNative="Helvetica Condensed Medium" FontStyleNameNative="$ID/Medium Condensed" PlatformName="$ID/" Version="001.003" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Condensed Oblique" FontFamily="Helvetica" Name="Helvetica Condensed Oblique" PostScriptName="Helvetica-Condensed-Oblique" Status="Substituted" FontStyleName="Condensed Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Oblique" FullNameNative="Helvetica Condensed Oblique" FontStyleNameNative="$ID/Condensed Oblique" PlatformName="$ID/" Version="001.003" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold Condensed" FontFamily="Helvetica" Name="Helvetica Bold Condensed" PostScriptName="Helvetica-Condensed-Bold" Status="Substituted" FontStyleName="Bold Condensed" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Bold" FullNameNative="Helvetica Condensed Bold" FontStyleNameNative="$ID/Bold Condensed" PlatformName="$ID/" Version="001.004" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold Condensed Oblique" FontFamily="Helvetica" Name="Helvetica Bold Condensed Oblique" PostScriptName="Helvetica-Condensed-BoldObl" Status="Substituted" FontStyleName="Bold Condensed Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Bold Oblique" FullNameNative="Helvetica Condensed Bold Oblique" FontStyleNameNative="$ID/Bold Condensed Oblique" PlatformName="$ID/" Version="001.004" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Black Condensed" FontFamily="Helvetica" Name="Helvetica Black Condensed" PostScriptName="Helvetica-Condensed-Black" Status="Substituted" FontStyleName="Black Condensed" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Black" FullNameNative="Helvetica Condensed Black" FontStyleNameNative="$ID/Black Condensed" PlatformName="$ID/" Version="001.003" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Black Condensed Oblique" FontFamily="Helvetica" Name="Helvetica Black Condensed Oblique" PostScriptName="Helvetica-Condensed-BlackObl" Status="Substituted" FontStyleName="Black Condensed Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Condensed Black Oblique" FullNameNative="Helvetica Condensed Black Oblique" FontStyleNameNative="$ID/Black Condensed Oblique" PlatformName="$ID/" Version="001.003" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Light" FontFamily="Helvetica" Name="Helvetica Light" PostScriptName="Helvetica-Light" Status="Substituted" FontStyleName="Light" FontType="Type1" WritingScript="0" FullName="Helvetica Light" FullNameNative="Helvetica Light" FontStyleNameNative="$ID/Light" PlatformName="$ID/" Version="001.002" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Light Oblique" FontFamily="Helvetica" Name="Helvetica Light Oblique" PostScriptName="Helvetica-LightOblique" Status="Substituted" FontStyleName="Light Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Light Oblique" FullNameNative="Helvetica Light Oblique" FontStyleNameNative="$ID/Light Oblique" PlatformName="$ID/" Version="001.002" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Bold Oblique" FontFamily="Helvetica" Name="Helvetica Bold Oblique" PostScriptName="Helvetica-BoldOblique" Status="Substituted" FontStyleName="Bold Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica Bold Oblique" FullNameNative="Helvetica Bold Oblique" FontStyleNameNative="$ID/Bold Oblique" PlatformName="$ID/" Version="003.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Black" FontFamily="Helvetica" Name="Helvetica Black" PostScriptName="Helvetica-Black" Status="Substituted" FontStyleName="Black" FontType="Type1" WritingScript="0" FullName="Helvetica Black" FullNameNative="Helvetica Black" FontStyleNameNative="$ID/Black" PlatformName="$ID/" Version="001.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Black Oblique" FontFamily="Helvetica" Name="Helvetica Black Oblique" PostScriptName="Helvetica-BlackOblique" Status="Substituted" FontStyleName="Black Oblique" FontType="Type1" WritingScript="0" FullName="Helvetica.Black Oblique" FullNameNative="Helvetica.Black Oblique" FontStyleNameNative="$ID/Black Oblique" PlatformName="$ID/" Version="001.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Ultra Compressed" FontFamily="Helvetica" Name="Helvetica Ultra Compressed" PostScriptName="Helvetica-UltraCompressed" Status="Substituted" FontStyleName="Ultra Compressed" FontType="Type1" WritingScript="0" FullName="Helvetica Ultra Compressed" FullNameNative="Helvetica Ultra Compressed" FontStyleNameNative="$ID/Ultra Compressed" PlatformName="$ID/" Version="001.000" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Extra Compressed" FontFamily="Helvetica" Name="Helvetica Extra Compressed" PostScriptName="Helvetica-ExtraCompressed" Status="Substituted" FontStyleName="Extra Compressed" FontType="Type1" WritingScript="0" FullName="Helvetica Extra Compressed" FullNameNative="Helvetica Extra Compressed" FontStyleNameNative="$ID/Extra Compressed" PlatformName="$ID/" Version="001.001" TypekitID="$ID/" />
		<Font Self="difdFontnHelvetica Compressed" FontFamily="Helvetica" Name="Helvetica Compressed" PostScriptName="Helvetica-Compressed" Status="Substituted" FontStyleName="Compressed" FontType="Type1" WritingScript="0" FullName="Helvetica Compressed" FullNameNative="Helvetica Compressed" FontStyleNameNative="$ID/Compressed" PlatformName="$ID/" Version="001.001" TypekitID="$ID/" />
	</FontFamily>

Well, ideally you have access to an IDML file that was made when the font was available and installed for all users.

 

Regards,
Uwe Laubender

( ACP )

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

LATEST

The use case I have is to allow an end user of indesing tool to use an .idd file and my extension will show the user the missing fonts and solve them from a locally managed font source

 

I have tried converting the idd file to idml by exporting the file behind the scene when the doc opens, but I fear this will be very suboptimal in terms of performance. This works though. But I would need to detect the names and format using extendscript

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines