Copy link to clipboard
Copied
I know, it's impossible.
However, I've built the following function and I think it's getting close to working. What I'm trying to do is get a collection of the fonts available to the system and match those against fonts I find in my document. It's getting hung up because my technique for gathering the system fonts is also getting the document-declared fonts.
So my question is, is there a way to specify that I want system fonts only?
Here's what I've got so far:
//================================================
//target illustrator;
var docRef = app.activeDocument;
var missingCount = detectMissingFonts(docRef);
function detectMissingFonts(docRef){
//start counter at the number of fonts being used in the document
var missingcount = docRef.textFrames.length;
alert("FRAMES LENGTH: " + missingcount);
//collect available fonts in a variable
var availableFonts = [];
var fontlist = [];
for(inc=0; inc<textFonts.length; inc++){
var sysFont = textFonts[inc].family;
availableFonts[sysFont] = 1;
fontlist[inc] = sysFont;
}
alert(fontlist);
//collect document fonts
for (k = 0 ; k<docRef.textFrames.length ; k++){ // loop thru textFrames
//set current frame into obj variable
var frame = docRef.textFrames
//set the font family attribute into a variable
var font = frame.textRange.characterAttributes.textFont.family;
//alert("FOUND FONT: " + font + ": " + availableFonts[font]);
//test if found font is in the associative array of available fonts
if ( availableFonts[font] == 1){
alert("Matching " + font + ": " + availableFonts[font]);
//decrement the counter to account for this not-missing font
missingcount--;
}
}
return missingcount;
}
alert("COUNT: " + missingcount);
//================================================
An emergency work-around would be to hard-code in my list of system fonts, but I'd hate for it to come to that. I really appreciate any advice and thanks for reading!!!
p.s. I'm still learning all of this stuff so I'd also be grateful for any advice for making my code more streamline.
p.p.s. Sorry for all of the alerts. I like to be sure every variable I set is working correctly.
Copy link to clipboard
Copied
What happens if you temporarily create a new document and get your actual system fonts from that?
Copy link to clipboard
Copied
Using Jongware's suggestion, here's the updated script that is finding missing fonts:
//===========================================
var availableFonts = getFonts();
var docRef = //OPEN A NEW DOCUMENT NOW;
var missingFonts = detectMissingFonts(docRef, availableFonts);
function getFonts(){
//create blank document
//collect available fonts in a variable
var availableFonts = [];
var fontlist = [];
for(inc=0; inc<textFonts.length; inc++){
var sysFont = textFonts[inc].family;
availableFonts[sysFont] = 1;
fontlist[inc] = sysFont;
}
alert(fontlist);
//close document, return list
return availableFonts;
}
function detectMissingFonts(docRef, availableFonts){
//start counter at the number of fonts being used in the document
var missingcount = docRef.textFrames.length;
alert("FRAMES LENGTH: " + missingcount);
//collect document fonts
for (k = 0 ; k<docRef.textFrames.length ; k++){ // loop thru textFrames
//set current frame into obj variable
var frame = docRef.textFrames
//set the font family attribute into a variable
var font = frame.textRange.characterAttributes.textFont.family;
//test if found font is in the associative array of available fonts
if ( availableFonts[font] == 1){
alert("Matching " + font + ": " + availableFonts[font]);
//decrement the counter to account for this not-missing font
missingcount--;
}
}
return missingcount;
}
alert("COUNT: " + missingcount);
//===========================================
Thanks again, Jongware!
Copy link to clipboard
Copied
Noah, what file types are you dealing with…?
Copy link to clipboard
Copied
Only EPS and AI.
Copy link to clipboard
Copied
Illustrator, lists the missing 'required' fonts in file for EPS's that it created so it is possible to parse these couple of strings out… I can't remember if the same is true for AI… I would have to check… I try to avoid EPS these days when ever possible…
Copy link to clipboard
Copied
1. Why do you avoid EPS's?
2. Is what you're talking about a function of textFrame? If not, why not!?
3. Thanks!
Copy link to clipboard
Copied
There just more problematic to deal with in scripting IMO… Having so many different creators and there content can have allsorts. On the mac I can check creator types but I have no idea how you would do this on the other side… EPS as a file format has fallen by the way side too… It's bloated and flat for a start… Only MO thou…
Copy link to clipboard
Copied
Well, I value your O, so thanks! Dealing with EPS's is unavoidable for me, but I dig what you're saying.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now