Skip to main content
Inspiring
July 17, 2012
Answered

Finding Unassigned Glyphs

  • July 17, 2012
  • 6 replies
  • 32544 views

If we import or enter a text code (e.g. a Katakana character )  for which a font has no Glyph, then Indesign will display an x'd rectangle.

Is it possible to find/scan for these with a script?

Thanks !

This topic has been closed for replies.
Correct answer PeteBaumgartner

I did finally manage to script a list of all the unassinged glyphs in my document - with .findGlyph().

This sample just writes to the extendscript toolkit js console.

[CS6]

-------------------------------------------------------------------------------

var myDocument=app.activeDocument;

var allFound = [];

var numFonts = myDocument.fonts.length;

for (var z=0;z<numFonts;z++) {

    allFound = [];

    app.findGlyphPreferences = NothingEnum.nothing;

    app.findGlyphPreferences = NothingEnum.nothing;

    app.findGlyphPreferences.glyphID  = 0;

    app.findGlyphPreferences.appliedFont = myDocument.fonts.name;

    allFound = app.findGlyph ();

    if (allFound.length>0) {

        $.writeln(allFound.length+ ' Unassigned Glyphs in ' + myDocument.fonts.name );

   

        for (var y=0;y<allFound.length;y++) {

             $.writeln( allFound.contents+ '   ' +allFound.contents.charCodeAt(0) );

        }

   }

}

   

$.writeln('--done--');

-------------------------------------------------------------------------------

6 replies

projectsd88043538
Participant
September 25, 2019

I modified your sceript to make it work in CC2019

 


var myDocument=app.activeDocument;

$.writeln('--Looking for missing fonts in ' + myDocument.name + '--');

var allFound = [];

var numFonts = myDocument.fonts.length;

for (var z=0;z<numFonts;z++) {

allFound = [];
app.findGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences = NothingEnum.nothing;
app.findGlyphPreferences.glyphID = 0;
app.findGlyphPreferences.appliedFont = myDocument.fonts[z].name;
allFound = app.findGlyph ();

if (allFound.length>0) {
$.writeln(allFound.length+ ' Unassigned Glyphs in ' + myDocument.fonts[z].name );

for (var y=0;y<allFound.length;y++) {
$.writeln(allFound[y].contents+ ' ( ' +allFound[y].contents.charCodeAt(0)+')' );
}
}
}


$.writeln('--done--');

Jongware
Community Expert
Community Expert
July 17, 2012

For CS4 (and hopefully newer): create a preflight profile that checks just the bad'uns, then flesh out the relevant details. The scripting engineers went a little bit crazy on making this scriptable, it seems.

(This code only returns the results after 2 minutes, and it only shows them. So please none of that "plz can u send ur complete script" crap if you plz.)

if (!app.preflightProfiles.item("Check glyphs only").isValid)

{

          glyphsOnlyProfile = app.preflightProfiles[0].duplicate();

          glyphsOnlyProfile.name = "Check glyphs only";

          for (i=0; i<glyphsOnlyProfile.preflightProfileRules.length; i++)

                    glyphsOnlyProfile.preflightProfileRules.flag = PreflightRuleFlag.RULE_IS_DISABLED;

          glyphsOnlyProfile.preflightProfileRules.itemByName("ADBE_MissingGlyph").flag = PreflightRuleFlag.RETURN_AS_ERROR;

}

glyphsOnlyProfile = app.preflightProfiles.itemByName("Check glyphs only");

activeProcess = app.preflightProcesses.add (app.activeDocument, glyphsOnlyProfile);

activeProcess.waitForProcess(120);

result = {};

for (i=2; i<activeProcess.aggregatedResults[2].length; i++)

          if (result[activeProcess.aggregatedResults[2][1]])

                    result[activeProcess.aggregatedResults[2][1]]++;

          else

                    result[activeProcess.aggregatedResults[2][1]] = 1;

alert (result.toSource());

Jongware
Community Expert
Community Expert
July 17, 2012

Gosh -- trying it on a hundred pages of text where I replaced all of the body font with Symbol made ID crash

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0   ???                                     0xac8f4630 _XHNDL_trapback_instruction + 0

1   com.adobe.InDesign.Package and Preflight          0x0fd477ec GetPlugIn + 554380

Oh well, better use it "within reasonable limites" then.

PeteBaumgartnerAuthorCorrect answer
Inspiring
July 19, 2012

I did finally manage to script a list of all the unassinged glyphs in my document - with .findGlyph().

This sample just writes to the extendscript toolkit js console.

[CS6]

-------------------------------------------------------------------------------

var myDocument=app.activeDocument;

var allFound = [];

var numFonts = myDocument.fonts.length;

for (var z=0;z<numFonts;z++) {

    allFound = [];

    app.findGlyphPreferences = NothingEnum.nothing;

    app.findGlyphPreferences = NothingEnum.nothing;

    app.findGlyphPreferences.glyphID  = 0;

    app.findGlyphPreferences.appliedFont = myDocument.fonts.name;

    allFound = app.findGlyph ();

    if (allFound.length>0) {

        $.writeln(allFound.length+ ' Unassigned Glyphs in ' + myDocument.fonts.name );

   

        for (var y=0;y<allFound.length;y++) {

             $.writeln( allFound.contents+ '   ' +allFound.contents.charCodeAt(0) );

        }

   }

}

   

$.writeln('--done--');

-------------------------------------------------------------------------------

Peter Kahrel
Community Expert
Community Expert
July 17, 2012

Everybody please head to the feature request page: http://www.adobe.com/support/feature.html

I've been asking for script support for this for years, but my feeble voice hasn't had much success.

The more requests, the bigger the chance we get the feature.

Peter

Inspiring
July 17, 2012

All;

Thanks for the ideas. I will continue to tinker.

I did add an entry to the Feature requests.

pjb

Community Expert
July 17, 2012

@Pete – just a thought:

if we are looking for all none-white space characters and try to convert  character by character to outlines, and this convertion will fail, would that be the proof that we found a unassigned glyph?

Here an example. Characters that cannot converted to outlines will be formatted with the character style "NotDefinedGlyph", that you have to prepare before running this snippet:

//Very slow. Don't try this on large stories:

var d=app.documents[0];

var sChars=d.stories[0].texts[0].characters;

var sCharsLength = sChars.length;

//Not foolproof!

//False positives with ligatures like "fi" or "ffi":

for(var n=0;n<sCharsLength;n++){

   

    //Do not create outlines on white space characters:

    if(sChars.contents.match(/\S/)){

        try{

            var myOutlineArray = sChars.createOutlines(false);

            try{

            myOutlineArray[0].remove();

                }catch(e){};

            }catch(e){

                //Let's mark it with a character style in case it cannot be converted to outlines:

                sChars.appliedCharacterStyle = "NotDefinedGlyph";

                $.writeln(sChars.contents);

                };

        };

   

    };

Downside: this code would run very, very slow…
And: it's NOT foolproof. There are false positives with ligatures like "fi" or "ffi" etc.pp.

Uwe

Inspiring
July 17, 2012

Depending on what you're trying to do—i.e., is a simple pass/fail enough, or do you need to programmatically do something to each missing glyph—the preflight might work.

Jeff

Trevor:
Legend
July 17, 2012