Updated 2018-08-18 16:59:10 by trijezdci

trijezdci (2018): I have made a generic font map generator library, which can be viewed at and downloaded from github at:

https://github.com/trijezdci/TclTk-Fontmap/

The font map generator automatically creates entries for the regular, italic, bold and bold-italic styles for each font family requested, whereby it consults a list of known irregular postscript font names that divert from the usual -Italic, -Bold, -BoldItalic naming convention. It also corrects improper case in Tk font names, such as when Tk turns DejaVuSans into DejavuSans or FreeSans into Freesans.

Usage Example:
  import ::fontmap::font_map_for
  ...
  .c postscript -fontmap\
    [font_map_for {{FreeSans 12 14} {FreeSerif 12 14} {FreeMono 10}}] -file sample.ps

This creates a font map as follows:
  font_map(FreeSans 12 bold)                = FreeSansBold 12
  font_map(FreeSans 12 italic)              = FreeSansOblique 12
  font_map(FreeSans 12 {bold italic})       = FreeSansBoldOblique 12
  font_map(FreeSans 12 {})                  = FreeSans 12
  font_map(Freesans 12 bold)                = FreeSansBold 12
  font_map(Freesans 12 italic)              = FreeSansOblique 12
  font_map(Freesans 12 {bold italic})       = FreeSansBoldOblique 12
  font_map(Freesans 12 {})                  = FreeSans 12
  font_map(FreeSans 14 bold)                = FreeSansBold 14
  font_map(FreeSans 14 italic)              = FreeSansOblique 14
  font_map(FreeSans 14 {bold italic})       = FreeSansBoldOblique 14
  font_map(FreeSans 14 {})                  = FreeSans 14
  font_map(Freesans 14 bold)                = FreeSansBold 14
  font_map(Freesans 14 italic)              = FreeSansOblique 14
  font_map(Freesans 14 {bold italic})       = FreeSansBoldOblique 14
  font_map(Freesans 14 {})                  = FreeSans 14
  etc etc

adrian (Dec 2015): here is an example of a fontmap when exporting the canvas content to a postscript. The fontmap is an array with the keys being the font as specified in the -font option of the text canvas items and the array values being the postscript font specifications. You can find the postscript font names in a file called Fontmap.GS on your system.
package require Tk

canvas .c
pack .c -fill both -expand TRUE

set txt "Lorem ipsum dolor sit amet..."

set f1 "*-Helvetica-Medium-R-Normal-*-12-*"
set f2 [font create -family "DejaVu Sans" -size 14]
set f3 TkDefaultFont
set f4 [font create -family [lindex [font families] 9] -weight bold]


set y 40
foreach f [list $f1 $f2 $f3 $f4] {
    .c create text 50 $y -text $txt -anchor w -font $f 
    incr y 40
}

set fm($f1) [list Helvetica 12]
set fm($f2) [list Times 13]
set fm($f3) [list Courier 14]
set fm($f4) [list Bookman-Demi 15]

.c postscript -file test.ps -fontmap fm

EG : The file Fontmap.GS is part of ghostscript, so is unlikely to be in a standard Windows install. The list of portable font names (the so called "base 35", taken from "Postscript Level 2" specification) is the following:

Bookman-Demi Bookman-DemiItalic Bookman-Light Bookman-LightItalic Courier Courier-Oblique Courier-Bold Courier-BoldOblique AvantGarde-Book AvantGarde-BookOblique AvantGarde-Demi AvantGarde-DemiOblique Helvetica Helvetica-Oblique Helvetica-Bold Helvetica-BoldOblique Helvetica-Narrow Helvetica-Narrow-Oblique Helvetica-Narrow-Bold Helvetica-Narrow-BoldOblique Palatino-Roman Palatino-Italic Palatino-Bold Palatino-BoldItalic NewCenturySchlbk-Roman NewCenturySchlbk-Italic NewCenturySchlbk-Bold NewCenturySchlbk-BoldItalic Times-Roman Times-Italic Times-Bold Times-BoldItalic Symbol ZapfChancery-MediumItalic ZapfDingbats .