proc smallcaps {w index text {font ""} {smallness 67}} { if {$font eq ""} {set font [$w cget -font]} set bigtag [string map {" " _ \{ _ \} _} $font] $w tag configure $bigtag -font $font set bigsize [lindex $font 1] set smallsize [expr {round($bigsize*$smallness/100.)}] set smallfont [lreplace $font 1 1 $smallsize] set smalltag [string map {" " _ \{ _ \} _} $smallfont] $w tag configure $smalltag -font $smallfont set cmd [list $w insert $index] #set re {([A-Z]*)([^A-Z]*)} ;# (1) set re {([[:upper:]]*)([^[:upper:]]*)} foreach {- big small} [regexp -all -inline $re $text] { lappend cmd $big $bigtag [string toupper $small] $smalltag } eval $cmd }#-- Testing:
pack [text .t] smallcaps .t end "Testing SmallCaps..\n\n" {Times 12} .t insert end "This is normal text, in comparison"
Lars H: It should probably be pointed out that the above produces what is known as fake smallcaps in typography; the problem with linearly shrinking glyphs is that they come out looking too light and too tight together. This is probably not noticable at the low resolution of a computer screen (most stems end up 1 pixel thick anyway), but it looks bad in print. Better font families have specially designed smallcaps fonts instead. (Question: How do these show up in Tk -- as a separate style or as something completely unrelated to the regular font?) The classical quote on the subject is
- Anyone who would fake smallcaps would also steal sheep.
Arts and crafts of Tcl-Tk programming Category Widget Category Example