16 Replies Latest reply on Sep 19, 2008 5:55 AM by Peter Kahrel

    Get all the characters of a given typeface?

    Klаus Level 1
      Hi there!

      I wonder if theres a way via script to fill a text frame with all the characters of a given typeface besides the boring one of typing them all in?

      Thanks
      Klaus
        • 1. Re: Get all the characters of a given typeface?
          Level 1
          The problem is knowing which is (or isn't) a glyph. You can use convert to outlines to find out -- if a glyph won't convert to outlines, it has no outlines and so doesn't exist (or maybe it's an esoteric space character that wouldn't show up anyway).

          Dave
          • 2. Re: Get all the characters of a given typeface?
            Loic.Aigon Adobe Community Professional
            You can use Indesign UI features such as Libraries.
            As a graphic designer, I used to create once a textframe with all the alphabets, signs & numbers. Put them in alibrary then drop it in my doc when needed. So at the end, I just had to switch to the typeface.
            But now I just open the glyph palette. I find it's much more quicker.
            Loic
            • 3. Re: Get all the characters of a given typeface?
              Klаus Level 1
              Thanks for the input.

              Id guess I have to outline my issue a bit clearer ... Want I have in mind is sort of a listing of all characters of a given typeface, like

              !"#$%&' and so on,
              but also things like
              รฤศ
              or
              ʣʤʥ

              ... therefore including all the present characters of that given typeface.

              Even better would be a listing like this:

              Unicode 0021:!
              Unicode 0022:"
              Unicode 0023:#
              .
              .
              .

              Any chance to achieve this with the help of a script?

              Klaus
              • 4. Re: Get all the characters of a given typeface?
                Level 1
                Yes. You would have to do what I said in my earlier message. Cycle through the complete unicode range (that will take some time, of course) and check each glyph to see if it can be converted to outlines. If so, then it exists, so make the entry; if not, it doesn't so move on to the next value.

                Dave
                • 5. Re: Get all the characters of a given typeface?
                  Klаus Level 1
                  Dave suggests:
                  > Cycle through the complete unicode range (that will take some time, of course) and check each glyph to see if it can be converted to outlines.

                  Well, that means to type in each and every character/glyph or to evoke it using the glyph palette, if I understand correctly. There's nothing left to do for any script then ...

                  Klaus
                  • 6. Re: Get all the characters of a given typeface?
                    Level 1
                    No! I'm describing what the script should do.

                    Dave
                    • 7. Re: Get all the characters of a given typeface?
                      Klаus Level 1
                      What script?

                      Klaus
                      • 8. Re: Get all the characters of a given typeface?
                        Level 1
                        The script you I thought you wanted to write.

                        Dave
                        • 9. Re: Get all the characters of a given typeface?
                          Klаus Level 1
                          Uh, misunderstanding. If everybody on board this forum can write a script of that sort I cant ...

                          Klaus
                          • 10. Re: Get all the characters of a given typeface?
                            Loic.Aigon Adobe Community Professional
                            Yes but that's the place to start learning :-)
                            Loic
                            Will have a closer look if I can.
                            • 11. Re: Get all the characters of a given typeface?
                              Peter Kahrel Adobe Community Professional & MVP
                              Klaus,

                              Here's a script that lists which characters are available in a font in the range you specify. You indicate a range by replacing the values at "start" and "stop". The ranges in the script -- 0x0020 and 0x2BFF -- cover the characters from the space character up to the last character in the Math & Arrows range. This includes standard ASCII, Latin Extended A, B, C, D, and Additional, Phonetics, Cyrrillic, Greek, Hebrew -- up to and including Math. Pick what you want, but don't go lower than 0020 or InDesign will lock up.

                              To run the script, start an ID document and draw a text frame. Assign to that text frame the font whose characters you want to display. Make sure that the text frame is selected and run the script. When the script is finished you'll need to adjust the text frame (size, number of columns) to see all results.

                              The script could take several minutes to run depending on your hardware. If you decide to run the script against a long range (e.g. 0020-FFFF), you'd better go out for lunch. One of the reasons why the script takes its time is that in order to determine whether a glyph exists in a font, it actually inserts that character in the ID document and tries to make an outline. That takes time. (For the record, the "createOutline" trick was found independently by Teus de Jong and Dave Saunders.)

                              #target indesign
                              

                              //--------------------------------------------------------

                              start = 0x0020;
                              stop = 0x2BFF;

                              //--------------------------------------------------------

                              if (app.selection.length == 0 || app.selection[0].constructor.name != 'TextFrame')
                                 exit();

                              test_frame = app.selection[0];
                              in_font = [];

                              for (i = start; i <= stop; i++)
                                 if (char_in_font (test_frame, String.fromCharCode (i)))
                                    in_font.push (pad (i) + ': ' + String.fromCharCode (i));

                              if (in_font.length > 0)
                                 test_frame.contents = in_font.join ('\r');

                              function char_in_font (tf, ch)
                                 {
                                 try
                                    {
                                    // insert the character
                                    tf.contents = ch;
                                    // create outline
                                    tf.characters[0].createOutlines();
                                    // if we got here it worked: delete the outline and return 'true'
                                    tf.characters[0].remove();
                                    return true
                                    }
                                 catch(_)
                                    {
                                    // couldn't create outline: delete it, return 'false'
                                    tf.characters[0].remove();
                                    return false
                                    }
                                 }

                              // Pad hex numbers to a 4-place string
                              function pad (n)
                                 {
                                 n = '000' + n.toString(16).toUpperCase();
                                 return n.replace (/.+(....)$/, '$1')
                                 }
                              • 12. Re: Get all the characters of a given typeface?
                                Klаus Level 1
                                Thanks for the script, Peter.

                                Just as to stress my lack of scripting knowledge once again, Im not even sure whether I should generate a .jsx or an .applescript from it ...

                                Tried both, limited the range to

                                start = 0x0020;
                                stop = 0x0022;

                                but it doesnt seem to work.

                                Running the .jsx nothing at all seems to happen, running the .applescript results in a »unknown token« error message.

                                I am using CS3 by the way.

                                Klaus
                                • 13. Re: Get all the characters of a given typeface?
                                  Peter Kahrel Adobe Community Professional & MVP
                                  It's a JavaScript and works in CS3. Save it as a plain text file with the extension .jsx in your script folder (Users/[username]/Library/Preferences/Adobe InDesign/Version 5.0/Scripts).

                                  In InDesign, place an empty text frame in a document and set the font whose characters you want to show. Then select the text frame (make sure that the frame is selected: you should see the frame's edges. If nothing happens you hadn't selected a text frame.

                                  With the text frame selected, open the scrip panel (Window > Automation > Scripts) and double-click the script's name.

                                  The script could have been made a bit more user-friendly, but there you are.

                                  Peter
                                  • 14. Re: Get all the characters of a given typeface?
                                    Peter Kahrel Adobe Community Professional & MVP
                                    Here is a (slightly) friendlier version. Enter values for the typeface, font style, and start and stop values. (The range in this version is just A-Z). If the font is available, the script creates a new document and places a small text frame with all available characters. You still need to resize that frame afterwards.

                                    Peter

                                    //DESCRIPTION: Print a font's available characters
                                    //Peter Kahrel -- www.kahrel.plus.com

                                    #target indesign
                                    

                                    //---------------------------

                                    typeface = 'Minion Pro';
                                    fontstyle = 'Regular';

                                    start = 0x0041;
                                    stop = 0x005A;

                                    //---------------------------

                                    if (app.fonts.item (typeface+'\t'+fontstyle).status == FontStatus.notAvailable)
                                       {
                                       alert (typeface+'-'+fontstyle + " is not available.");
                                       exit()
                                       }

                                    test_frame = app.documents.add ().textFrames.add ({geometricBounds: ["10mm","10mm","30mm","30mm"]});

                                    in_font = [];
                                    for (i = start; i <= stop; i++)
                                       if (char_in_font (test_frame, String.fromCharCode (i)))
                                          in_font.push (pad (i) + ': ' + String.fromCharCode (i));

                                    if (in_font.length > 0)
                                       test_frame.contents = in_font.join ('\r');

                                    function char_in_font (tf, ch)
                                       {
                                       try
                                          {
                                          // insert the character
                                          tf.contents = ch;
                                          // create outline
                                          tf.characters[0].createOutlines();
                                          // if we got here it worked: delete the outline and return 'true'
                                          tf.characters[0].remove();
                                          return true
                                          }
                                       catch(_)
                                          {
                                          // couldn't create outline: delete it, return 'false'
                                          tf.characters[0].remove();
                                          return false
                                          }
                                       }

                                    // Pad hex numbers to a 4-place string
                                    function pad (n)
                                       {
                                       n = '000' + n.toString(16).toUpperCase();
                                       return n.replace (/.+(....)$/, '$1')
                                       }
                                    • 15. Re: Get all the characters of a given typeface?
                                      Klаus Level 1
                                      Peter wrote:
                                      > Then select the text frame (make sure that the frame is selected: you should see the frame's edges.

                                      Uh OK, my fault: I had the text frame selected with the type cursor activated inside.

                                      I did a run for the range 0020 to FFFF, and after 30 minutes or so I got a error message saying:

                                      JavaScript Error!

                                      Error number: 45
                                      Error string: Object is unvalid
                                      Line: 38
                                      Source: tf.characters[0].remove();


                                      (Translated from German)

                                      The text frame remained empty.

                                      Other runs with smaller ranges were successful, though.

                                      To get all the characters of a given typeface, what stop value should be appropriate? FFFF, to be totally sure?

                                      Thanks
                                      Klaus
                                      • 16. Re: Get all the characters of a given typeface?
                                        Peter Kahrel Adobe Community Professional & MVP
                                        >I got a error message saying:

                                        Ah, yes, I should have checked for errors. The version below does that.

                                        >To get all the characters of a given typeface, what stop value should be appropriate? FFFF, to be totally sure?

                                        To be totally absolutely sure you have to check the whole Unicode range. But if you know that the font contains characters from certain ranges, check those. See http://www.unicode.org/charts/ for what is in which range.

                                        Peter

                                        //DESCRIPTION: Print a font's available characters
                                        
                                        //Peter Kahrel -- www.kahrel.plus.com

                                        #target indesign

                                        //---------------------------

                                        typeface = 'Minion Pro';
                                        fontstyle = 'Regular';

                                        start = 0x0041;
                                        stop = 0x005A;

                                        //---------------------------

                                        if (app.fonts.item (typeface+'\t'+fontstyle).status == FontStatus.notAvailable)
                                           {
                                           alert (typeface+'-'+fontstyle + " is not available.");
                                           exit()
                                           }

                                        test_frame = app.documents.add ().textFrames.add ({geometricBounds: ["10mm","10mm","30mm","30mm"]});

                                        in_font = [];
                                        for (i = start; i <= stop; i++)
                                           {
                                           try
                                              {
                                              if (char_in_font (test_frame, String.fromCharCode (i)))
                                                 in_font.push (pad (i) + ': ' + String.fromCharCode (i));
                                              }
                                           catch (_){}
                                           }

                                        if (in_font.length > 0)
                                           test_frame.contents = in_font.join ('\r');

                                        function char_in_font (tf, ch)
                                           {
                                           try
                                              {
                                              // insert the character
                                              tf.contents = ch;
                                              // create outline
                                              tf.characters[0].createOutlines();
                                              // if we got here it worked: delete the outline and return 'true'
                                              tf.characters[0].remove();
                                              return true
                                              }
                                           catch(_)
                                              {
                                              // couldn't create outline: delete it, return 'false'
                                              tf.characters[0].remove();
                                              return false
                                              }
                                           }

                                        // Pad hex numbers to a 4-place string
                                        function pad (n)
                                           {
                                           n = '000' + n.toString(16).toUpperCase();
                                           return n.replace (/.+(....)$/, '$1')
                                           }