Re: font tweaking

Brent Welch <[email protected]> Wed, 27 Apr 2005 23:12:25 -0700
Newsgroups gmane.mail.exmh.devel
Message-ID <[email protected]>
>>>John Beck said:
 > 
 > Brent> ... you'd need to send yourself a text part in some alternate charact
     er
 > Brent> set and ensure that it is displayed right.  I don't think it will be.
 > 
 > I suspected something like that.  OK, I've undone that change ...
 > 
 > Brent> The way to try your fix is to use a "tag raise" command ...
 > 
 > Excellent; now it works as I had originally hoped.

cool

 > Just one (I hope) follow-up question: I'm not sure what font to use as a
 > default for this.  The default "master" font appears to be "fixed", but
 > although `xlsfonts` lists that, I don't see any sort of obvious bold analog.
 > I use 9x15 for many things, so 9x15bold is the obvious one for *me* to use.
 > If you have a suggestion, I'll happily included that in my patch of the
 > app-defaults file; otherwise, I'll use 9x15bold.

Tk has a font mechanism that should help with this.  If you get the
font name, you can query its attributes, and then change the weight
attribute from "normal" to "bold".  The trick is to query the tags
at the given location, then query the font attributes of those
tags, then query the metrics of the font...

Something like 

foreach tag [$text tag names $index] {
  # Iterate over tags from lowest to highest priority
  set font [$text tag cget -font]
  if {$font != ""} {
     set fontattrs [font actual $font]
     set ix [lsearch -exact $fontattrs -weight]
     incr ix
     set fontattrs [lreplace $fontattrs $ix $ix bold]
  }
}
# Define a new, bold font
set font [eval font create $fontattrs]
# and a new tag
$text tag configure bold$font -font $font

To be most efficient, you'd like to only configure the bold
tag once.  Tk sets up a somewhat heavy-weight data structure and
X11 context for each text tag and font.

Or, for your purposes, simply hardwire the tag :-)

--
Brent Welch
Software Architect, Panasas Inc
Accelerating Time to Results(tm) with Clustered Storage

www.panasas.com
[email protected]