[Tkinter-discuss] Canvas.postscript() fails to render some fonts properly

Michael Lange klappnase at web.de
Fri Aug 27 19:33:00 CEST 2010

Hello all,

I did now some further investigation on this topic and I thought I
might share what I found here, for the archives :)

It seems that in fact the problem is the name of the postscript font
created by Tk. Tk itself treats all font names case insensitive, so
"cOMiC SanS mS" is equivalent with "comic sans ms". Postscript however
appears to be quite fastidious about the spelling of a font name. Even
worse, it looks like the requested spelling of a font can differ from one
postscript interpreter to another.
Tk itself creates postscript font names always the same way: the first
letter capitalized, the rest lower case, as in "Courier". If the name
contains white space, each "word" is capitalized and the white space
removed, so e.g. "comic sans ms" becomes "ComicSansMs". This behavior is
hard coded in tkFont.c . In my example the postscript interpreter insists
on "ComicSansMS" though and therefore fails to print the font correctly.
This is where the fontmap option comes in, passing the exact postscript
font name to the fontmap like:

   set fontMap($fonty) {"ComicSansMS" 16}
   .c postscript -file "~/test.ps" -fontmap fontMap

the "comic" font works as expected.
However the bad thing is that this does not mean that it will work on any
system, e.g. the same postscript file that works on my debian linux system
did *not* work on my windows2000 box with a newly installed ghostscript
(latest version).
However if it is for personal use only, it seems to be better to directly
add entries to the postscript fontmap (on unix systems usually
/usr/share/ghostscript/<version>/lib/Fontmap )
In my example this entry simply looks like:

/ComicSansMs			/ComicSansMS	;

or, probably better, add custom entries like this to a file MyFontmap in
the same folder and add a line

(MyFontmap) .runlibfile

to Fontmap, so the private entries won't be lost after an update.


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

	"Beauty is transitory."
	"Beauty survives."
		-- Spock and Kirk, "That Which Survives", stardate unknown

More information about the Tkinter-discuss mailing list