Font

Missing Font Replacement by Marc

See also Find/change missing font by Marijan Tompa

Document.prototype.changeMissingFontsBy = function(/*str|Font*/fontOrFontName)
{
var asFont = function(/*var*/f)
     {
     if (!f) return null;
     if (typeof f == 'string') f = app.fonts.item(f);
     if (f.constructor != Font) return null;
     return(f);
     };
 
var missing = function(/*Font*/f)
     {return ( f.status != FontStatus.INSTALLED );}     
     
var substFont = asFont(fontOrFontName);
if ((!substFont) || missing(substFont))
     {
     alert( "["+ fontOrFontName + "] is not installed!" );
     return;
     }
 
var changeMissingFont = function(obj)
     { //  : any object with appliedFont prop
     var f = asFont(obj.appliedFont);
     if ((!f) || (!missing(f))) return;
 
     try{obj.appliedFont = substFont;}
     catch(ex){}
     };
     
var scope = this.allCharacterStyles
     .concat(this.allParagraphStyles)
     .concat(this.stories.everyItem().textStyleRanges.everyItem().getElements());
 
var s;
while ( s=scope.shift() ) changeMissingFont(s);
}
 
// test
app.activeDocument.changeMissingFontsBy("Times New Roman");