@matheusbsbs / matheus-bagliano / commits / 0ed1dd3c77
Fork 0

gitk: Keep track of font attributes ourselves instead of using font actual

Unfortunately there seems to be a bug in Tk8.5 where font actual -size sometimes gives the wrong answer (e.g. 12 for Bitstream Vera Sans 9), even though the font is actually displayed at the right size. This works around it by parsing and storing the family, size, weight and slant of the mainfont, textfont and uifont explicitly. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Oct 6, 2007 at 18:27 UTC 0ed1dd3c77e606156f0f5d1baa59a47f33711787
1 file changed +57 -25
gitk
+57 -25
@@ -5685,43 +5685,73 @@ proc redisplay {} {
5685 }
5686 }
5687
5688 -proc fontdescr {f} {
5689 - set d [list [font actual $f -family] [font actual $f -size]]
5690 - if {[font actual $f -weight] eq "bold"} {
5691 - lappend d "bold"
5688 +proc parsefont {f n} {
5689 + global fontattr
5690 +
5691 + set fontattr($f,family) [lindex $n 0]
5692 + set s [lindex $n 1]
5693 + if {$s eq {} || $s == 0} {
5694 + set s 10
5695 + } elseif {$s < 0} {
5696 + set s [expr {int(-$s / [winfo fpixels . 1p] + 0.5)}]
5697 }
5693 - if {[font actual $f -slant] eq "italic"} {
5694 - lappend d "italic"
5698 + set fontattr($f,size) $s
5699 + set fontattr($f,weight) normal
5700 + set fontattr($f,slant) roman
5701 + foreach style [lrange $n 2 end] {
5702 + switch -- $style {
5703 + "normal" -
5704 + "bold" {set fontattr($f,weight) $style}
5705 + "roman" -
5706 + "italic" {set fontattr($f,slant) $style}
5707 + }
5708 }
5696 - if {[font actual $f -underline]} {
5697 - lappend d "underline"
5709 +}
5710 +
5711 +proc fontflags {f {isbold 0}} {
5712 + global fontattr
5713 +
5714 + return [list -family $fontattr($f,family) -size $fontattr($f,size) \
5715 + -weight [expr {$isbold? "bold": $fontattr($f,weight)}] \
5716 + -slant $fontattr($f,slant)]
5717 +}
5718 +
5719 +proc fontname {f} {
5720 + global fontattr
5721 +
5722 + set n [list $fontattr($f,family) $fontattr($f,size)]
5723 + if {$fontattr($f,weight) eq "bold"} {
5724 + lappend n "bold"
5725 }
5699 - if {[font actual $f -overstrike]} {
5700 - lappend d "overstrike"
5726 + if {$fontattr($f,slant) eq "italic"} {
5727 + lappend n "italic"
5728 }
5702 - return $d
5729 + return $n
5730 }
5731
5732 proc incrfont {inc} {
5733 global mainfont textfont ctext canv phase cflist showrefstop
5707 - global stopped entries
5734 + global stopped entries fontattr
5735 +
5736 unmarkmatches
5709 - set s [font actual mainfont -size]
5737 + set s $fontattr(mainfont,size)
5738 incr s $inc
5739 if {$s < 1} {
5740 set s 1
5741 }
5742 + set fontattr(mainfont,size) $s
5743 font config mainfont -size $s
5744 font config mainfontbold -size $s
5716 - set mainfont [fontdescr mainfont]
5717 - set s [font actual textfont -size]
5745 + set mainfont [fontname mainfont]
5746 + set s $fontattr(textfont,size)
5747 incr s $inc
5748 if {$s < 1} {
5749 set s 1
5750 }
5751 + set fontattr(textfont,size) $s
5752 font config textfont -size $s
5753 font config textfontbold -size $s
5724 - set textfont [fontdescr textfont]
5754 + set textfont [fontname textfont]
5755 setcoords
5756 settabs
5757 redisplay
@@ -8340,15 +8370,17 @@ set selectbgcolor gray85
8370 catch {source ~/.gitk}
8371
8372 font create optionfont -family sans-serif -size -12
8343 -font create mainfont
8344 -catch {eval font config mainfont [font actual $mainfont]}
8345 -eval font create mainfontbold [font actual mainfont] -weight bold
8346 -font create textfont
8347 -catch {eval font config textfont [font actual $textfont]}
8348 -eval font create textfontbold [font actual textfont]
8349 -font config textfontbold -weight bold
8350 -font create uifont
8351 -catch {eval font config uifont [font actual $uifont]}
8373 +
8374 +parsefont mainfont $mainfont
8375 +eval font create mainfont [fontflags mainfont]
8376 +eval font create mainfontbold [fontflags mainfont 1]
8377 +
8378 +parsefont textfont $textfont
8379 +eval font create textfont [fontflags textfont]
8380 +eval font create textfontbold [fontflags textfont 1]
8381 +
8382 +parsefont uifont $uifont
8383 +eval font create uifont [fontflags uifont]
8384
8385 # check that we can find a .git directory somewhere...
8386 if {[catch {set gitdir [gitdir]}]} {