- # This file is a Tcl script to test out the procedures in tkUnixFont.c.
- # It is organized in the standard fashion for Tcl tests.
- #
- # Many of these tests are visually oriented and cannot be checked
- # programmatically (such as "does an underlined font appear to be
- # underlined?"); these tests attempt to exercise the code in question,
- # but there are no results that can be checked. Some tests depend on the
- # fonts having or not having certain properties, which may not be valid
- # at all sites.
- #
- # Copyright (c) 1996 Sun Microsystems, Inc.
- # Copyright (c) 1998-1999 by Scriptics Corporation.
- # All rights reserved.
- #
- # RCS: @(#) $Id: unixFont.test,v 1.7 2002/07/13 20:28:35 dgp Exp $
- package require tcltest 2.1
- namespace import -force tcltest::configure
- namespace import -force tcltest::testsDirectory
- configure -testdir [file join [pwd] [file dirname [info script]]]
- configure -loadfile [file join [testsDirectory] constraints.tcl]
- tcltest::loadTestedCommands
- testConstraint hasArial 1
- testConstraint hasCourierNew 1
- testConstraint hasTimesNew 1
- set xlsf [auto_execok xlsfonts]
- if {[llength $xlsf]} {
- foreach {constraint font} {
- hasArial arial
- hasCourierNew "courier new"
- hasTimesNew "times new roman"
- } {
- if {![catch {eval exec $xlsf [list *-$font-*]} res]
- && ![string match *unmatched* $res]} {
- # Newer Unix systems have more default fonts installed,
- # so we can't rely on fallbacks for fonts to need to
- # fall back on anything.
- testConstraint $constraint 0
- }
- }
- }
- catch {destroy .b}
- toplevel .b
- wm geom .b +0+0
- update idletasks
- # Font should be fixed width and have chars missing below char 32, so can
- # test control char expansion and missing character code.
- set courier {Courier -10}
- set cx [font measure $courier 0]
- label .b.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left -text "0" -font fixed
- pack .b.l
- canvas .b.c -closeenough 0
- set t [.b.c create text 0 0 -anchor nw -just left -font $courier]
- pack .b.c
- update
- set ax [winfo reqwidth .b.l]
- set ay [winfo reqheight .b.l]
- proc getsize {} {
- update
- return "[winfo reqwidth .b.l] [winfo reqheight .b.l]"
- }
- test unixfont-1.1 {TkpGetNativeFont procedure: not native} {unix noExceed} {
- list [catch {font measure {} xyz} msg] $msg
- } {1 {font "" doesn't exist}}
- test unixfont-1.2 {TkpGetNativeFont procedure: native} unix {
- font measure fixed 0
- } {6}
- test unixfont-2.1 {TkpGetFontFromAttributes procedure: no family} unix {
- font actual {-size 10}
- set x {}
- } {}
- test unixfont-2.2 {TkpGetFontFromAttributes procedure: Times relatives}
- {unix noExceed hasTimesNew} {
- set x {}
- lappend x [lindex [font actual {-family "Times New Roman"}] 1]
- lappend x [lindex [font actual {-family "New York"}] 1]
- lappend x [lindex [font actual {-family "Times"}] 1]
- } {times times times}
- test unixfont-2.3 {TkpGetFontFromAttributes procedure: Courier relatives}
- {unix noExceed hasCourierNew} {
- set x {}
- lappend x [lindex [font actual {-family "Courier New"}] 1]
- lappend x [lindex [font actual {-family "Monaco"}] 1]
- lappend x [lindex [font actual {-family "Courier"}] 1]
- } {courier courier courier}
- test unixfont-2.4 {TkpGetFontFromAttributes procedure: Helvetica relatives}
- {unix noExceed hasArial} {
- set x {}
- lappend x [lindex [font actual {-family "Arial"}] 1]
- lappend x [lindex [font actual {-family "Geneva"}] 1]
- lappend x [lindex [font actual {-family "Helvetica"}] 1]
- } {helvetica helvetica helvetica}
- test unixfont-2.5 {TkpGetFontFromAttributes procedure: fallback} unix {
- font actual {-xyz-xyz-*-*-*-*-*-*-*-*-*-*-*-*}
- set x {}
- } {}
- test unixfont-2.6 {TkpGetFontFromAttributes: fallback to fixed family} unix {
- lindex [font actual {-family fixed -size 10}] 1
- } {fixed}
- test unixfont-2.7 {TkpGetFontFromAttributes: fixed family not available!} unix {
- # no test available
- } {}
- test unixfont-2.8 {TkpGetFontFromAttributes: loop over returned font names} unix {
- lindex [font actual {-family fixed -size 31}] 1
- } {fixed}
- test unixfont-2.9 {TkpGetFontFromAttributes: reject adobe courier if possible} {unix noExceed} {
- lindex [font actual {-family courier}] 1
- } {courier}
- test unixfont-2.10 {TkpGetFontFromAttributes: scalable font found} unix {
- lindex [font actual {-family courier -size 37}] 3
- } {37}
- test unixfont-2.11 {TkpGetFontFromAttributes: font cannot be loaded} unix {
- # On Linux, XListFonts() was returning names for fonts that do not
- # actually exist, causing the subsequent XLoadQueryFont() to fail
- # unexpectedly. Now falls back to another font if that happens.
- font actual {-size 14}
- set x {}
- } {}
- test unixfont-3.1 {TkpDeleteFont procedure} unix {
- font actual {-family xyz}
- set x {}
- } {}
- test unixfont-4.1 {TkpGetFontFamilies procedure} unix {
- font families
- set x {}
- } {}
- test unixfont-5.1 {Tk_MeasureChars procedure: no chars to be measured} unix {
- .b.l config -text "000000" -wrap [expr $ax*3]
- .b.l config -wrap 0
- } {}
- test unixfont-5.2 {Tk_MeasureChars procedure: no right margin} unix {
- .b.l config -text "000000"
- } {}
- test unixfont-5.3 {Tk_MeasureChars procedure: loop over chars} unix {
- .b.l config -text "0"
- .b.l config -text "377"
- .b.l config -text "03770377"
- .b.l config -text "000000000000000"
- } {}
- .b.l config -wrap [expr $ax*10]
- test unixfont-5.4 {Tk_MeasureChars procedure: reached right edge} unix {
- .b.l config -text "0000000000000"
- getsize
- } "[expr $ax*10] [expr $ay*2]"
- test unixfont-5.5 {Tk_MeasureChars procedure: ran out of chars} unix {
- .b.l config -text "000000"
- getsize
- } "[expr $ax*6] $ay"
- test unixfont-5.6 {Tk_MeasureChars procedure: find last word} unix {
- .b.l config -text "000000 00000"
- getsize
- } "[expr $ax*6] [expr $ay*2]"
- test unixfont-5.7 {Tk_MeasureChars procedure: already saw space in line} unix {
- .b.l config -text "000000 00000"
- getsize
- } "[expr $ax*6] [expr $ay*2]"
- test unixfont-5.8 {Tk_MeasureChars procedure: internal spaces significant} unix {
- .b.l config -text "00 000 00000"
- getsize
- } "[expr $ax*7] [expr $ay*2]"
- test unixfont-5.9 {Tk_MeasureChars procedure: TK_PARTIAL_OK} unix {
- .b.c dchars $t 0 end
- .b.c insert $t 0 "0000"
- .b.c index $t @[expr int($ax*2.5)],1
- } {2}
- test unixfont-5.10 {Tk_MeasureChars procedure: TK_AT_LEAST_ONE} unix {
- .b.l config -text "000000000000"
- getsize
- } "[expr $ax*10] [expr $ay*2]"
- test unixfont-5.11 {Tk_MeasureChars: TK_AT_LEAST_ONE + not even one char fit!} unix {
- set a [.b.l cget -wrap]
- .b.l config -text "000000" -wrap 1
- set x [getsize]
- .b.l config -wrap $a
- set x
- } "$ax [expr $ay*6]"
- test unixfont-5.12 {Tk_MeasureChars procedure: include eol spaces} unix {
- .b.l config -text "000 n000"
- getsize
- } "[expr $ax*6] [expr $ay*2]"
- test unixfont-6.1 {Tk_DrawChars procedure: loop test} unix {
- .b.l config -text "a"
- update
- } {}
- test unixfont-6.2 {Tk_DrawChars procedure: loop test} unix {
- .b.l config -text "abcd"
- update
- } {}
- test unixfont-6.3 {Tk_DrawChars procedure: special char} unix {
- .b.l config -text "