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

Get all the characters of a given typeface?

Engaged ,
Sep 17, 2008 Sep 17, 2008
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
TOPICS
Scripting
2.2K
Translate
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
Participant ,
Sep 17, 2008 Sep 17, 2008
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
Translate
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
People's Champ ,
Sep 17, 2008 Sep 17, 2008
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
Translate
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
Engaged ,
Sep 17, 2008 Sep 17, 2008
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
Translate
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
Participant ,
Sep 18, 2008 Sep 18, 2008
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
Translate
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
Engaged ,
Sep 18, 2008 Sep 18, 2008
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
Translate
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
Participant ,
Sep 18, 2008 Sep 18, 2008
No! I'm describing what the script should do.

Dave
Translate
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
Engaged ,
Sep 18, 2008 Sep 18, 2008
What script?

Klaus
Translate
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
Participant ,
Sep 18, 2008 Sep 18, 2008
The script you I thought you wanted to write.

Dave
Translate
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
Engaged ,
Sep 18, 2008 Sep 18, 2008
Uh, misunderstanding. If everybody on board this forum can write a script of that sort I cant ...

Klaus
Translate
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
People's Champ ,
Sep 18, 2008 Sep 18, 2008
Yes but that's the place to start learning :-)
Loic
Will have a closer look if I can.
Translate
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 ,
Sep 18, 2008 Sep 18, 2008
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')
}
Translate
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
Engaged ,
Sep 18, 2008 Sep 18, 2008
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
Translate
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 ,
Sep 19, 2008 Sep 19, 2008
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
Translate
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 ,
Sep 19, 2008 Sep 19, 2008
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')
}
Translate
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
Engaged ,
Sep 19, 2008 Sep 19, 2008
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
Translate
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 ,
Sep 19, 2008 Sep 19, 2008
LATEST
>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')
}
Translate
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