|
From: Donal K. F. <don...@ma...> - 2008-12-14 08:55:29
|
T. Horsnell wrote:
> Hi, I'm new to tcl, so apologies if this is an inappropriate list
> to ask for help.
> I have tcl/tk 8.5.2 on Fedora 9, and hav a curious problem using the
> 'postscript' command on a canvas.
Perhaps the newsgroup comp.lang.tcl would have been more appropriate,
since there are more eyes watching it.
> I have a line like:
> .c create text 200 200 -text "Hello World" -font {FreeSans 50}
> in my tcltk script file, and the text displays with the correct font.
>
> If I dump the cancas window to a file with a line like:
> .c postscript -x 0 -y 0 -height $h -width $w -pagewidth 8.0i \
> -pageheight 11.0i -pagex 4.0i -pagey 5.5i -pageanchor c \
> -file junk2.ps
> The postscript file ends up with a line like
> /Freesans findfont 50 scalefont ISOEncode setfont
>
> The FreeSans from the script has been changed to Freesans in the
> postscript file and Ghostscript cant then find the font.
>
> Short of editing all my (ttf) font files is there a fix for this?
By default, Tk's got a fairly hokey bit of font guessing code for
converting things to postscript; it's necessary to do this because
printers often have much smaller sets of fonts installed (more than just
"Times", "Helvetica" and "Courier", but not much more). As I said, the
code is hokey and is defeated by the way "FreeSans" has a significant
inner capital letter; its default of "title-case each word and
concatenate them" didn't work this time.
But there is a way round.
If you specify the -fontmap option to the postscript subcommand/method,
then you take complete control over how the font is converted since the
option lets you give your own mapping directly (well, as a name to an
array that contains the mapping). Mind you, I've not experimented with
the option a lot myself so some experimentation to get good results
might be needed. Still, at a guess this might work...
set theFont "FreeSans 50"
set mapAry($theFont) $theFont
.c postscript -fontmap mapAry ...all the other options
Of course, it should also be possible to use traces on the array to get
things working even better. Note also that postscript font names don't
have spaces in (since they're PS symbols).
More details, such as they are, are at:
http://www.tcl.tk/man/tcl8.5/TkCmd/canvas.htm#M63
The Tcler's wiki is currently very sparse on this topic. I'll add a bit
more, but you're encouraged to contribute as well.
http://wiki.tcl.tk/
As an aside for tinkering with this stuff, I found the following useful
for shortening the interactive try-a-change-and-test cycle...
less <<[.c postscript -fontmap mapAry]
Donal.
|