Ghostscript - determine the final substituted font at runtime

1.5k views Asked by At

I have a file which is attempting to find which font is available to re-encode it for some internal reason (I have no idea why yet, it's just another roll-your-own PS file).

It does this with some logic like:

/Arial 
dup /Font resourcestatus{ pop pop }{ pop /ArialMT }ifelse
dup /Font resourcestatus{ pop pop }{ pop /Helvetica }ifelse 

The intent is that the best available font key is on the stack at the end.

In Ghostscript on Windows this appears to be /Arial (as resourcestatus returns 2). However attempting to find the font results in the common warnings:

Can't find (or can't open) font file %rom%Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Can't find (or can't open) font file %rom%Resource/Font/ArialMT.
Can't find (or can't open) font file ArialMT.
Querying operating system for font files...
Didn't find this font on the system!
Substituting font Helvetica for ArialMT.

Is it possible to determine the final /Helvetica font key in this situation, before we attempt to use it?

It matters since the substitution process is causing some errors where other embedded fonts go missing. There's surely a bug somewhere causing this but I'm still investigating, and curious anyway.

1

There are 1 answers

5
KenS On BEST ANSWER

The answer is 'not really'. The font substitution mechanism in Ghostscript is quite complex and involves some heuristics based on the font characteristics. It also dependsw on how you have configured Ghostscript and the fonts installed.

In your specific case you will probably find that there is a definition in fontmap.GS for Arial. In fact the default fontmap.GS includes this:

/Arial /ArialMT ;

However, unless you installed on a Windows system (and used the GS installer to set FontPath) it won't have actually installed a reference for ArialMT. So, since ArialMT isn't defined, it reverts to the 'if all else fails' font, which is Helvetica. Pretty much what you see on the back channel above.

Your best bet for avoiding font substitution problems is to carefully configure fontmap.GS, the version shipped with the Ghostscript sources is an example, its not intended to be used 'as is' on every system.