From 15ce64e5282d617ca16a98e30ca697b5c31d9dad Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 1 Jan 2014 14:17:46 +0000 Subject: Allow font family to be set, falling back to Times, and increase the default font size to 16 --- tkread | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tkread b/tkread index b14204a..b4f9f2e 100755 --- a/tkread +++ b/tkread @@ -13,9 +13,9 @@ # - if window width is small, reduce padx space # - make scrolling using mouse work even when text area isn't hovered over (also note this sort of scrolling doesn't update the title); integrate the MouseWheel event with scroll. this *should* also fix the issue of dragging and then leaving the window, as the strange scrolling is likely caused by related default behaviour # - add more markdown processing -# - use font create / configure to name a font to simplify changing its size -set fontsize 15 +set fontfamily {Linux Libertine O} +set fontsize 16 set textcolour #443322 set bgcolour #eeeeee set outercolour #f8f8f5 @@ -49,6 +49,7 @@ proc rewrap {text} { # deleted without affecting the position for formatting. proc markup {widget} { global surroundfmt + global fontfamily global fontsize global tagnum @@ -86,22 +87,23 @@ proc markup {widget} { $widget tag add tag_$tagnum markon_$x markoff_$x } - $widget tag configure tag_$tagnum -font "Times $fontsize $fmtstring" + $widget tag configure tag_$tagnum -font "{$fontfamily} $fontsize $fmtstring" incr tagnum } } proc changeFontSize {change} { + global fontfamily global fontsize global surroundfmt global tagnum set newsize [expr $fontsize $change] if {$newsize > 0} { set fontsize $newsize - .t configure -font "Times $fontsize" -padx [expr $fontsize * 3] + .t configure -font "{$fontfamily} $fontsize" -padx [expr $fontsize * 3] for {set x 0} {$x < $tagnum} {incr x} { set fmtstring [lindex [lindex $surroundfmt $x] 1] - .t tag configure tag_$x -font "Times $fontsize $fmtstring" + .t tag configure tag_$x -font "{$fontfamily} $fontsize $fmtstring" } } } @@ -136,8 +138,12 @@ proc doMotion {ypos} { set lasty $ypos } +if { [lsearch [font families] "$fontfamily"] == -1 } { + # A font called "Times" is guaranteed by Tk to be available + set fontfamily Times +} . configure -bg $outercolour -text .t -font "Times $fontsize" -wrap word -width 64 -padx [expr $fontsize * 3] -bg $bgcolour -fg $textcolour -relief flat -inactiveselectbackground {} -cursor {} +text .t -font "{$fontfamily} $fontsize" -wrap word -width 64 -padx [expr $fontsize * 3] -bg $bgcolour -fg $textcolour -relief flat -inactiveselectbackground {} -cursor {} pack .t -expand yes -fill y set text [read stdin] foreach arg $::argv { -- cgit v1.2.3