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

Firat Ozgul ozgulfirat at gmail.com
Tue Aug 24 21:49:28 CEST 2010


In Tk documentation, it reads:

"(...) Tk attempts to guess what Postscript font to use. Tk's guesses
generally only work for well-known fonts such as Times and Helvetica and
Courier (...)"

source: http://www.tcl.tk/man/tcl8.4/TkCmd/canvas.htm (see "-fontmap"
section)

So if you would like to be on the safe side, you are only limited to Times,
Helvetica and Courier...

In GNU/Linux, as you know, fonts are generally in /usr/share/fonts.
Therefore you can take this path as the base for your application's font
folder.

Also I believe that distributing your own fonts is not a bad idea. If I were
you, I would just collect all the fonts I need into a folder, and distribute
that folder with my application. This way, I would always know where and
what the fonts are... For instance, suppose that you collected all your .tff
files in a folder named "freefont", and you know that there is a .tff file
named "FreeSansOblique.ttf" in that folder:

http://paste-it.net/public/ke2fa61/

There are some interesting websites giving away free fonts over the net. For
example:

http://www.webpagepublicity.com/free-fonts.html

I tested some of these fonts in my code (under Ubuntu), and they all work.

Good Luck!
Firat



2010/8/24 Michael Lange <klappnase at web.de>

> Hello,
>
> Thus spoketh Firat Ozgul <ozgulfirat at gmail.com>
> unto us on Tue, 24 Aug 2010 16:54:30 +0300:
>
> > Hello,
> >
> > It looks like that postscript() function cannot render every font with
> > no obvious reason. "Renderable" fonts are rendered correctly regardless
> > of whether they contain spaces or not...
>
> I guess you are right, and using the fontmap option does not seem to make
> any difference; when I use e.g. times in the canvas and override it
> through the fontmap with verdana, I get verdana in the postscript. If I
> use e.g. "clean" instead of verdana I get something that looks like
> courier. So it looks like the good news is that I don't need to bother
> trying to get the fontmap working when the font name contains white
> space :)
>
> > However it seems that,
> > alternatively, we can achieve what we want through the Image, ImageDraw
> > and ImageFont modules. All we need to know is the name of the .ttf file
> > to which the font name corresponds.
> >
> > Here is the code: http://paste-it.net/public/t66c5c0/
>
> Nice, i did not know that this is possible, but unfortunately this is no
> option for me. I want that my app can be run on any linux machine, so I
> would have to ship my own fonts to know where exactly the files are.
>
> I wonder if there is some way to determine from within Tkinter which
> fonts can't be used with postscript; if yes I could simply remove these
> from the menu where the font can be selected, I could live very well with
> that. What's bad is that the font that is printed is not the one the user
> sees on the screen.
>
> Regards
>
> Michael
>
>
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.
>
> There's a way out of any cage.
>                -- Captain Christopher Pike, "The Menagerie" ("The Cage"),
>                   stardate unknown.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20100824/aeb43a5b/attachment-0001.html>


More information about the Tkinter-discuss mailing list