7 Replies Latest reply on Mar 27, 2008 6:02 AM by Martin Fischer

    Fetching all available characters of a font

    Martin Fischer Level 2
      I would like to build a genaral view of the available characters of a font.
      Does anybody have an idea how to fetch them?

      How can I iterate though unicode values?

      And how can I check, whether a character with a specific unicode value is presentable with the applied font?

      Thanks in advance
      Martin Fischer
        • 1. Re: Fetching all available characters of a font
          Level 1
          I think it's impossible to check if there is "real" character under specified unicode ... but maybe I'm wrong ;)

          but ... maybe if you will create outline of each char and check if is empty (error when creating outline) or it is crossed or not rectangle ...

          robin

          --
          www.adobescripts.com
          • 2. Re: Fetching all available characters of a font
            Martin Fischer Level 2
            Hi Robin,

            > maybe if you will create outline of each char and check if is empty

            Ah, good idea.

            Thank you
            Martin
            • 3. Re: Fetching all available characters of a font
              srakete Level 1
              Martin,

              my first thought was the InDiCode Script:

              http://www.adobeforums.com/webx/.3bc441ad

              Maybe this will help

              Stefan
              • 4. Re: Fetching all available characters of a font
                Martin Fischer Level 2
                Stefan,

                what a wonderful stuff!

                Thank you for pointing me to this link.
                I should have remembered it.

                Martin
                • 5. Re: Fetching all available characters of a font
                  Peter Kahrel Adobe Community Professional & MVP
                  Martin,

                  You can cycle through Unicode ranges using their hexadecimal numbers:

                  for (i = 0x0100; i < 0x017F; i++)
                  $.writeln (String.fromCharCode(i));

                  writes the characters in Latin Extended A to ESTK's console.

                  Peter
                  • 6. Re: Fetching all available characters of a font
                    Martin Fischer Level 2
                    Peter,

                    good to know this.
                    (I didn't yet).

                    Thank you
                    Martin
                    • 7. Re: Fetching all available characters of a font
                      Martin Fischer Level 2
                      Maybe somebody is interested in another approach catching all available glyphs of a font.

                      We had a discussion in http://www.hilfdirselbst.ch/gforum/gforum.cgi?post=343195#343195
                      Bastian has told that not every glyph has a unicode value. So you have to choose another way to get every glyph of a font.

                      Only findGlyphPreference and changeGlyphPreference do have a property glyphID. So we have been looking for a way to get the glyphs over this preferences.

                      Here is a workaround to catch the glyphs:


                      var t = app.activeDocument.pages[0].textFrames.add({geometricBounds:[0,0,210,148] });
                      var myFont = 'Garamond Premier Pro\tItalic'; // 'Times New Roman\tRegular'; 'Minion Pro\tRegular'
                      var glyphCounter = 2555;
                      var s = t.parentStory;
                      var c = fillStory( s, glyphCounter );
                      app.findGlyphPreferences = app.changeGlyphPreferences = NothingEnum.nothing;
                      app.findGlyphPreferences.glyphID = 1; // glyphID of space
                      app.findGlyphPreferences.appliedFont = app.changeGlyphPreferences.appliedFont = myFont;

                      for ( i = 1; i < c.length; i++ )
                      {
                      app.changeGlyphPreferences.glyphID = i ;
                      try { c[i].changeGlyph(); }
                      catch(e) { errorExit( 'Stopped with glyph no. ' + i )}
                      }

                      function errorExit( aMessage )
                      {
                        alert( aMessage );
                        exit();
                      }

                      function fillStory( aStory, aCounter )
                      {
                      aStory.contents = '';
                      for ( i = 0; i < aCounter; i++ )
                        aStory.insertionPoints[-1].contents = ' ';
                      aStory.texts[0].appliedFont = myFont;
                      return aStory.characters;
                      }


                      We have used the space as placeholder.
                      In some fonts the glyphID of the space is 1 in some other the glyphID is 2 and e.g. in Times New Roman the glyphID is 3.
                      Until now I did't find a way how to read out the glyphID of the space of one font. So you should adjust 'app.findGlyphPreferences.glyphID = 1;' in the script above.

                      I also could't find out how to get the length of glyphs of a font.
                      So you should adjust 'var glyphCounter' in the script above, too.

                      In UI one can insert a glyphID in the search-field with its unicode-value or with its GID/CID. You can switch the units.
                      I couldn't find out how to insert the value als unicode-value.
                      I would like to set the value for the search-glyphID for space in font-independent unicode-format '\u0020'.

                      Thanks
                      Martin