Hi all,
I've been working on a script to try and build a list of font's that not loaded in Illustrator. I know that Illustrator will alert missing fonts when a document is opened but this routine will be part of a larger script that will have the user dialogs turned off. My process is to build a list of fonts that are available to the the application, then build a list of fonts that are used within the active document and cross reference them to see if there are document fonts that are not in the application fonts list.
I have used a great function that I believe was posted originally by Moluapple and with some some brilliant advice from the always helpful CarlosCanto I thought that I had found the soultion but it appears to have some limitations. If I get a list of fonts available to the application and the document that I want to cross reference them against is open, the list that's returned contains fonts that are used in the document. Then when I get a list of fonts used in the document and cross reference them they will all be in the application list regardless of whether they're loaded or not.
The only way that I can get accurate results are if I run the script without any documents open and build a list of application fonts, then open a document and build a list of document fonts and then cross reference. This is the only way I can find out what fonts aren't loaded.
Does anybody know of another way to build a list of missing fonts without having to close documents first? I have searched through the XMP data and this doesn't seem to give me any clues and I've tried writing the code in applescript but it appears to work in the same way. Any help or comments would be welcome.
Here's my code:
#target illustrator
var doclist = app.textFonts
var appFontList = new Array ();
for (i=0;i< app.textFonts.length; i++){
var fontName = app.textFonts[i].name;
appFontList[i] = fontName;
}
var myfile = File.openDialog ('Choose a file');
app.open (myfile);
var docFontsList = getUsedFonts(activeDocument);
// function accredited to Moluapple
function getUsedFonts (doc ){
var xmlString = new XML(doc.XMPString);
fontsInfo = xmlString.descendants("stFnt:fontName");
var ln = fontsInfo.length(), arr = [];
for (var i = 0; i<ln; i++){arr.push(fontsInfo[i])};
return arr;
}
var missingFontsList = checkFonts();
alert(missingFontsList);
function checkFonts(){
var fontArray = new Array ();
for (i=0; i < docFontsList.length; i++){
var thisDocFont = docFontsList[i];
var activeFont = false;
for (j = 0; j < appFontList.length; j++){
var thisAppFont = appFontList[j];
if (thisDocFont == thisAppFont){
activeFont = true;
}
}
if (activeFont == false){
fontArray.push (thisDocFont);
}
}
return fontArray;
}
Many Thanks,
Nik