Prev: TclApp under OSX: where are the packages?
Next: Tablelist event binding doesn't behave as expected
From: Gerhard Reithofer on 16 Jul 2010 03:33 Hi *, once more I found a tcl script which fails due to new "standard" tk* font names. Example: pack [text .t] set cfont [.t cget -font] .t insert end "Hello World!" .t configure -font "$cfont bold" This works in Tcl 8.4 but fails in Tcl 8.5 with the error message: expected integer but got "bold" The reason is, that 8.4 text default font is "Courier -12" in my Linux environment and in 8.5 it's "TkFixedFont" without size value. It works also on 8.5 im using .t configure -font "{$cfont bold}" I have the "solution", but the 1st version is widely used in many older scripts (seen here again in Visual Regexp). Q: Is this a bug or feature? -- Gerhard Reithofer Tech-EDV Support Forum - http://support.tech-edv.co.at
From: Aric Bills on 16 Jul 2010 10:07 On Jul 16, 1:33 am, Gerhard Reithofer <gerhard.reitho...(a)tech- edv.co.at> wrote: > Hi *, > once more I found a tcl script which fails due to new "standard" tk* > font names. > > Example: > pack [text .t] > set cfont [.t cget -font] > .t insert end "Hello World!" > .t configure -font "$cfont bold" > > This works in Tcl 8.4 but fails in Tcl 8.5 with the error message: > expected integer but got "bold" > > The reason is, that 8.4 text default font is "Courier -12" in my > Linux environment and in 8.5 it's "TkFixedFont" without size value. > > It works also on 8.5 im using > .t configure -font "{$cfont bold}" > > I have the "solution", but the 1st version is widely used in many > older scripts (seen here again in Visual Regexp). > > Q: Is this a bug or feature? > > -- > Gerhard Reithofer > Tech-EDV Support Forum -http://support.tech-edv.co.at I can't say whether "{$cfont bold}" is a bug or feature, but a more robust way to get the bold weight of a font in both 8.4 and 8.5 would be as follows: set cfont [font actual [.t cget -font] -displayof .t] set index [expr {[lsearch $cfont "-weight"] + 1}] .t configure -font [lreplace $cfont $index $index "bold"] For 8.5 (or 8.4 with dict extension) this can be simplified to set cfont [font actual [.t cget -font] -displayof .t] .t configure -font [dict replace $cfont -weight bold]
From: Joe English on 16 Jul 2010 20:02 Gerhard Reithofer wrote: > once more I found a tcl script which fails due to new "standard" tk* > font names. > > Example: > pack [text .t] > set cfont [.t cget -font] > .t insert end "Hello World!" > .t configure -font "$cfont bold" > > This works in Tcl 8.4 but fails in Tcl 8.5 with the error message: > expected integer but got "bold" Note that this would also have failed under Tk 8.4 if (for instance) the user had set something like: *Text.font: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 in the X resource database. The recommended way to generate modified versions of other fonts is: set newFont [dict replace [font actual $oldFont] -weight bold] (or, for pre-8.5 versions, the obvious dict-free equivalent using [array set] / [array get]) This works no matter how the font was originally specified -- named fonts, platform-specific fonts, XLFD fonts, "shorthand" "family ?size? ?style...?" specifications and -option/-value lists. [set newFont "$oldFont bold"] has always been fragile; it only used to work by accident. > The reason is, that 8.4 text default font is "Courier -12" in my > Linux environment and in 8.5 it's "TkFixedFont" without size value. Alternately, if you know you want "Courier -12 bold", you could just say "Courier -12 bold"... --Joe English
|
Pages: 1 Prev: TclApp under OSX: where are the packages? Next: Tablelist event binding doesn't behave as expected |