📄 textdisp.test
字号:
# This file is a Tcl script to test the code in the file tkTextDisp.c.# This file is organized in the standard fashion for Tcl tests.## Copyright (c) 1994 The Regents of the University of California.# Copyright (c) 1994-1997 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## SCCS: @(#) textDisp.test 1.55 97/07/24 15:15:43if {[string compare test [info procs test]] == 1} { source defs if {$testConfig(fonts) == 0} { puts "skipping font-sensitive tests" }}# The procedure below is used as the scrolling command for the text;# it just saves the scrolling information in a variable "scrollInfo".proc scroll args { global scrollInfo set scrollInfo $args}# The procedure below is used to generate errors during scrolling commands.proc scrollError args { error "scrolling error"}# Create entries in the option database to be sure that geometry options# like border width have predictable values.option add *Text.borderWidth 2option add *Text.highlightThickness 2# The frame .f is needed to make sure that the overall window is always# fairly wide, even if the text window is very narrow. This is needed# because some window managers don't allow the overall width of a window# to get very narrow.foreach i [winfo child .] { destroy $i}frame .f -width 100 -height 20pack append . .f leftif {$tcl_platform(platform) == "windows"} { set fixedFont {Courier -14}} else { set fixedFont {Courier -12}}set fixedHeight [font metrics $fixedFont -linespace]set fixedWidth [font measure $fixedFont m]set varFont {Times -14}set bigFont {Helvetica -24}text .t -font $fixedFont -width 20 -height 10 -yscrollcommand scrollpack append . .t {top expand fill}.t tag configure big -font $bigFont.t debug onwm geometry . {}# The statements below reset the main window; it's needed if the window# manager is mwm to make mwm forget about a previous minimum size setting.wm withdraw .wm minsize . 1 1wm positionfrom . userwm deiconify .update# Some window managers (like olwm under SunOS 4.1.3) misbehave in a way# that tends to march windows off the top and left of the screen. If# this happens, some tests will fail because parts of the window will# not need to be displayed (because they're off-screen). To keep this# from happening, move the window if it's getting near the left or top# edges of the screen.if {([winfo rooty .] < 50) || ([winfo rootx .] < 50)} { wm geom . +50+50}test textDisp-1.1 {GetStyle procedure, priorities and tab stops} { .t delete 1.0 end .t insert 1.0 "x\ty" .t tag delete x y z .t tag configure x -tabs {50} .t tag configure y -foreground black .t tag configure z -tabs {70} .t tag add x 1.0 1.end .t tag add y 1.0 1.end .t tag add z 1.0 1.end update idletasks set x [lindex [.t bbox 1.2] 0] .t tag configure z -tabs {} lappend x [lindex [.t bbox 1.2] 0] .t tag configure z -tabs {30} .t tag raise x update idletasks lappend x [lindex [.t bbox 1.2] 0]} {75 55 55}.t tag delete x y ztest textDisp-1.2 {GetStyle procedure, wrapmode} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "abcd\nefg hijkl mnop qrstuv wxyz" .t tag configure x -wrap word .t tag configure y -wrap none .t tag raise y update set result [list [.t bbox 2.20]] .t tag add x 2.0 2.1 lappend result [.t bbox 2.20] .t tag add y 1.end 2.2 lappend result [.t bbox 2.20]} {{5 31 7 13} {40 31 7 13} {}}.t tag delete x ytest textDisp-2.1 {LayoutDLine, basics} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "This is some sample text for testing." list [.t bbox 1.19] [.t bbox 1.20]} [list [list [expr 5 + $fixedWidth * 19] 5 $fixedWidth $fixedHeight] [list 5 [expr 5 + $fixedHeight] $fixedWidth $fixedHeight]]test textDisp-2.2 {LayoutDLine, basics} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "This isx some sample text for testing." list [.t bbox 1.19] [.t bbox 1.20]} {{138 5 7 13} {5 18 7 13}}test textDisp-2.3 {LayoutDLine, basics} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "This isxxx some sample text for testing." list [.t bbox 1.19] [.t bbox 1.20]} {{138 5 7 13} {5 18 7 13}}test textDisp-2.4 {LayoutDLine, word wrap} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This is some sample text for testing." list [.t bbox 1.19] [.t bbox 1.20]} {{138 5 7 13} {5 18 7 13}}test textDisp-2.5 {LayoutDLine, word wrap} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This isx some sample text for testing." list [.t bbox 1.13] [.t bbox 1.14] [.t bbox 1.19]} {{96 5 49 13} {5 18 7 13} {40 18 7 13}}test textDisp-2.6 {LayoutDLine, word wrap} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This isxxx some sample text for testing." list [.t bbox 1.15] [.t bbox 1.16]} {{110 5 35 13} {5 18 7 13}}test textDisp-2.7 {LayoutDLine, marks and tags} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This isxxx some sample text for testing." .t tag add foo 1.4 1.6 .t mark set insert 1.8 list [.t bbox 1.2] [.t bbox 1.5] [.t bbox 1.11]} {{19 5 7 13} {40 5 7 13} {82 5 7 13}}foreach m [.t mark names] { catch {.t mark unset $m}}scan [wm geom .] %dx%d width heighttest textDisp-2.8 {LayoutDLine, extra chunk at end of dline} {fonts} { wm geom . [expr $width+1]x$height update .t configure -wrap char .t delete 1.0 end .t insert 1.0 "This isxx some sample text for testing." .t mark set foo 1.20 list [.t bbox 1.19] [.t bbox 1.20]} {{138 5 8 13} {5 18 7 13}}wm geom . {}updatetest textDisp-2.9 {LayoutDLine, marks and tags} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This is a very_very_long_word_that_wraps." list [.t bbox 1.9] [.t bbox 1.10] [.t bbox 1.25]} {{68 5 77 13} {5 18 7 13} {110 18 7 13}}test textDisp-2.10 {LayoutDLine, marks and tags} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "This is a very_very_long_word_that_wraps." .t tag add foo 1.13 .t tag add foo 1.15 .t tag add foo 1.17 .t tag add foo 1.19 list [.t bbox 1.9] [.t bbox 1.10] [.t bbox 1.25]} {{68 5 77 13} {5 18 7 13} {110 18 7 13}}test textDisp-2.11 {LayoutDLine, newline width} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "a\nbb\nccc\ndddd" list [.t bbox 2.2] [.t bbox 3.3]} {{19 18 126 13} {26 31 119 13}}test textDisp-2.12 {LayoutDLine, justification} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "\na\nbb\nccc\ndddd" .t tag configure x -justify center .t tag add x 1.0 end .t tag add y 3.0 3.2 list [.t bbox 1.0] [.t bbox 2.0] [.t bbox 4.0] [.t bbox 4.2]} {{75 5 70 13} {71 18 7 13} {64 44 7 13} {78 44 7 13}}test textDisp-2.13 {LayoutDLine, justification} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "\na\nbb\nccc\ndddd" .t tag configure x -justify right .t tag add x 1.0 end .t tag add y 3.0 3.2 list [.t bbox 1.0] [.t bbox 2.0] [.t bbox 4.0] [.t bbox 4.2]} {{145 5 0 13} {138 18 7 13} {124 44 7 13} {138 44 7 13}}test textDisp-2.14 {LayoutDLine, justification} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "\na\nbb\nccc\ndddd" .t tag configure x -justify center .t tag add x 2.0 3.1 .t tag configure y -justify right .t tag add y 3.0 4.0 .t tag raise y list [.t bbox 2.0] [.t bbox 3.0] [.t bbox 3.end] [.t bbox 4.0]} {{71 18 7 13} {131 31 7 13} {145 31 0 13} {5 44 7 13}}test textDisp-2.15 {LayoutDLine, justification} {fonts} { .t configure -wrap char .t delete 1.0 end .t insert 1.0 "\na\nbb\nccc\ndddd" .t tag configure x -justify center .t tag add x 2.0 3.1 .t tag configure y -justify right .t tag add y 3.0 4.0 .t tag lower y list [.t bbox 2.0] [.t bbox 3.0] [.t bbox 3.end] [.t bbox 4.0]} {{71 18 7 13} {68 31 7 13} {82 31 63 13} {5 44 7 13}}test textDisp-2.16 {LayoutDLine, justification} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines" .t tag configure x -justify center .t tag add x 1.1 1.20 .t tag add x 1.21 1.end list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.36] [.t bbox 2.0]} {{5 5 7 13} {5 18 7 13} {43 31 7 13} {5 44 7 13}}test textDisp-2.17 {LayoutDLine, justification} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines" .t tag configure x -justify center .t tag add x 1.20 list [.t bbox 1.0] [.t bbox 1.20] [.t bbox 1.36] [.t bbox 2.0]} {{5 5 7 13} {19 18 7 13} {5 31 7 13} {5 44 7 13}}test textDisp-2.18 {LayoutDLine, justification} {fonts} { .t configure -wrap none .t delete 1.0 end .t insert 1.0 "Lots of long words, enough to extend out of the window\n" .t insert end "Then\nmore lines\nThat are shorter" .t tag configure x -justify center .t tag configure y -justify right .t tag add x 2.0 .t tag add y 3.0 .t xview scroll 5 units list [.t bbox 2.0] [.t bbox 3.0]} {{26 18 7 13} {40 31 7 13}}.t tag delete x.t tag delete ytest textDisp-2.19 {LayoutDLine, margins} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines" .t tag configure x -lmargin1 20 -lmargin2 40 -rmargin 15 .t tag add x 1.0 end list [.t bbox 1.0] [.t bbox 1.12] [.t bbox 1.13] [.t bbox 2.0]} {{25 5 7 13} {109 5 36 13} {45 18 7 13} {25 70 7 13}}test textDisp-2.20 {LayoutDLine, margins} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "Lots of long words, enough to force word wrap\nThen\nmore lines" .t tag configure x -lmargin1 20 -lmargin2 10 -rmargin 3 .t tag configure y -lmargin1 15 -lmargin2 5 -rmargin 0 .t tag raise y .t tag add x 1.0 end .t tag add y 1.13 list [.t bbox 1.0] [.t bbox 1.13] [.t bbox 1.30] [.t bbox 2.0]} {{25 5 7 13} {10 18 7 13} {15 31 7 13} {25 44 7 13}}test textDisp-2.21 {LayoutDLine, margins} {fonts} { .t configure -wrap word .t delete 1.0 end .t insert 1.0 "Sample text" .t tag configure x -lmargin1 80 -lmargin2 80 -rmargin 100 .t tag add x 1.0 end list [.t bbox 1.0] [.t bbox 1.1] [.t bbox 1.2]} {{85 5 60 13} {85 18 60 13} {85 31 60 13}}.t tag delete x.t tag delete ytest textDisp-2.22 {LayoutDLine, spacing options} {fonts} { .t configure -wrap word .t delete 1.0 end .t tag delete x y .t insert end "Short line\nLine 2 is long enough " .t insert end "to wrap around a couple of times" .t insert end "\nLine 3\nLine 4" set i [.t dlineinfo 1.0] set b1 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 2.0] set b2 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 2.end] set b3 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 3.0] set b4 [expr [lindex $i 1] + [lindex $i 4]] .t configure -spacing1 2 -spacing2 1 -spacing3 3 set i [.t dlineinfo 1.0] set b1 [expr [lindex $i 1] + [lindex $i 4] - $b1] set i [.t dlineinfo 2.0] set b2 [expr [lindex $i 1] + [lindex $i 4] - $b2] set i [.t dlineinfo 2.end] set b3 [expr [lindex $i 1] + [lindex $i 4] - $b3] set i [.t dlineinfo 3.0] set b4 [expr [lindex $i 1] + [lindex $i 4] - $b4] list $b1 $b2 $b3 $b4} {2 7 10 15}.t configure -spacing1 0 -spacing2 0 -spacing3 0test textDisp-2.23 {LayoutDLine, spacing options} {fonts} { .t configure -wrap word .t delete 1.0 end .t tag delete x y .t insert end "Short line\nLine 2 is long enough " .t insert end "to wrap around a couple of times" .t insert end "\nLine 3\nLine 4" set i [.t dlineinfo 1.0] set b1 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 2.0] set b2 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 2.end] set b3 [expr [lindex $i 1] + [lindex $i 4]] set i [.t dlineinfo 3.0] set b4 [expr [lindex $i 1] + [lindex $i 4]] .t configure -spacing1 4 -spacing2 4 -spacing3 4 .t tag configure x -spacing1 1 -spacing2 2 -spacing3 3 .t tag add x 1.0 end .t tag configure y -spacing1 0 -spacing2 3 .t tag add y 2.19 end .t tag raise y set i [.t dlineinfo 1.0] set b1 [expr [lindex $i 1] + [lindex $i 4] - $b1] set i [.t dlineinfo 2.0] set b2 [expr [lindex $i 1] + [lindex $i 4] - $b2] set i [.t dlineinfo 2.end] set b3 [expr [lindex $i 1] + [lindex $i 4] - $b3] set i [.t dlineinfo 3.0] set b4 [expr [lindex $i 1] + [lindex $i 4] - $b4] list $b1 $b2 $b3 $b4} {1 5 13 16}.t configure -spacing1 0 -spacing2 0 -spacing3 0test textDisp-2.24 {LayoutDLine, tabs, saving from first chunk} {fonts} { .t delete 1.0 end .t tag delete x y .t tag configure x -tabs 70 .t tag configure y -tabs 80 .t insert 1.0 "ab\tcde" .t tag add x 1.0 end .t tag add y 1.1 end lindex [.t bbox 1.3] 0} {75}test textDisp-2.25 {LayoutDLine, tabs, breaking chunks at tabs} {fonts} { .t delete 1.0 end .t tag delete x .t tag configure x -tabs {30 60 90 120} .t insert 1.0 "a\tb\tc\td\te" .t mark set dummy1 1.1 .t mark set dummy2 1.2 .t tag add x 1.0 end list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \ [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]} {35 65 95 125}test textDisp-2.26 {LayoutDLine, tabs, breaking chunks at tabs} {fonts} { .t delete 1.0 end .t tag delete x .t tag configure x -tabs {30 60 90 120} -justify right .t insert 1.0 "a\tb\tc\td\te" .t mark set dummy1 1.1 .t mark set dummy2 1.2 .t tag add x 1.0 end list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0] \ [lindex [.t bbox 1.6] 0] [lindex [.t bbox 1.8] 0]} {117 124 131 138}test textDisp-2.27 {LayoutDLine, tabs, calling AdjustForTab} {fonts} { .t delete 1.0 end .t tag delete x .t tag configure x -tabs {30 60} .t insert 1.0 "a\tb\tcd" .t tag add x 1.0 end list [lindex [.t bbox 1.2] 0] [lindex [.t bbox 1.4] 0]} {35 65}test textDisp-2.28 {LayoutDLine, tabs, running out of space in dline} {fonts} { .t delete 1.0 end .t insert 1.0 "a\tb\tc\td" .t bbox 1.6} {5 18 7 13}test textDisp-2.29 {LayoutDLine, tabs, running out of space in dline} {fonts} {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -