OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [tests/] [font.test] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file is a Tcl script to test out Tk's "font" command
2
# plus the procedures in tkFont.c.  It is organized in the
3
# standard fashion for Tcl tests.
4
#
5
# Copyright (c) 1996 Sun Microsystems, Inc.
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
# RCS: @(#) $Id: font.test,v 1.1.1.1 2002-01-16 10:25:58 markom Exp $
11
 
12
if {[string compare test [info procs test]] != 0} {
13
    source defs
14
}
15
 
16
catch {destroy .b}
17
toplevel .b
18
wm geom .b +0+0
19
update idletasks
20
 
21
proc setup {} {
22
    catch {destroy .b.f}
23
    catch {font delete xyz}
24
    label .b.f
25
    pack .b.f
26
    update
27
}
28
 
29
label .b.l -padx 0 -pady 0 -bd 0 -highlightthickness 0 -justify left -text "0" -font "Courier -12"
30
pack .b.l
31
canvas .b.c -closeenough 0
32
.b.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
33
pack .b.c
34
update
35
 
36
set ax [winfo reqwidth .b.l]
37
set ay [winfo reqheight .b.l]
38
proc getsize {} {
39
    update
40
    return "[winfo reqwidth .b.l] [winfo reqheight .b.l]"
41
}
42
 
43
proc csetup {{str ""}} {
44
    focus -force .b.c
45
    .b.c dchars text 0 end
46
    .b.c insert text 0 $str
47
    .b.c focus text
48
}
49
 
50
setup
51
 
52
case $tcl_platform(platform) {
53
    unix        {set fixed "fixed"}
54
    windows     {set fixed "courier 12"}
55
    macintosh   {set fixed "monaco 9"}
56
}
57
set times [font actual {times 0} -family]
58
 
59
test font-1.1 {font command: general} {
60
    list [catch {font} msg] $msg
61
} {1 {wrong # args: should be "font option ?arg?"}}
62
test font-1.2 {font command: actual: arguments} {
63
    list [catch {font actual xyz -displayof} msg] $msg
64
} {1 {value for "-displayof" missing}}
65
test font-1.3 {font command: actual: arguments} {
66
    list [catch {font actual} msg] $msg
67
} {1 {wrong # args: should be "font actual font ?-displayof window? ?option?"}}
68
test font-1.4 {font command: actual: arguments} {
69
    list [catch {font actual xyz abc def} msg] $msg
70
} {1 {wrong # args: should be "font actual font ?-displayof window? ?option?"}}
71
test font-1.5 {font command: actual: arguments} {
72
    list [catch {font actual {}} msg] $msg
73
} {1 {font "" doesn't exist}}
74
test font-1.6 {font command: actual: displayof specified, so skip to next} {
75
    catch {font actual xyz -displayof . -size}
76
} {0}
77
test font-1.7 {font command: actual: displayof specified, so skip to next} {
78
    lindex [font actual xyz -displayof .] 0
79
} {-family}
80
test font-1.8 {font command: actual} {unix || mac} {
81
    string tolower [font actual {-family times} -family]
82
} {times}
83
test font-1.9 {font command: actual} {pcOnly} {
84
    font actual {-family times} -family
85
} {Times New Roman}
86
test font-1.10 {font command: actual} {
87
    lindex [font actual {-family times}] 0
88
} {-family}
89
test font-1.11 {font command: bad option} {
90
    list [catch {font actual xyz -style} msg] $msg
91
} {1 {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
92
 
93
test font-2.1 {font command: configure} {
94
    list [catch {font configure} msg] $msg
95
} {1 {wrong # args: should be "font configure fontname ?options?"}}
96
test font-2.2 {font command: configure: non-existent font} {
97
    list [catch {font configure xyz} msg] $msg
98
} {1 {named font "xyz" doesn't exist}}
99
test font-2.3 {font command: configure: "deleted" font} {
100
    setup
101
    font create xyz
102
    .b.f configure -font xyz
103
    font delete xyz
104
    list [catch {font configure xyz} msg] $msg
105
} {1 {named font "xyz" doesn't exist}}
106
test font-2.4 {font command: configure: get all options} {
107
    setup
108
    font create xyz -family xyz
109
    lindex [font configure xyz] 1
110
} xyz
111
test font-2.5 {font command: configure: get one option} {
112
    setup
113
    font create xyz -family xyz
114
    font configure xyz -family
115
} xyz
116
test font-2.6 {font command: configure: update existing font} {
117
    setup
118
    font create xyz
119
    font configure xyz -family xyz
120
    update
121
    font configure xyz -family
122
} xyz
123
test font-2.7 {font command: configure: bad option} {
124
    setup
125
    font create xyz
126
    list [catch {font configure xyz -style} msg] $msg
127
} {1 {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
128
 
129
test font-3.1 {font command: create: make up name} {
130
    font delete [font create]
131
    font delete [font create -family xyz]
132
} {}
133
test font-3.2 {font command: create: already exists} {
134
    setup
135
    font create xyz
136
    list [catch {font create xyz} msg] $msg
137
} {1 {font "xyz" already exists}}
138
test font-3.3 {font command: create: error recreating "deleted" font} {
139
    setup
140
    font create xyz
141
    .b.f configure -font xyz
142
    font delete xyz
143
    list [catch {font create xyz -xyz times} msg] $msg
144
} {1 {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
145
test font-3.4 {font command: create: recreate "deleted" font} {
146
    setup
147
    font create xyz
148
    .b.f configure -font xyz
149
    font delete xyz
150
    font actual xyz
151
    font create xyz -family times
152
    update
153
    font configure xyz -family
154
} {times}
155
test font-3.5 {font command: create: bad option creating new font} {
156
    setup
157
    list [catch {font create xyz -xyz times} msg] $msg
158
} {1 {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
159
test font-3.6 {font command: create: totally new font} {
160
    setup
161
    font create xyz -family xyz
162
    font configure xyz -family
163
} {xyz}
164
 
165
test font-4.1 {font command: delete: arguments} {
166
    list [catch {font delete} msg] $msg
167
} {1 {wrong # args: should be "font delete fontname ?fontname ...?"}}
168
test font-4.2 {font command: delete: loop test} {
169
    font create a -underline 1
170
    font create b -underline 1
171
    font create c -underline 1
172
    font delete a b c
173
    list [font actual a -underline] [font actual b -underline] [font actual c -underline]
174
} {0 0 0}
175
test font-4.3 {font command: delete: non-existent} {
176
    setup
177
    list [catch {font delete xyz} msg] $msg
178
} {1 {named font "xyz" doesn't exist}}
179
test font-4.4 {font command: delete: mark for later deletion} {
180
    setup
181
    font create xyz
182
    .b.f configure -font xyz
183
    font delete xyz
184
    font actual xyz
185
    list [catch {font configure xyz} msg] $msg
186
} {1 {named font "xyz" doesn't exist}}
187
test font-4.5 {font command: delete: actually delete} {
188
    setup
189
    font create xyz -underline 1
190
    font delete xyz
191
    font actual xyz -underline
192
} {0}
193
 
194
test font-5.1 {font command: families: arguments} {
195
    list [catch {font families -displayof} msg] $msg
196
} {1 {value for "-displayof" missing}}
197
test font-5.2 {font command: families: arguments} {
198
    list [catch {font families xyz} msg] $msg
199
} {1 {wrong # args: should be "font families ?-displayof window?"}}
200
test font-5.3 {font command: families} {
201
    font families
202
    set x {}
203
} {}
204
 
205
test font-6.1 {font command: measure: arguments} {
206
    list [catch {font measure xyz -displayof} msg] $msg
207
} {1 {value for "-displayof" missing}}
208
test font-6.2 {font command: measure: arguments} {
209
    list [catch {font measure} msg] $msg
210
} {1 {wrong # args: should be "font measure font ?-displayof window? text"}}
211
test font-6.3 {font command: measure: arguments} {
212
    list [catch {font measure xyz abc def} msg] $msg
213
} {1 {wrong # args: should be "font measure font ?-displayof window? text"}}
214
test font-6.4 {font command: measure: arguments} {
215
    list [catch {font measure {} abc} msg] $msg
216
} {1 {font "" doesn't exist}}
217
test font-6.5 {font command: measure} {
218
    expr [font measure $fixed "abcdefg"]==[font measure $fixed "a"]*7
219
} {1}
220
 
221
test font-7.1 {font command: metrics: arguments} {
222
    list [catch {font metrics xyz -displayof} msg] $msg
223
} {1 {value for "-displayof" missing}}
224
test font-7.2 {font command: metrics: arguments} {
225
    list [catch {font metrics} msg] $msg
226
} {1 {wrong # args: should be "font metrics font ?-displayof window? ?option?"}}
227
test font-7.3 {font command: metrics: get all metrics} {
228
    catch {unset a}
229
    array set a [font metrics {-family xyz}]
230
    set x [lsort [array names a]]
231
    unset a
232
    set x
233
} {-ascent -descent -fixed -linespace}
234
test font-7.4 {font command: metrics: get ascent} {
235
    catch {expr [font metrics $fixed -ascent]}
236
} {0}
237
test font-7.5 {font command: metrics: get descent} {
238
    catch {expr [font metrics {-family xyz} -descent]}
239
} {0}
240
test font-7.6 {font command: metrics: get linespace} {
241
    catch {expr [font metrics {-family fixed} -linespace]}
242
} {0}
243
test font-7.7 {font command: metrics: get fixed} {
244
    catch {expr [font metrics {-family fixed} -fixed]}
245
} {0}
246
test font-7.8 {font command: metrics: get ascent} {
247
    catch {expr [font metrics {-family xyz} -ascent]}
248
} {0}
249
test font-7.9 {font command: metrics: get descent} {
250
    catch {expr [font metrics {-family xyz} -descent]}
251
} {0}
252
test font-7.10 {font command: metrics: get linespace} {
253
    catch {expr [font metrics {-family fixed} -linespace]}
254
} {0}
255
test font-7.11 {font command: metrics: get fixed} {
256
    catch {expr [font metrics {-family fixed} -fixed]}
257
} {0}
258
test font-7.12 {font command: metrics: bad metric} {
259
    list [catch {font metrics {-family fixed} -xyz} msg] $msg
260
} {1 {bad metric "-xyz": must be -ascent, -descent, -linespace, or -fixed}}
261
 
262
test font-8.1 {font command: names: arguments} {
263
    list [catch {font names xyz} msg] $msg
264
} {1 {wrong # args: should be "font names"}}
265
test font-8.2 {font command: names} {
266
    setup
267
    font create xyz
268
    font create abc
269
    set x [lsort [font names]]
270
    font delete abc
271
    font delete xyz
272
    set x
273
} {abc xyz}
274
test font-8.3 {font command: names} {
275
    setup
276
    font create xyz
277
    font create abc
278
    set x [lsort [font names]]
279
    .b.f config -font xyz
280
    font delete xyz
281
    lappend x [font names]
282
    font delete abc
283
    set x
284
} {abc xyz abc}
285
 
286
test font-9.1 {font command: unknown option} {
287
    list [catch {font xyz} msg] $msg
288
} {1 {bad option "xyz": must be actual, configure, create, delete, families, measure, metrics, or names}}
289
 
290
test font-10.1 {UpdateDependantFonts procedure: no users} {
291
    setup
292
    font create xyz
293
    font configure xyz -family times
294
} {}
295
test font-10.2 {UpdateDependantFonts procedure: pings the widgets} {
296
    setup
297
    font create xyz -family times -size 20
298
    .b.f config -font xyz -text "abcd" -padx 0 -bd 0 -highlightthickness 0
299
    set a1 [font measure xyz "abcd"]
300
    update
301
    set b1 [winfo reqwidth .b.f]
302
    font configure xyz -family helvetica -size 20
303
    set a2 [font measure xyz "abcd"]
304
    update
305
    set b2 [winfo reqwidth .b.f]
306
    expr {$a1==$b1 && $a2==$b2}
307
} {1}
308
 
309
test font-11.1 {Tk_GetFont procedure: bump ref count} {
310
    setup
311
    .b.f config -font {-family fixed}
312
    lindex [font actual {-family fixed}] 0
313
} {-family}
314
test font-11.2 {Tk_GetFont procedure: bump ref count of named font, too} {
315
    setup
316
    font create xyz
317
    .b.f config -font xyz
318
    lindex [font actual xyz] 0
319
} {-family}
320
test font-11.3 {Tk_GetFont procedure: get named font} {
321
    setup
322
    font create xyz
323
    .b.f config -font xyz
324
} {}
325
test font-11.4 {Tk_GetFont procedure: get native font} {unixOnly} {
326
    setup
327
    .b.f config -font fixed
328
} {}
329
test font-11.5 {Tk_GetFont procedure: get native font} {pcOnly} {
330
    setup
331
    .b.f config -font oemfixed
332
} {}
333
test font-11.6 {Tk_GetFont procedure: get native font} {macOnly} {
334
    setup
335
    .b.f config -font application
336
} {}
337
test font-11.7 {Tk_GetFont procedure: get attribute font} {
338
    list [catch {.b.f config -font {xxx yyy zzz}} msg] $msg
339
} {1 {expected integer but got "yyy"}}
340
test font-11.8 {Tk_GetFont procedure: get attribute font} {
341
    lindex [font actual {plan 9}] 0
342
} {-family}
343
test font-11.9 {Tk_GetFont procedure: no match} {
344
    list [catch {font actual {}} msg] $msg
345
} {1 {font "" doesn't exist}}
346
 
347
test font-12.1 {Tk_NameOfFont procedure} {
348
    setup
349
    .b.f config -font {-family fixed}
350
    .b.f cget -font
351
} {-family fixed}
352
 
353
test font-13.1 {Tk_FreeFont procedure: one ref} {
354
    setup
355
    .b.f config -font {-family fixed}
356
    destroy .b.f
357
} {}
358
test font-13.2 {Tk_FreeFont procedure: multiple ref} {
359
    setup
360
    .b.f config -font {-family fixed}
361
    button .b.b -font {-family fixed}
362
    destroy .b.f
363
    set x [.b.b cget -font]
364
    destroy .b.b
365
    set x
366
} {-family fixed}
367
test font-13.3 {Tk_FreeFont procedure: named font} {
368
    setup
369
    font create xyz
370
    .b.f config -font xyz
371
    destroy .b.f
372
    font names
373
} {xyz}
374
test font-13.4 {Tk_FreeFont procedure: named font} {
375
    setup
376
    font create xyz -underline 1
377
    .b.f config -font xyz
378
    font delete xyz
379
    set x [font actual xyz -underline]
380
    destroy .b.f
381
    list [font actual xyz -underline] $x
382
} {0 1}
383
test font-13.5 {Tk_FreeFont procedure: named font not deleted yet} {
384
    setup
385
    font create xyz
386
    .b.f config -font xyz
387
    button .b.b -font xyz
388
    font delete xyz
389
    set x [font actual xyz]
390
    destroy .b.b
391
    list [lindex [font actual xyz] 0] [lindex $x 0]
392
} {-family -family}
393
 
394
test font-14.1 {Tk_FontId} {
395
    .b.f config -font "times 20"
396
    update
397
} {}
398
 
399
test font-15.1 {Tk_FontMetrics procedure} {
400
    button .b.w1 -text abc
401
    entry .b.w2 -text abcd
402
    update
403
    destroy .b.w1 .b.w2
404
} {}
405
 
406
proc psfontname {name} {
407
    set a [.b.c itemcget text -font]
408
    .b.c itemconfig text -font $name
409
    set post [.b.c postscript]
410
    .b.c itemconfig text -font $a
411
    set end [string first "findfont" $post]
412
    incr end -2
413
    set post [string range $post [expr $end-70] $end]
414
    set start [string first "gsave" $post]
415
    return [string range $post [expr $start+7] end]
416
}
417
test font-16.1 {Tk_PostscriptFontName procedure: native} {unixOnly} {
418
    set x [font actual {{itc avant garde} 10} -family]
419
    if {[string match *avant*garde $x]} {
420
        psfontname "{itc avant garde} 10"
421
    } else {
422
        set x {AvantGarde-Book}
423
    }
424
} {AvantGarde-Book}
425
test font-16.2 {Tk_PostscriptFontName procedure: native} {pcOnly} {
426
    psfontname "arial 10"
427
} {Helvetica}
428
test font-16.3 {Tk_PostscriptFontName procedure: native} {pcOnly} {
429
    psfontname "{times new roman} 10"
430
} {Times-Roman}
431
test font-16.4 {Tk_PostscriptFontName procedure: native} {pcOnly} {
432
    psfontname "{courier new} 10"
433
} {Courier}
434
test font-16.5 {Tk_PostscriptFontName procedure: native} {macOnly} {
435
    psfontname "geneva 10"
436
} {Helvetica}
437
test font-16.6 {Tk_PostscriptFontName procedure: native} {macOnly} {
438
    psfontname "{new york} 10"
439
} {Times-Roman}
440
test font-16.7 {Tk_PostscriptFontName procedure: native} {macOnly} {
441
    psfontname "monaco 10"
442
} {Courier}
443
test font-16.8 {Tk_PostscriptFontName procedure: spaces} {unixOnly} {
444
    set x [font actual {{lucida bright} 10} -family]
445
    if {[string match lucida*bright $x]} {
446
        psfontname "{lucida bright} 10"
447
    } else {
448
        set x {LucidaBright}
449
    }
450
} {LucidaBright}
451
test font-16.9 {Tk_PostscriptFontName procedure: spaces} {unixOnly} {
452
    psfontname "{new century schoolbook} 10"
453
} {NewCenturySchlbk-Roman}
454
set i 10
455
foreach p {
456
    {"avantgarde" AvantGarde-Book AvantGarde-Demi AvantGarde-BookOblique AvantGarde-DemiOblique}
457
    {"bookman" Bookman-Light Bookman-Demi Bookman-LightItalic Bookman-DemiItalic}
458
    {"courier" Courier Courier-Bold Courier-Oblique Courier-BoldOblique}
459
    {"helvetica" Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique}
460
    {"new century schoolbook" NewCenturySchlbk-Roman NewCenturySchlbk-Bold NewCenturySchlbk-Italic NewCenturySchlbk-BoldItalic}
461
    {"palatino" Palatino-Roman Palatino-Bold Palatino-Italic Palatino-BoldItalic}
462
    {"symbol" Symbol Symbol Symbol Symbol}
463
    {"times" Times-Roman Times-Bold Times-Italic Times-BoldItalic}
464
    {"zapfchancery" ZapfChancery-MediumItalic ZapfChancery-MediumItalic ZapfChancery-MediumItalic ZapfChancery-MediumItalic}
465
    {"zapfdingbats" ZapfDingbats ZapfDingbats ZapfDingbats ZapfDingbats}
466
} {
467
    test font-16.$i {Tk_PostscriptFontName procedure: exhaustive} {unixOnly} {
468
        set family [lindex $p 0]
469
        set x {}
470
        set i 1
471
        foreach slant {roman italic} {
472
            foreach weight {normal bold} {
473
                set name [list $family 12 $slant $weight]
474
                if {[font actual $name -family] == $family} {
475
                    lappend x [psfontname $name]
476
                } else {
477
                    lappend x [lindex $p $i]
478
                }
479
                incr i
480
            }
481
        }
482
        incr i
483
        set x
484
    } [lrange $p 1 end]
485
}
486
foreach p {
487
    {"arial" Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique}
488
    {"courier new" Courier Courier-Bold Courier-Oblique Courier-BoldOblique}
489
    {"helvetica" Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique}
490
    {"symbol" Symbol Symbol-Bold Symbol-Italic Symbol-BoldItalic}
491
    {"times new roman" Times-Roman Times-Bold Times-Italic Times-BoldItalic}
492
} {
493
    test font-16.$i {Tk_PostscriptFontName procedure: exhaustive} {pcOnly} {
494
        set family [lindex $p 0]
495
        set x {}
496
        foreach slant {roman italic} {
497
            foreach weight {normal bold} {
498
                lappend x [psfontname [list $family 12 "$slant $weight"]]
499
            }
500
        }
501
        incr i
502
        set x
503
    } [lrange $p 1 end]
504
}
505
foreach p {
506
    {"courier" Courier Courier-Bold Courier-Oblique Courier-BoldOblique}
507
    {"geneva" Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique}
508
    {"helvetica" Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique}
509
    {"monaco" Courier Courier-Bold Courier-Oblique Courier-BoldOblique}
510
    {"new york" Times-Roman Times-Bold Times-Italic Times-BoldItalic}
511
    {"symbol" Symbol Symbol-Bold Symbol-Italic Symbol-BoldItalic}
512
    {"times" Times-Roman Times-Bold Times-Italic Times-BoldItalic}
513
} {
514
    test font-16.$i {Tk_PostscriptFontName procedure: exhaustive} {macOnly} {
515
        set family [lindex $p 0]
516
        set x {}
517
        foreach slant {roman italic} {
518
            foreach weight {normal bold} {
519
                lappend x [psfontname [list $family 12 $slant $weight]]
520
            }
521
        }
522
        incr i
523
        set x
524
    } [lrange $p 1 end]
525
}
526
 
527
test font-17.1 {Tk_UnderlineChars procedure} {
528
    text .b.t
529
    .b.t insert 1.0 abc\tdefg
530
    .b.t tag config sel -underline 1
531
    .b.t tag add sel 1.0 end
532
    update
533
} {}
534
 
535
setup
536
test font-18.1 {Tk_ComputeTextLayout: empty string} {
537
    .b.l config -text ""
538
} {}
539
test font-18.2 {Tk_ComputeTextLayout: simple string} {
540
    .b.l config -text "000"
541
    getsize
542
} "[expr $ax*3] $ay"
543
test font-18.3 {Tk_ComputeTextLayout: find special chars} {
544
    .b.l config -text "000\n000"
545
    getsize
546
} "[expr $ax*3] [expr $ay*2]"
547
test font-18.4 {Tk_ComputeTextLayout: calls Tk_MeasureChars} {
548
    .b.l config -text "000\n000"
549
    getsize
550
} "[expr $ax*3] [expr $ay*2]"
551
test font-18.5 {Tk_ComputeTextLayout: break line} {
552
    .b.l config -text "000\t00000" -wrap [expr 9*$ax]
553
    set x [getsize]
554
    .b.l config -wrap 0
555
    set x
556
} "[expr 8*$ax] [expr 2*$ay]"
557
test font-18.6 {Tk_ComputeTextLayout: normal ended on special char} {
558
    .b.l config -text "000\n000"
559
} {}
560
test font-18.7 {Tk_ComputeTextLayout: special char was \n} {
561
    .b.l config -text "000\n0000"
562
    getsize
563
} "[expr $ax*4] [expr $ay*2]"
564
test font-18.8 {Tk_ComputeTextLayout: special char was \t} {
565
    .b.l config -text "000\t00"
566
    getsize
567
} "[expr $ax*10] $ay"
568
test font-18.9 {Tk_ComputeTextLayout: tab didn't cause break} {
569
    set x {}
570
    .b.l config -text "000\t000"
571
    lappend x [getsize]
572
    .b.l config -text "000\t000" -wrap [expr 100*$ax]
573
    lappend x [getsize]
574
    .b.l config -wrap 0
575
    set x
576
} "{[expr $ax*11] $ay} {[expr $ax*11] $ay}"
577
test font-18.10 {Tk_ComputeTextLayout: tab caused break} {
578
    set x {}
579
    .b.l config -text "000\t"
580
    lappend x [getsize]
581
    .b.l config -text "000\t00" -wrap [expr $ax*6]
582
    lappend x [getsize]
583
    .b.l config -wrap 0
584
    set x
585
} "{[expr $ax*3] $ay} {[expr $ax*3] [expr $ay*2]}"
586
test font-18.11 {Tk_ComputeTextLayout: absorb spaces at eol} {
587
    set x {}
588
    .b.l config -text "000            000" -wrap [expr $ax*5]
589
    lappend x [getsize]
590
    .b.l config -text "000            "
591
    lappend x [getsize]
592
    .b.l config -wrap 0
593
    set x
594
} "{[expr $ax*3] [expr $ay*2]} {[expr $ax*3] $ay}"
595
test font-18.12 {Tk_ComputeTextLayout: append non-printing spaces to chunk} {
596
    set x {}
597
    .b.l config -text "000            0000" -wrap [expr $ax*5]
598
    lappend x [getsize]
599
    .b.l config -text "000\t00            0000" -wrap [expr $ax*12]
600
    lappend x [getsize]
601
    .b.l config -wrap 0
602
    set x
603
} "{[expr $ax*4] [expr $ay*2]} {[expr $ax*10] [expr $ay*2]}"
604
test font-18.13 {Tk_ComputeTextLayout: many lines -> realloc line array} {
605
    .b.l config -text "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
606
    getsize
607
} "1 [expr $ay*129]"
608
test font-18.14 {Tk_ComputeTextLayout: text ended with \n} {
609
    list [.b.l config -text "0000"; getsize] [.b.l config -text "0000\n"; getsize]
610
} "{[expr $ax*4] $ay} {[expr $ax*4] [expr $ay*2]}"
611
test font-18.15 {Tk_ComputeTextLayout: justification} {
612
    csetup "000\n00000"
613
    set x {}
614
    .b.c itemconfig text -just left
615
    lappend x [.b.c index text @[expr $ax*2],0]
616
    .b.c itemconfig text -just center
617
    lappend x [.b.c index text @[expr $ax*2],0]
618
    .b.c itemconfig text -just right
619
    lappend x [.b.c index text @[expr $ax*2],0]
620
    .b.c itemconfig text -just left
621
    set x
622
} {2 1 0}
623
 
624
test font-19.1 {Tk_FreeTextLayout procedure} {
625
    setup
626
    .b.f config -text foo
627
    .b.f config -text boo
628
} {}
629
 
630
test font-20.1 {Tk_DrawTextLayout procedure: auto-detect last char} {
631
    .b.f config -text foo
632
} {}
633
test font-20.2 {Tk_DrawTextLayout procedure: multiple chunks} {
634
    csetup "000\t00\n000"
635
} {}
636
test font-20.3 {Tk_DrawTextLayout: draw subset of chunk: numDisplay <= 0} {
637
    csetup "000\t00"
638
    .b.c select from text 3
639
    .b.c select to text 5
640
} {}
641
test font-20.4 {Tk_DrawTextLayout: draw subset of chunk: firstChar <= 0} {
642
    .b.c select from text 3
643
    .b.c select to text 5
644
} {}
645
test font-20.5 {Tk_DrawTextLayout: draw subset of chunk: firstChar > 0} {
646
    .b.c select from text 2
647
    .b.c select to text 2
648
} {}
649
test font-20.6 {Tk_DrawTextLayout: draw subset of chunk: lastChar < numChars} {
650
    .b.c select from text 4
651
    .b.c select to text 4
652
} {}
653
 
654
test font-21.1 {Tk_UnderlineTextLayout procedure: no underline chosen} {
655
    .b.f config -text "foo" -under -1
656
} {}
657
test font-21.2 {Tk_UnderlineTextLayout procedure: underline not visible} {
658
    .b.f config -text "000          00000" -wrap [expr $ax*7] -under 10
659
} {}
660
test font-21.3 {Tk_UnderlineTextLayout procedure: underline is visible} {
661
    .b.f config -text "000          00000" -wrap [expr $ax*7] -under 5
662
    .b.f config -wrap -1 -under -1
663
} {}
664
 
665
test font-22.1 {Tk_PointToChar procedure: above all lines} {
666
    csetup "000"
667
    .b.c index text @-1,0
668
} {0}
669
test font-22.2 {Tk_PointToChar procedure: no chars} {
670
    # After fixing the following bug:
671
    #
672
    # In canvas text item, it was impossible to click to position the
673
    # insertion point just after the last character.
674
    #
675
    # introduced another bug that Tk_PointToChar() would return a character
676
    # index of 1 if TextLayout contained 0 characters.
677
 
678
    csetup ""
679
    .b.c index text @100,100
680
} {0}
681
test font-22.3 {Tk_PointToChar procedure: loop test} {
682
    csetup "000\n000\n000\n000"
683
    .b.c index text @10000,0
684
} {3}
685
test font-22.4 {Tk_PointToChar procedure: intersect line} {
686
    csetup "000\n000\n000"
687
    .b.c index text @0,$ay
688
} {4}
689
test font-22.5 {Tk_PointToChar procedure: to the left of all chunks} {
690
    .b.c index text @-100,$ay
691
} {4}
692
test font-22.6 {Tk_PointToChar procedure: past any possible chunk} {
693
    .b.c index text @100000,$ay
694
} {7}
695
test font-22.7 {Tk_PointToChar procedure: which chunk on this line} {
696
    csetup "000\n000\t000\t000\n000"
697
    .b.c index text @[expr $ax*2],$ay
698
} {6}
699
test font-22.8 {Tk_PointToChar procedure: which chunk on this line} {
700
    csetup "000\n000\t000\t000\n000"
701
    .b.c index text @[expr $ax*10],$ay
702
} {10}
703
test font-22.9 {Tk_PointToChar procedure: in special chunk} {
704
    csetup "000\n000\t000\t000\n000"
705
    .b.c index text @[expr $ax*6],$ay
706
} {7}
707
test font-22.10 {Tk_PointToChar procedure: past all chars in chunk} {
708
    csetup "000 0000000"
709
    .b.c itemconfig text -width [expr $ax*5]
710
    set x [.b.c index text @[expr $ax*5],0]
711
    .b.c itemconfig text -width 0
712
    set x
713
} {3}
714
test font-22.11 {Tk_PointToChar procedure: below all chunks} {
715
    csetup "000 0000000"
716
    .b.c index text @0,1000000
717
} {11}
718
 
719
test font-23.1 {Tk_CharBBox procedure: index < 0} {
720
    .b.f config -text "000" -underline -1
721
} {}
722
test font-23.2 {Tk_CharBBox procedure: loop} {
723
    .b.f config -text "000\t000\t000\t000" -underline 9
724
} {}
725
test font-23.3 {Tk_CharBBox procedure: special char} {
726
    .b.f config -text "000\t000\t000" -underline 7
727
} {}
728
test font-23.4 {Tk_CharBBox procedure: normal char} {
729
    .b.f config -text "000" -underline 1
730
} {}
731
test font-23.5 {Tk_CharBBox procedure: right edge of bbox truncated} {
732
    .b.f config -text "0    0000" -wrap [expr $ax*4] -under 2
733
    .b.f config -wrap 0
734
} {}
735
test font-23.6 {Tk_CharBBox procedure: bbox pegged to right edge} {
736
    .b.f config -text "0    0000" -wrap [expr $ax*4] -under 3
737
    .b.f config -wrap 0
738
} {}
739
 
740
.b.c bind all  {lappend x [.b.c index current @%x,%y]}
741
 
742
test font-24.1 {Tk_TextLayoutToPoint procedure: loop once} {
743
    csetup "000\n000\n000"
744
    set x {}
745
    event generate .b.c 
746
    event generate .b.c  -x 0 -y 0
747
    set x
748
} {0}
749
test font-24.2 {Tk_TextLayoutToPoint procedure: loop multiple} {
750
    csetup "000\n000\n000"
751
    set x {}
752
    event generate .b.c 
753
    event generate .b.c  -x $ax -y $ay
754
    set x
755
} {5}
756
test font-24.3 {Tk_TextLayoutToPoint procedure: loop to end} {
757
    csetup "000\n0\n000"
758
    set x {}
759
    event generate .b.c 
760
    event generate .b.c  -x [expr $ax*2] -y $ay
761
    set x
762
} {}
763
test font-24.4 {Tk_TextLayoutToPoint procedure: hit a special char (tab)} {
764
    csetup "000\t000\n000"
765
    set x {}
766
    event generate .b.c 
767
    event generate .b.c  -x [expr $ax*6] -y 0
768
    set x
769
} {3}
770
test font-24.5 {Tk_TextLayoutToPoint procedure: ignore newline} {
771
    csetup "000\n0\n000"
772
    set x {}
773
    event generate .b.c 
774
    event generate .b.c  -x [expr $ax*2] -y $ay
775
    set x
776
} {}
777
test font-24.6 {Tk_TextLayoutToPoint procedure: ignore spaces at eol} {
778
    csetup "000\n000      000000000"
779
    .b.c itemconfig text -width [expr $ax*10]
780
    set x {}
781
    event generate .b.c 
782
    event generate .b.c  -x [expr $ax*5] -y $ay
783
    .b.c itemconfig text -width 0
784
    set x
785
} {}
786
.b.c itemconfig text -justify center
787
test font-24.7 {Tk_TextLayoutToPoint procedure: on left side} {
788
    csetup "0\n000"
789
    set x {}
790
    event generate .b.c 
791
    event generate .b.c  -x 0 -y 0
792
    set x
793
} {}
794
test font-24.8 {Tk_TextLayoutToPoint procedure: on right side} {
795
    csetup "0\n000"
796
    set x {}
797
    event generate .b.c 
798
    event generate .b.c  -x [expr $ax*2] -y 0
799
    set x
800
} {}
801
test font-24.9 {Tk_TextLayoutToPoint procedure: inside line} {
802
    csetup "0\n000"
803
    set x {}
804
    event generate .b.c 
805
    event generate .b.c  -x $ax -y 0
806
    set x
807
} {0}
808
test font-24.10 {Tk_TextLayoutToPoint procedure: above line} {
809
    csetup "0\n000"
810
    set x {}
811
    event generate .b.c 
812
    event generate .b.c  -x 0 -y 0
813
    set x
814
} {}
815
test font-24.11 {Tk_TextLayoutToPoint procedure: below line} {
816
    csetup "000\n0"
817
    set x {}
818
    event generate .b.c 
819
    event generate .b.c  -x 0 -y $ay
820
    set x
821
} {}
822
test font-24.12 {Tk_TextLayoutToPoint procedure: in line} {
823
    csetup "0\n000"
824
    set x {}
825
    event generate .b.c 
826
    event generate .b.c  -x $ax -y $ay
827
    set x
828
} {3}
829
.b.c itemconfig text -justify left
830
test font-24.13 {Tk_TextLayoutToPoint procedure: exact hit} {
831
    csetup "000"
832
    set x {}
833
    event generate .b.c 
834
    event generate .b.c  -x $ax -y 0
835
    set x
836
} {1}
837
 
838
test font-25.1 {Tk_TextLayoutToArea procedure: loop once} {
839
    csetup "000\n000\n000"
840
    .b.c find overlapping 0 0 0 0
841
} [.b.c find withtag text]
842
test font-25.2 {Tk_TextLayoutToArea procedure: loop multiple} {
843
    csetup "000\t000\t000"
844
    .b.c find overlapping [expr $ax*10] 0 [expr $ax*10] 0
845
} [.b.c find withtag text]
846
test font-25.3 {Tk_TextLayoutToArea procedure: loop to end} {
847
    csetup "0\n000"
848
    .b.c find overlapping [expr $ax*2] 0 [expr $ax*2] 0
849
} {}
850
test font-25.4 {Tk_TextLayoutToArea procedure: hit a special char (tab)} {
851
    csetup "000\t000"
852
    .b.c find overlapping [expr $ax*6] 0 [expr $ax*6] 0
853
} [.b.c find withtag text]
854
test font-25.5 {Tk_TextLayoutToArea procedure: ignore newlines} {
855
    csetup "000\n0\n000"
856
    .b.c find overlapping $ax $ay $ax $ay
857
} {}
858
test font-25.6 {Tk_TextLayoutToArea procedure: ignore spaces at eol} {
859
    csetup "000\n000      000000000"
860
    .b.c itemconfig text -width [expr $ax*10]
861
    set x [.b.c find overlapping [expr $ax*5] $ay [expr $ax*5] $ay]
862
    .b.c itemconfig text -width 0
863
    set x
864
} {}
865
 
866
test font-26.1 {Tk_TextLayoutToPostscript: ensure buffer doesn't overflow} {
867
    # If there were a whole bunch of returns or tabs in a row, then the
868
    # temporary buffer could overflow and write on the stack.
869
 
870
    csetup "qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm\n"
871
    .b.c itemconfig text -width 800
872
    .b.c insert text end "qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm\n"
873
    .b.c insert text end "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
874
    .b.c insert text end "end"
875
    set x [.b.c postscript]
876
    set i [string first "(qwerty" $x]
877
    string range $x $i [expr {$i + 213}]
878
} {(qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm)
879
(qwertyuiopasdfghjklzxcvbnm1234qwertyuiopasdfghjklzxcvbnm)
880
()
881
()
882
()
883
()
884
()
885
()
886
()
887
()
888
()
889
()
890
()
891
()
892
()
893
()
894
()
895
()
896
()
897
()
898
()
899
()
900
()
901
()
902
()
903
()
904
()
905
()
906
()
907
()
908
()
909
()
910
(end)
911
}
912
 
913
test font-27.1 {Tk_TextWidth procedure} {
914
    font measure [.b.l cget -font] "000"
915
} [expr $ax*3]
916
 
917
test font-28.1 {SetupFontMetrics procedure} {
918
    setup
919
    .b.f config -font $fixed
920
} {}
921
 
922
test font-29.1 {TkInitFontAttributes procedure} {
923
    setup
924
    font create xyz
925
    font config xyz
926
} {-family {} -size 0 -weight normal -slant roman -underline 0 -overstrike 0}
927
 
928
test font-30.1 {ConfigAttributes procedure: arguments} {
929
    setup
930
    list [catch {font create xyz -family} msg] $msg
931
} {1 {missing value for "-family" option}}
932
test font-30.2 {ConfigAttributes procedure: arguments} {
933
    setup
934
    list [catch {font create xyz -xyz xyz} msg] $msg
935
} {1 {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
936
set i 3
937
foreach p {
938
    {family xyz times}
939
    {size 20 40}
940
    {weight normal bold}
941
    {slant roman italic}
942
    {underline 0 1}
943
    {overstrike 0 1}
944
} {
945
    set opt [lindex $p 0]
946
    test font-30.$i "ConfigAttributes procedure: $opt" {
947
        setup
948
        set x {}
949
        font create xyz -$opt [lindex $p 1]
950
        lappend x [font config xyz -$opt]
951
        font config xyz -$opt [lindex $p 2]
952
        lappend x [font config xyz -$opt]
953
    } [lrange $p 1 2]
954
    incr i
955
}
956
foreach p {
957
    {size       xyz {1 {expected integer but got "xyz"}}}
958
    {weight     xyz {1 {bad -weight value "xyz": must be normal, bold}}}
959
    {slant      xyz {1 {bad -slant value "xyz": must be roman, italic}}}
960
    {underline  xyz {1 {expected boolean value but got "xyz"}}}
961
    {overstrike xyz {1 {expected boolean value but got "xyz"}}}
962
} {
963
    test font-30.$i "ConfigAttributes procedure: [lindex $p 0]" {
964
        setup
965
        list [catch {font create xyz -[lindex $p 0] [lindex $p 1]} msg] $msg
966
    } [lindex $p 2]
967
    incr i
968
}
969
 
970
test font-31.1 {GetAttributeInfo procedure: error} {
971
    list [catch {font actual xyz -style} msg] $msg
972
} {1 {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}}
973
test font-31.2 {GetAttributeInfo procedure: all attributes} {
974
    setup
975
    font create xyz -family xyz
976
    font config xyz
977
} {-family xyz -size 0 -weight normal -slant roman -underline 0 -overstrike 0}
978
set i 3
979
foreach p {
980
    {family     xyz     xyz}
981
    {size       20      20}
982
    {weight     normal  normal}
983
    {slant      italic  italic}
984
    {underline  yes     1}
985
    {overstrike false   0}
986
} {
987
    test font-31.$i "GetAttributeInfo procedure: [lindex $p 0]" {
988
        setup
989
        font create xyz -[lindex $p 0] [lindex $p 1]
990
        font config xyz -[lindex $p 0]
991
    } [lindex $p 2]
992
    incr i
993
}
994
 
995
# In tests below, one field is set to "xyz" so that font name doesn't
996
# look like a native X font, so that ParseFontName or TkParseXLFD will
997
# be called.
998
 
999
setup
1000
 
1001
test font-32.1 {ParseFontName procedure: begins with -} {
1002
    lindex [font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-*] 1
1003
} $times
1004
test font-32.2 {ParseFontName procedure: begins with -*} {
1005
    lindex [font actual -*-times-xyz-*-*-*-*-*-*-*-*-*-*-*] 1
1006
} $times
1007
test font-32.3 {ParseFontName procedure: begins with -, doesn't look like list} {
1008
    lindex [font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-*] 1
1009
} $times
1010
test font-32.4 {ParseFontName procedure: begins with -, looks like list} {
1011
    lindex [font actual {-family times}] 1
1012
} $times
1013
test font-32.5 {ParseFontName procedure: begins with *} {
1014
    lindex [font actual *-times-xyz-*-*-*-*-*-*-*-*-*-*-*] 1
1015
} $times
1016
test font-32.6 {ParseFontName procedure: begins with *} {
1017
    font actual *-times-xyz -family
1018
} $times
1019
test font-32.7 {ParseFontName procedure: arguments} {
1020
    list [catch {font actual {}} msg] $msg
1021
} {1 {font "" doesn't exist}}
1022
test font-32.8 {ParseFontName procedure: arguments} {
1023
    list [catch {font actual {times 20 xyz xyz}} msg] $msg
1024
} {1 {unknown font style "xyz"}}
1025
test font-32.9 {ParseFontName procedure: arguments} {
1026
    list [catch {font actual {times xyz xyz}} msg] $msg
1027
} {1 {expected integer but got "xyz"}}
1028
test font-32.10 {ParseFontName procedure: stylelist loop} {macOnly} {
1029
    lrange [font actual {times 12 bold italic overstrike underline}] 4 end
1030
} {-weight bold -slant italic -underline 1 -overstrike 0}
1031
test font-32.11 {ParseFontName procedure: stylelist loop} {unixOrPc} {
1032
    lrange [font actual {times 12 bold italic overstrike underline}] 4 end
1033
} {-weight bold -slant italic -underline 1 -overstrike 1}
1034
test font-32.12 {ParseFontName procedure: stylelist error} {
1035
    list [catch {font actual {times 12 bold xyz}} msg] $msg
1036
} {1 {unknown font style "xyz"}}
1037
 
1038
test font-33.1 {TkParseXLFD procedure: initial dash} {
1039
    font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-* -family
1040
} $times
1041
test font-33.2 {TkParseXLFD procedure: no initial dash} {
1042
    font actual *-times-*-*-*-*-*-*-*-*-*-*-*-xyz -family
1043
} $times
1044
test font-33.3 {TkParseXLFD procedure: not enough fields} {
1045
    font actual -xyz-times-*-*-* -family
1046
} $times
1047
test font-33.4 {TkParseXLFD procedure: all fields unspecified} {
1048
    lindex [font actual -xyz-*-*-*-*-*-*-*-*-*-*-*-*-*] 0
1049
} {-family}
1050
test font-33.5 {TkParseXLFD procedure: all fields specified} {
1051
    lindex [font actual -foundry-times-weight-slant-setwidth-addstyle-10-10-10-10-spacing-avgwidth-registry-encoding] 1
1052
} $times
1053
test font-33.6 {TkParseXLFD procedure: arguments} {
1054
    # XLFD with bad pointsize: fallback to some system font.
1055
    font actual -*-*-*-*-*-*-xyz-*-*-*-*-*-*-*
1056
    set x {}
1057
} {}
1058
test font-33.7 {TkParseXLFD procedure: arguments} {
1059
    # XLFD with bad pixelsize: fallback to some system font.
1060
    font actual -*-*-*-*-*-*-*-xyz-*-*-*-*-*-*
1061
    set x {}
1062
} {}
1063
test font-33.8 {TkParseXLFD procedure: pixelsize specified} {
1064
    font metrics -xyz-times-*-*-*-*-12-*-*-*-*-*-*-* -linespace
1065
    set x {}
1066
} {}
1067
test font-33.9 {TkParseXLFD procedure: weird pixelsize specified} {
1068
    font metrics {-xyz-times-*-*-*-*-[ 12.0 0 12.0 0]-*-*-*-*-*-*-*} -linespace
1069
    set x {}
1070
} {}
1071
test font-33.10 {TkParseXLFD procedure: pointsize specified} {
1072
    font metrics -xyz-times-*-*-*-*-*-120-*-*-*-*-*-* -linespace
1073
    set x {}
1074
} {}
1075
test font-33.11 {TkParseXLFD procedure: weird pointsize specified} {
1076
    font metrics {-xyz-times-*-*-*-*-*-[ 12.0 0 12.0 0]-*-*-*-*-*-*} -linespace
1077
    set x {}
1078
} {}
1079
 
1080
test font-34.1 {FieldSpecified procedure: specified vs. non-specified} {
1081
    font actual -xyz--*-*-*-*-*-*-*-*-*-*-*-*
1082
    font actual -xyz-*-*-*-*-*-*-*-*-*-*-*-*-*
1083
    font actual -xyz-?-*-*-*-*-*-*-*-*-*-*-*-*
1084
    lindex [font actual -xyz-times-*-*-*-*-*-*-*-*-*-*-*-*] 1
1085
} $times
1086
 
1087
test font-35.1 {NewChunk procedure: test realloc} {
1088
    .b.f config -text "xxx\nxxx\txxx\nxxx\t\t\t"
1089
} {}
1090
 
1091
destroy .b
1092
return

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.