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

How to get glyph ID using JS?

Community Beginner ,
Dec 31, 2013 Dec 31, 2013

Copy link to clipboard

Copied

Hello,

Please let me have the details to get the glyph ID using JS like some of the special characters used in the InDesign file doen't have the unicode value and InDesign is replacing them as � while exporting as HTML file. So to differentiate these symbols, we'd like to replace those characters with glyph ID which are having different IDs like 1602, 1604, etc.

Thanks,

Praveen

TOPICS
Scripting

Views

2.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 Beginner ,
Jan 02, 2014 Jan 02, 2014

Copy link to clipboard

Copied

Anyone please respond to this requirement?

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 ,
Jan 02, 2014 Jan 02, 2014

Copy link to clipboard

Copied

You can find the decimal and hexadecimal values of a glyph. I don't think you can get the glyph's ID though.

Peter

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
Advocate ,
Jan 02, 2014 Jan 02, 2014

Copy link to clipboard

Copied

I'm with Peter, I don't believe you can find out the GID of a character with a script (except by doing it the hard way, which I'll explain after I show you a script I just wrote). But if you are interested in changing characters with particular GIDs, then you can indeed do it along these lines:

//DESCRIPTION: Find/Change by Glyph ID Example

(function(){

          if (app.documents.length > 0) {

                    setupFindGlyph(84, 86);

                    app.documents[0].changeGlyph();

          }

          function setupFindGlyph(fmGID, toGID) {

                    // this is a simple demo function; it could do more

                    app.findChangeGlyphOptions = null;

                    app.findGlyphPreferences.appliedFont = "Minion Pro";

                    app.findGlyphPreferences.fontStyle = "Regular";

                    app.findGlyphPreferences.glyphID = fmGID;

                    app.changeGlyphPreferences.appliedFont = "Minion Pro";

                    app.changeGlyphPreferences.fontStyle = "Regular";

                    app.changeGlyphPreferences.glyphID = toGID;

          }

}())

Obviously, to be truly useful, you'd need to pass the font and style into the setup function rather than hard-code them as I've done here. This particular script changes all the "s" characters in Minion Pro Regular to the character "u".

To find the GID of a character of interest, use the Glyphs Panel. The tooltip associated with each character in the panel includes the GID.

Note: if you try to run this script with the FindGlyph panel open, either nothing will happen or InDesign will crash.

So what did I mean by "the hard way"? Well, you could set up a text frame with a character of interest in it and then use a variant of this script to FindGlyph cycling through all legal values until you get a hit. Ugly, but possible.

Dave

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 ,
Jan 03, 2014 Jan 03, 2014

Copy link to clipboard

Copied

LATEST

You are misunderstanding the purpose of a "glyph id". It is the numerical index of a particular glyph in a particular font. It has nothing to do with ID's special characters.

For example, the character 'a' (U+0061) has a Glyph ID of 68 in "Times New Roman", 66 in Minion Pro, and 73 in Baskerville. This tells you nothing you could possibly use for an export to HTML -- if only because the glyph ids may also vary per font version. One of the tables in each font file links Unicode values to their appropriate glyph ids.

What 'characters' do return 'U+FFFD' as their Unicode? In a quick test, I found one: "Page Break" -- but that is because "Page Break" is not in the Unicode tables. (It's also useless to try to convert its function into HTML.)

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