4 Replies Latest reply on Jan 3, 2014 2:58 PM by [Jongware]

    How to get glyph ID using JS?

    Gejaraja Level 1

      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

        • 1. Re: How to get glyph ID using JS?
          Gejaraja Level 1

          Anyone please respond to this requirement?

          • 2. Re: How to get glyph ID using JS?
            Peter Kahrel Adobe Community Professional & MVP

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

             

            Peter

            • 3. Re: How to get glyph ID using JS?
              Dave Saunders Level 4

              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

              • 4. Re: How to get glyph ID using JS?
                [Jongware] Most Valuable Participant

                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.)