Not available in the script fonts

I wrote the following script to generate an index of fonts in an InDesign document:

Generate new document

var doc = app.documents.add ();

frm var = doc.pages [0].textFrames.add ();

var l = doc.documentPreferences.pageWidth;

var h = doc.documentPreferences.pageHeight;

frm.geometricBounds = [0.5, 0.5, 10.5, 8];

Get a list of all the fonts installed and divided into tables of type and font family name

var appFonts = app.fonts.everyItem () .name;

var installedFonts = [];

var installedStyles = [];

var counter = - 1;

for (var i = 0; i < appFonts.length; i ++) {}

appFonts [i] is appFonts [i] .split ("\t");.

{If (i == 0 | appFonts [i] [0]! = {appFonts [i - 1] [0])}

installedFonts.push (appFonts [i] [0]);

counter ++;

installedStyles [counter] = [];

}

installedStyles [counter] .push (appFonts [i] [1]);

}

Loop through all families of fonts and styles

var thisFont = "";

var thisStyle = "";

for (var i = 0; i < installedFonts.length; i ++) {}

thisFont = installedFonts [i];

for (var j = 0; j < installedStyles [i] .length; j ++) {}

thisStyle = installedStyles [i] [j];

FRM.contents += thisFont + '-' + thisStyle + "\r";

with (frm.paragraphs.item(-1)) {}

try {}

appliedFont = thisFont;

try {}

fontStyle = thisStyle;

}

{} catch (errorVariable)

appliedFont = "Times New Roman";

fontStyle = "Regular";

}

}

{} catch (errorVariable)

appliedFont = "Times New Roman";

fontStyle = "Regular";

}

pointSize = 12;

Justification = Justification.leftAlign;

}

}

}

I've added the try/catch statements, because for some fonts script has been abandoned in the statement:

appliedFont = thisFont;

because he said that the police was not available. Why can't apply that font to text if app.fonts.everyItem () .name on the list?

Try to set both the font and style in a single command:

appliedFont = "Roman\tRegular" again

The "appliedFont" command may fail if the original font in this style was something not available for TNR, such as 'refine '. This should fix.

Tags: InDesign

Similar Questions

Maybe you are looking for