Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Detecting Missing Fonts (jsx ai-cs4)

Community Beginner ,
May 03, 2011 May 03, 2011

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.

TOPICS
Scripting
2.4K
Translate
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 Expert ,
May 03, 2011 May 03, 2011

What happens if you temporarily create a new document and get your actual system fonts from that?

Translate
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 ,
May 03, 2011 May 03, 2011

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!

Translate
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 ,
May 03, 2011 May 03, 2011

Noah, what file types are you dealing with…?

Translate
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 ,
May 03, 2011 May 03, 2011

Only EPS and AI.

Translate
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 ,
May 03, 2011 May 03, 2011

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…

Translate
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 ,
May 03, 2011 May 03, 2011

1. Why do you avoid EPS's?

2. Is what you're talking about a function of textFrame?  If not, why not!?

3. Thanks!

Translate
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 ,
May 03, 2011 May 03, 2011

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…

Translate
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 ,
May 03, 2011 May 03, 2011
LATEST

Well, I value your O, so thanks!  Dealing with EPS's is unavoidable for me, but I dig what you're saying.

Translate
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