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.
Copy link to clipboard
Copied
This is a fascinating discussion. I wish I understood more of it.
Copy link to clipboard
Copied
DeliverGlyphs from Jean loup Fusz (FR) might help:
Best,
Marc
Copy link to clipboard
Copied
Challenge added to Acrobat Forum Script Challenge - List all the glyphs & their counts used in a document by glyph names of the font
Copy link to clipboard
Copied