/
font.test
2356 lines (2226 loc) · 72.7 KB
/
font.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
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
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file is a Tcl script to test out Tk's "font" command
# plus the procedures in tkFont.c. It is organized in the
# standard white-box fashion for Tcl tests.
#
# Copyright (c) 1996-1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
package require tcltest 2.2
namespace import ::tcltest::*
eval tcltest::configure $argv
tcltest::loadTestedCommands
catch {eval font delete [font names]}
deleteWindows
# Toplevel used (in some tests) of the whole file
toplevel .t
wm geom .t +0+0
update idletasks
case [tk windowingsystem] {
x11 {set fixed "fixed"}
win32 {set fixed "courier 12"}
classic -
aqua {set fixed "monaco 9"}
}
# Procedure used in tests: 24.15, 26.*, 28.*, 30.*, 31.*, 32.1
proc csetup {{str ""}} {
focus -force .t.c
.t.c dchars text 0 end
.t.c insert text 0 $str
.t.c focus text
}
test font-1.1 {TkFontPkgInit} -setup {
catch {interp delete foo}
} -body {
interp create foo
foo eval {
load {} Tk
wm geometry . +0+0
update
}
interp delete foo
} -result {}
test font-2.1 {TkFontPkgFree} -setup {
catch {interp delete foo}
set x {}
} -body {
interp create foo
# Makes sure that named font was visible only to child interp.
foo eval {
load {} Tk
wm geometry . +0+0
button .b -font {times 16} -text "hi"
pack .b
font create wiggles -family courier -underline 1
update
}
lappend x [catch {font configure wiggles} msg; set msg]
# Tests cancelling the idle handler for TheWorldHasChanged,
# because app goes away before idle serviced.
foo eval {
.b config -font wiggles
font config wiggles -size 24
destroy .
}
lappend x [foo eval {catch {font families} msg; set msg}]
} -cleanup {
interp delete foo
} -result {{named font "wiggles" doesn't exist} {can't invoke "font" command: application has been destroyed}}
test font-3.1 {font command: general} -body {
font
} -returnCodes error -result {wrong # args: should be "font option ?arg?"}
test font-3.2 {font command: general} -body {
font xyz
} -returnCodes error -result {bad option "xyz": must be actual, configure, create, delete, families, measure, metrics, or names}
test font-4.1 {font command: actual: arguments} -body {
# (skip < 0)
font actual xyz -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-4.2 {font command: actual: arguments} -body {
# (objc < 3)
font actual
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.3 {font command: actual: arguments} -body {
# (objc - skip > 4) when skip == 0
font actual xyz abc def
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.4 {font command: actual: displayof specified, so skip to next} -body {
catch {font actual xyz -displayof . -size}
} -result {0}
test font-4.5 {font command: actual: displayof specified, so skip to next} -body {
lindex [font actual xyz -displayof .] 0
} -result {-family}
test font-4.6 {font command: actual: arguments} -body {
# (objc - skip > 4) when skip == 2
font actual xyz -displayof . abc def
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?option? ?--? ?char?"}
test font-4.7 {font command: actual: arguments} -constraints noExceed -body {
# (tkfont == NULL)
font actual "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-4.8 {font command: actual: all attributes} -body {
# not (objc > 3) so objPtr = NULL
lindex [font actual {-family times}] 0
} -result {-family}
test font-4.9 {font command: actual} -constraints {unix noExceed} -body {
# (objc > 3) so objPtr = objv[3 + skip]
string tolower [font actual {-family times} -family]
} -result {times}
test font-4.10 {font command: actual} -constraints win -body {
# (objc > 3) so objPtr = objv[3 + skip]
font actual {-family times} -family
} -result {Times New Roman}
test font-4.11 {font command: bad option} -body {
font actual xyz -style
} -returnCodes error -result {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}
test font-5.1 {font command: configure} -body {
# (objc < 3)
font configure
} -returnCodes error -result {wrong # args: should be "font configure fontname ?-option value ...?"}
test font-5.2 {font command: configure: non-existent font} -body {
# (namedHashPtr == NULL)
font configure xyz
} -returnCodes error -result {named font "xyz" doesn't exist}
test font-5.3 {font command: configure: "deleted" font} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# (nfPtr->deletePending != 0)
font create xyz
.t.f configure -font xyz
font delete xyz
font configure xyz
} -cleanup {
destroy .t.f
} -returnCodes error -result {named font "xyz" doesn't exist}
test font-5.4 {font command: configure: get all options} -setup {
catch {font delete xyz}
} -body {
# (objc == 3) so objPtr = NULL
font create xyz -family xyz
lindex [font configure xyz] 1
} -cleanup {
font delete xyz
} -result xyz
test font-5.5 {font command: configure: get one option} -setup {
catch {eval font delete [font names]}
} -body {
# (objc == 4) so objPtr = objv[3]
font create xyz -family xyz
font configure xyz -family
font names
} -cleanup {
font delete xyz
} -result xyz
test font-5.6 {font command: configure: update existing font} -setup {
catch {font delete xyz}
} -body {
# else result = ConfigAttributesObj()
font create xyz
font configure xyz -family xyz
update
font configure xyz -family
} -cleanup {
font delete xyz
} -result xyz
test font-5.7 {font command: configure: bad option} -setup {
catch {font delete xyz}
} -body {
font create xyz
font configure xyz -style
} -cleanup {
font delete xyz
} -returnCodes error -result {bad option "-style": must be -family, -size, -weight, -slant, -underline, or -overstrike}
test font-6.1 {font command: create: make up name} -setup {
catch {eval font delete [font names]}
} -body {
# (objc < 3) so name = NULL
font create
font names
} -cleanup {
font delete font1
} -result {font1}
test font-6.2 {font command: create: name specified} -setup {
catch {eval font delete [font names]}
} -body {
# not (objc < 3)
font create xyz
font names
} -cleanup {
font delete xyz
} -result {xyz}
test font-6.3 {font command: create: name not really specified} -setup {
catch {eval font delete [font names]}
} -body {
# (name[0] == '-') so name = NULL
font create -family xyz
font names
} -cleanup {
font delete font1
} -result {font1}
test font-6.4 {font command: create: generate name} -setup {
catch {eval font delete [font names]}
} -body {
# (name == NULL)
font create -family one
font create -family two
font create -family three
font delete font2
font create -family four
font configure font2 -family
} -cleanup {
catch {eval font delete [font names]}
} -result {four}
test font-6.5 {font command: create: bad option creating new font} -setup {
catch {font delete xyz}
} -body {
# name was specified so skip = 3
font create xyz -xyz times
} -returnCodes error -result {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}
test font-6.6 {font command: create: bad option creating new font} -setup {
catch {eval font delete [font names]}
} -body {
# name was not specified so skip = 2
font create -xyz times
} -returnCodes error -result {bad option "-xyz": must be -family, -size, -weight, -slant, -underline, or -overstrike}
test font-6.7 {font command: create: already exists} -setup {
catch {font delete xyz}
} -body {
# (CreateNamedFont() != TCL_OK)
font create xyz
font create xyz
} -cleanup {
font delete xyz
} -returnCodes error -result {named font "xyz" already exists}
test font-7.1 {font command: delete: arguments} -body {
# (objc < 3)
font delete
} -returnCodes error -result {wrong # args: should be "font delete fontname ?fontname ...?"}
test font-7.2 {font command: delete: loop test} -setup {
catch {eval font delete [font names]}
set x {}
} -body {
# for (i = 2; i < objc; i++)
font create a -underline 1
font create b -underline 1
font create c -underline 1
font create d -underline 1
font create e -underline 1
lappend x [lsort [font names]]
font delete a e c b
lappend x [lsort [font names]]
} -cleanup {
catch {eval font delete [font names]}
} -result {{a b c d e} d}
test font-7.3 {font command: delete: loop test} -setup {
catch {eval font delete [font names]}
set x {}
} -body {
# (namedHashPtr == NULL) in middle of loop
font create a -underline 1
font create b -underline 1
font create c -underline 1
font create d -underline 1
font create e -underline 1
lappend x [lsort [font names]]
catch {font delete a d q c e b}
lappend x [lsort [font names]]
} -cleanup {
catch {eval font delete [font names]}
} -result {{a b c d e} {b c e}}
test font-7.4 {font command: delete: non-existent} -setup {
catch {font delete xyz}
} -body {
# (namedHashPtr == NULL)
font delete xyz
} -returnCodes error -result {named font "xyz" doesn't exist}
test font-7.5 {font command: delete: mark for later deletion} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# (nfPtr->refCount != 0)
font create xyz
.t.f configure -font xyz
font delete xyz
font actual xyz
font configure xyz
} -cleanup {
destroy .t.f
} -returnCodes error -result {named font "xyz" doesn't exist}
test font-7.6 {font command: delete: mark for later deletion} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# (nfPtr->refCount != 0)
font create xyz
.t.f configure -font xyz
font delete xyz
font actual xyz
catch {font configure xyz}
.t.f cget -font
} -cleanup {
destroy .t.f
} -result xyz
test font-7.7 {font command: delete: actually delete} -setup {
catch {font delete xyz}
} -body {
# not (nfPtr->refCount != 0)
font create xyz -underline 1
font delete xyz
font config xyz
} -returnCodes error -match glob -result {*}
test font-8.1 {font command: families: arguments} -body {
# (skip < 0)
font families -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-8.2 {font command: families: arguments} -body {
# (objc - skip != 2) when skip == 0
font families xyz
} -returnCodes error -result {wrong # args: should be "font families ?-displayof window?"}
test font-8.3 {font command: families: arguments} -body {
# (objc - skip != 2) when skip == 2
font families -displayof . xyz
} -returnCodes error -result {wrong # args: should be "font families ?-displayof window?"}
test font-8.4 {font command: families} -body {
# TkpGetFontFamilies()
regexp -nocase times [font families]
} -result 1
test font-9.1 {font command: measure: arguments} -body {
# (skip < 0)
expr {[font measure xyz -displayof] > 0}
} -returnCodes ok -result 1
test font-9.2 {font command: measure: arguments} -body {
# (objc - skip != 4)
font measure
} -returnCodes error -result {wrong # args: should be "font measure font ?-displayof window? text"}
test font-9.3 {font command: measure: arguments} -body {
# (objc - skip != 4)
font measure xyz abc def
} -returnCodes error -result {wrong # args: should be "font measure font ?-displayof window? text"}
test font-9.4 {font command: measure: arguments} -constraints noExceed -body {
# (tkfont == NULL)
font measure "\{xyz" abc
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-9.5 {font command: measure} -body {
# Tk_TextWidth()
expr {[font measure $fixed "abcdefg"] == [font measure $fixed "a"]*7 }
} -result 1
test font-9.6 {font command: measure -d} -body {
expr {[font measure $fixed -d] > 0}
} -returnCodes ok -result 1
test font-9.7 {font command: measure -d with -displayof} -body {
expr {[font measure $fixed -displayof . -d] > 0}
} -returnCodes ok -result 1
test font-9.8 {font command: measure: arguments} -body {
font measure $fixed -displayof .
} -returnCodes error -result {wrong # args: should be "font measure font ?-displayof window? text"}
test font-10.1 {font command: metrics: arguments} -body {
font metrics xyz -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-10.2 {font command: metrics: arguments} -body {
# (skip < 0)
font metrics xyz -displayof
} -returnCodes error -result {value for "-displayof" missing}
test font-10.3 {font command: metrics: arguments} -body {
# (objc < 3)
font metrics
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"}
test font-10.4 {font command: metrics: arguments} -body {
# (objc - skip) > 4) when skip == 0
font metrics xyz abc def
} -returnCodes error -result {wrong # args: should be "font metrics font ?-displayof window? ?option?"}
test font-10.5 {font command: metrics: arguments} -body {
# (objc - skip) > 4) when skip == 2
font metrics xyz -displayof . abc
} -returnCodes error -result {bad metric "abc": must be -ascent, -descent, -linespace, or -fixed}
test font-10.6 {font command: metrics: bad font} -constraints noExceed -body {
# (tkfont == NULL)
font metrics "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-10.7 {font command: metrics: get all metrics} -setup {
catch {unset a}
} -body {
# (objc == 3)
array set a [font metrics {-family xyz}]
lsort [array names a]
} -cleanup {
unset a
} -result {-ascent -descent -fixed -linespace}
test font-10.8 {font command: metrics: bad metric} -body {
# (Tcl_GetIndexFromObj() != TCL_OK)
font metrics $fixed -xyz
} -returnCodes error -result {bad metric "-xyz": must be -ascent, -descent, -linespace, or -fixed}
test font-10.9 {font command: metrics: get individual metrics} -body {
font metrics $fixed -ascent
font metrics $fixed -descent
font metrics $fixed -linespace
font metrics $fixed -fixed
} -result 1
test font-11.1 {font command: names: arguments} -body {
# (objc != 2)
font names xyz
} -returnCodes error -result {wrong # args: should be "font names"}
test font-11.2 {font command: names: loop test: no passes} -setup {
catch {eval font delete [font names]}
} -body {
font names
} -result {}
test font-11.3 {font command: names: loop test: one pass} -setup {
catch {eval font delete [font names]}
} -body {
font create
font names
} -result {font1}
test font-11.4 {font command: names: loop test: multiple passes} -setup {
catch {eval font delete [font names]}
} -body {
font create xyz
font create abc
font create def
lsort [font names]
} -cleanup {
catch {eval font delete [font names]}
} -result {abc def xyz}
test font-11.5 {font command: names: skip deletePending fonts} -setup {
destroy .t.f
catch {eval font delete [font names]}
pack [label .t.f]
update
set x {}
} -body {
# (nfPtr->deletePending == 0)
font create xyz
font create abc
lappend x [lsort [font names]]
.t.f config -font xyz
font delete xyz
lappend x [font names]
} -cleanup {
catch {eval font delete [font names]}
} -result {{abc xyz} abc}
test font-12.1 {UpdateDependantFonts procedure: no users} -setup {
catch {font delete xyz}
} -body {
# (nfPtr->refCount == 0)
font create xyz
font configure xyz -family times
} -cleanup {
font delete xyz
} -result {}
test font-12.2 {UpdateDependantFonts procedure: pings the widgets} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
font create xyz -family times -size 20
.t.f config -font xyz -text "abcd" -padx 0 -bd 0 -highlightthickness 0
set a1 [font measure xyz "abcd"]
update
set b1 [winfo reqwidth .t.f]
font configure xyz -family helvetica -size 20
set a2 [font measure xyz "abcd"]
update
set b2 [winfo reqwidth .t.f]
expr {$a1==$b1 && $a2==$b2}
} -cleanup {
destroy .t.f
font delete xyz
} -result {1}
test font-13.1 {CreateNamedFont: new named font} -setup {
catch {font delete xyz}
set x {}
} -body {
# not (new == 0)
lappend x [font names]
font create xyz
lappend x [font names]
} -cleanup {
font delete xyz
} -result {{} xyz}
test font-13.2 {CreateNamedFont: named font already exists} -setup {
catch {font delete xyz}
} -body {
# (new == 0)
font create xyz
font create xyz
} -cleanup {
font delete xyz
} -returnCodes error -result {named font "xyz" already exists}
test font-13.3 {CreateNamedFont: named font already exists} -setup {
catch {font delete xyz}
} -body {
# (nfPtr->deletePending == 0)
font create xyz
font create xyz
} -cleanup {
font delete xyz
} -returnCodes error -result {named font "xyz" already exists}
test font-13.4 {CreateNamedFont: recreate "deleted" font} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# not (nfPtr->deletePending == 0)
font create xyz -family times
.t.f configure -font xyz
font delete xyz
font create xyz -family courier
font configure xyz -family
} -cleanup {
font delete xyz
destroy .t.f
} -result {courier}
test font-14.1 {Tk_GetFont procedure} -body {
} -result {}
test font-15.1 {Tk_AllocFontFromObj - converting internal reps} -constraints {
testfont
} -setup {
destroy .b1 .b2
} -body {
set x {Times 16}
lindex $x 0
button .b1 -font $x
lindex $x 0
testfont counts {Times 16}
} -cleanup {
destroy .b1 .b2
} -result {{1 0}}
test font-15.2 {Tk_AllocFontFromObj - discard stale font} -constraints {
testfont
} -setup {
destroy .b1 .b2
set result {}
} -body {
set x {Times 16}
button .b1 -font $x
destroy .b1
lappend result [testfont counts {Times 16}]
button .b2 -font $x
lappend result [testfont counts {Times 16}]
} -cleanup {
destroy .b2
} -result {{} {{1 1}}}
test font-15.3 {Tk_AllocFontFromObj - reuse existing font} -constraints {
testfont
} -setup {
destroy .b1 .b2
set result {}
} -body {
set x {Times 16}
button .b1 -font $x
lappend result [testfont counts {Times 16}]
button .b2 -font $x
pack .b1 .b2 -side top
lappend result [testfont counts {Times 16}]
} -cleanup {
destroy .b1 .b2
} -result {{{1 1}} {{2 1}}}
test font-15.4 {Tk_AllocFontFromObj procedure: bump ref count} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# (new == 0)
.t.f config -font {-family fixed}
lindex [font actual {-family fixed}] 0
} -cleanup {
destroy .t.f
} -result {-family}
test font-15.5 {Tk_AllocFontFromObj procedure: get named font} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# (namedHashPtr != NULL)
font create xyz
.t.f config -font xyz
} -cleanup {
destroy .t.f
font delete xyz
} -result {}
test font-15.6 {Tk_AllocFontFromObj procedure: not a named font} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# not (namedHashPtr != NULL)
.t.f config -font {times 20}
} -cleanup {
destroy .t.f
} -result {-family} -result {}
test font-15.7 {Tk_AllocFontFromObj procedure: get native font} -constraints {
unix
} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# not (fontPtr == NULL)
.t.f config -font fixed
} -result {}
test font-15.8 {Tk_AllocFontFromObj procedure: get native font} -constraints {
win
} -setup {
destroy .t.f
catch {eval font delete [font names]}
pack [label .t.f]
update
} -body {
# not (fontPtr == NULL)
.t.f config -font oemfixed
} -cleanup {
destroy .t.f
} -result {}
test font-15.9 {Tk_AllocFontFromObj procedure: get attribute font} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# (fontPtr == NULL)
.t.f config -font {xxx yyy zzz}
} -cleanup {
destroy .t.f
} -returnCodes error -result {expected integer but got "yyy"}
test font-15.10 {Tk_AllocFontFromObj procedure: no match} -constraints noExceed -body {
# (ParseFontNameObj() != TCL_OK)
font actual "\{xyz"
} -returnCodes error -result "font \"{xyz\" doesn't exist"
test font-15.11 {Tk_AllocFontFromObj procedure: get attribute font} -body {
# not (ParseFontNameObj() != TCL_OK)
lindex [font actual {plan 9}] 0
} -result {-family}
test font-15.12 {Tk_AllocFontFromObj procedure: setup tab width} -setup {
destroy .l
} -body {
# Tk_MeasureChars(fontPtr, "0", ...)
label .l -bd 0 -padx 0 -highlightthickness 0 -font $fixed -text "a\tb"
update
set res1 [winfo reqwidth .l]
set res2 [expr [font measure $fixed "0"]*9]
expr {$res1 eq $res2}
} -cleanup {
destroy .l
} -result 1
test font-15.13 {Tk_AllocFontFromObj procedure: underline position} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# (fontPtr->underlineHeight == 0) because size was < 10
.t.f config -text "underline" -font "times -8 underline"
update
} -cleanup {
destroy .t.f
} -result {}
test font-16.1 {Tk_NameOfFont procedure} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
.t.f config -font -family\ fixed
.t.f cget -font
} -cleanup {
destroy .t.f
} -result {-family fixed}
test font-17.1 {Tk_FreeFontFromObj - reference counts} -constraints {
testfont
} -setup {
destroy .b1 .b2 .b3
set result {}
} -body {
set x {Courier 12}
button .b1 -font $x
button .b3 -font $x
button .b2 -font $x
lappend result [testfont counts {Courier 12}]
destroy .b1
lappend result [testfont counts {Courier 12}]
destroy .b2
lappend result [testfont counts {Courier 12}]
destroy .b3
lappend result [testfont counts {Courier 12}]
} -result {{{3 1}} {{2 1}} {{1 1}} {}}
test font-17.2 {Tk_FreeFont procedure: one ref} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
# (fontPtr->refCount == 0)
.t.f config -font {-family fixed}
destroy .t.f
} -result {}
test font-17.3 {Tk_FreeFont procedure: multiple ref} -setup {
destroy .t.f .t.b
pack [label .t.f]
update
} -body {
# not (fontPtr->refCount == 0)
.t.f config -font {-family fixed}
button .t.b -font {-family fixed}
destroy .t.f
.t.b cget -font
} -cleanup {
destroy .t.b
} -result {-family fixed}
test font-17.4 {Tk_FreeFont procedure: named font} -setup {
destroy .t.f
catch {eval font delete [font names]}
pack [label .t.f]
update
} -body {
# (fontPtr->namedHashPtr != NULL)
font create xyz
.t.f config -font xyz
destroy .t.f
font names
} -result {xyz}
test font-17.5 {Tk_FreeFont procedure: named font} -setup {
destroy .t.f
catch {font delete xyz}
pack [label .t.f]
update
} -body {
# not (fontPtr->refCount == 0)
font create xyz -underline 1
.t.f config -font xyz
font delete xyz
set x [font actual xyz -underline]
destroy .t.f
list [font actual xyz -underline] $x
} -result {0 1}
test font-17.6 {Tk_FreeFont procedure: named font not deleted yet} -setup {
destroy .t.f .t.b
catch {font delete xyz}
pack [label .t.f]
update
} -body {
font create xyz
.t.f config -font xyz
button .t.b -font xyz
font delete xyz
set x [font actual xyz]
destroy .t.b
list [lindex [font actual xyz] 0] [lindex $x 0]
} -cleanup {
destroy .t.f
} -result {-family -family}
test font-18.1 {FreeFontObjProc} -constraints testfont -setup {
destroy .b1
set result {}
} -body {
set x [format {Courier 12}]
button .b1 -font $x
set y [format {Courier 12}]
.b1 configure -font $y
set z [format {Courier 12}]
.b1 configure -font $z
lappend result [testfont counts {Courier 12}]
set x red
lappend result [testfont counts {Courier 12}]
set z 32
lappend result [testfont counts {Courier 12}]
destroy .b1
lappend result [testfont counts {Courier 12}]
set y bogus
return $result
} -result {{{1 3}} {{1 2}} {{1 1}} {}}
test font-19.1 {Tk_FontId} -setup {
destroy .t.f
pack [label .t.f]
update
} -body {
.t.f config -font "times 20"
update
} -cleanup {
destroy .t.f
} -result {}
test font-20.1 {Tk_GetFontMetrics procedure} -setup {
destroy .t.w1 .t.w2
} -body {
button .t.w1 -text abc
entry .t.w2 -text abcd
update
destroy .t.w1 .t.w2
} -result {}
# Procedure used in 21.* tests
proc psfontname {name} {
destroy .t.c
canvas .t.c -closeenough 0
.t.c create text 0 0 -tags text -anchor nw -just left -font "Courier -12"
pack .t.c
update
set a [.t.c itemcget text -font]
.t.c itemconfig text -text "We need text" -font $name
set post [.t.c postscript]
.t.c itemconfig text -font $a
set end [string first "findfont" $post]
incr end -2
set post [string range $post [expr $end-70] $end]
set start [string first "gsave" $post]
destroy .t.c
return [string range $post [expr $start+7] end]
}
test font-21.1 {Tk_PostscriptFontName procedure: native} -constraints {
unix
} -body {
set x [font actual {{itc avant garde} 10} -family]
if {[string match *avant*garde $x]} {
psfontname "{itc avant garde} 10"
} else {
set x {AvantGarde-Book}
}
} -result {AvantGarde-Book}
test font-21.2 {Tk_PostscriptFontName procedure: native} -constraints {
win
} -body {
psfontname "arial 10"
} -result {Helvetica}
test font-21.3 {Tk_PostscriptFontName procedure: native} -constraints {
win
} -body {
psfontname "{times new roman} 10"
} -result {Times-Roman}
test font-21.4 {Tk_PostscriptFontName procedure: native} -constraints {
win
} -body {
psfontname "{courier new} 10"
} -result {Courier}
test font-21.5 {Tk_PostscriptFontName procedure: spaces} -constraints {
unix
} -body {
set x [font actual {{lucida bright} 10} -family]
if {[string match lucida*bright $x]} {
psfontname "{lucida bright} 10"
} else {
set x {LucidaBright}
}
} -result {LucidaBright}
test font-21.6 {Tk_PostscriptFontName procedure: spaces} -constraints {
unix
} -body {
psfontname "{new century schoolbook} 10"
} -result {NewCenturySchlbk-Roman}
test font-21.7 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {avantgarde 12 roman normal}
if {[font actual {avantgarde 12 roman normal} -family] == "avantgarde"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x AvantGarde-Book
}
} -result {AvantGarde-Book}
test font-21.8 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {avantgarde 12 roman bold}
if {[font actual {avantgarde 12 roman normal} -family] == "avantgarde"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x AvantGarde-Demi
}
} -result {AvantGarde-Demi}
test font-21.9 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {avantgarde 12 italic normal}
if {[font actual {avantgarde 12 roman normal} -family] == "avantgarde"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x AvantGarde-BookOblique
}
} -result {AvantGarde-BookOblique}
test font-21.10 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {avantgarde 12 italic bold}
if {[font actual {avantgarde 12 roman normal} -family] == "avantgarde"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x AvantGarde-DemiOblique
}
} -result {AvantGarde-DemiOblique}
test font-21.11 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {bookman 12 roman normal}
if {[font actual {avantgarde 12 roman normal} -family] == "bookman"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Bookman-Light
}
} -result {Bookman-Light}
test font-21.12 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {bookman 12 roman bold}
if {[font actual {avantgarde 12 roman normal} -family] == "bookman"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Bookman-Demi
}
} -result {Bookman-Demi}
test font-21.13 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {bookman 12 italic normal}
if {[font actual {avantgarde 12 roman normal} -family] == "bookman"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Bookman-LightItalic
}
} -result {Bookman-LightItalic}
test font-21.14 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {bookman 12 italic bold}
if {[font actual {avantgarde 12 roman normal} -family] == "bookman"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Bookman-DemiItalic
}
} -result {Bookman-DemiItalic}
test font-21.15 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {courier 12 roman normal}
if {[font actual {avantgarde 12 roman normal} -family] == "courier"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Courier
}
} -result {Courier}
test font-21.16 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
unix
} -body {
set name {courier 12 roman bold}
if {[font actual {avantgarde 12 roman normal} -family] == "courier"} {
set x [psfontname avantgarde 12 roman normal]
} else {
set x Courier-Bold