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

To list all the glyphs and their counts used in a document from a specific font

Explorer ,
Sep 15, 2024 Sep 15, 2024

Copy link to clipboard

Copied

I am trying to make a script to list all the glyphs by their names or IDs and their counts in a document. The glyphs should be listed by their names or IDs (not by Unicode) as each Unicode character has several alternate shapes and I want to get result for each and every alternate shape. I have tried but in vain. Here is my script that I am working on.

 

// Get the active document
var doc = app.activeDocument;

// Define an object to store the glyph name counts
var glyphCounts = {};

// Define the output file path
var outputFile = File("~/Desktop/GlyphCount.txt");
outputFile.open("w");

// Write the initial line to the file
outputFile.writeln("Glyph Counts for the font: Arabic Font 1");

// Function to process characters and count glyphs
function countGlyphs(character) {
    try {
        // Check if the character has glyphs
        if (character.hasOwnProperty('glyphs') && character.glyphs.length > 0) {
            var glyph = character.glyphs[0]; // Get the first glyph object
            var glyphName = glyph.glyphName; // Get the glyph name
            
            // Use a placeholder if glyphName is undefined
            if (!glyphName) {
                glyphName = "UnknownGlyph";
            }

            // Update the glyph count based on the glyph name
            if (glyphCounts[glyphName] === undefined) {
                glyphCounts[glyphName] = 1;
            } else {
                glyphCounts[glyphName]++;
            }

            // Debug output using alerts
            alert("Glyph: " + glyphName + ", Count: " + glyphCounts[glyphName]);
        } else {
            alert("No glyphs found for character.");
        }
    } catch (e) {
        // Log errors if glyph retrieval fails
        alert("Error processing character. Error: " + e.toString());
    }
}

// Loop through all stories (text frames) in the document
for (var i = 0; i < doc.stories.length; i++) {
    var story = doc.stories[i];

    // Loop through all characters in the story
    for (var j = 0; j < story.characters.length; j++) {
        var character = story.characters[j];
        var font = character.appliedFont.name;

        // Check if the character is from the specific font you're interested in
        if (font === "Arabic Font 1") {
            countGlyphs(character);
        }
    }
}

// Write the glyph counts to the file
for (var glyphName in glyphCounts) {
    outputFile.writeln("Glyph: " + glyphName + ", Count: " + glyphCounts[glyphName]);
}

// Close the file
outputFile.close();

// Notify the user
alert("Glyph count saved to " + outputFile.fsName);


Any help is greatly appreciated.

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

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 Expert ,
Sep 19, 2024 Sep 19, 2024

Copy link to clipboard

Copied

Where in the world does one learn of "wax"?

 

'wax'is in fact an old typesetting term, see e.g. 

https://purplefusion.wordpress.com/2011/02/04/remembering-a-classic-the-wax-machine/

Votes

Translate

Translate

Report

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 Expert ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

This is a fascinating discussion. I wish I understood more of it.

Votes

Translate

Translate

Report

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 ,
Sep 19, 2024 Sep 19, 2024

Copy link to clipboard

Copied

Please contribute a few questions, then 😉

 

Votes

Translate

Translate

Report

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 Expert ,
Sep 19, 2024 Sep 19, 2024

Copy link to clipboard

Copied

LATEST

I need some classroom time before I'll even know whre to start. 😜

Votes

Translate

Translate

Report

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 ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Sep 19, 2024 Sep 19, 2024

Copy link to clipboard

Copied

Interesting - DeliverGlyphs also uses find/change glyph, as I suggested earlier on, same as the old idea of Dave Saunders that Joel found.

 

This may not work though with fonts that substitute a single character with multiple glyphs - such as ligature decomposition as mentioned in the OpenType specification. I don't have a concrete example at hand to try.

https://learn.microsoft.com/en-us/typography/opentype/otspec181/gsub

Same with contextual substitution, where entire glyph sequences are exchanged for others. You must inspect the output of the font program defining those substitutions to know the final output, and even then there won't be an exact single character to change.

Votes

Translate

Translate

Report

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
Explorer ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 Expert ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

@zuhair777

 

Why your link is no linger valid?

 

Votes

Translate

Translate

Report

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
Explorer ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

 

Dirk Becker, from your post it appears that you are on Mac but I am on Windows. Does your Plugin work on Windows? If you could add another function to it, to find the occurences of these glyphs in the document e.g. uni064C has 7 occurences in the document, we should be able to search for these occurences in the document then it would be of great help.

Votes

Translate

Translate

Report

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
Explorer ,
Sep 16, 2024 Sep 16, 2024

Copy link to clipboard

Copied

I have sent you a new link

Votes

Translate

Translate

Report

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