summaryrefslogtreecommitdiff
path: root/tk/tests/macFont.test
blob: 667f2f7afa4dd09e3bde7b21264e15455d75c23e (plain)
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
# This file is a Tcl script to test out the procedures in tkMacFont.c. 
# It is organized in the standard fashion for Tcl tests.
#
# Some 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.  
#
# Copyright (c) 1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
# RCS: @(#) $Id$

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

catch {destroy .b}
toplevel .b
update idletasks

set courier {Courier 12}
set cx [font measure $courier 0]

set fixed {Monaco 12}
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]"
}

testConstraint gothic 0
set gothic {gothic 12}
set mx [font measure  $gothic \u4e4e]
if {[font actual $gothic -family] != [font actual system -family]} {
    testConstraint gothic 1
}

test macFont-1.1 {TkpFontPkgInit} {macOnly} {
} {}

test macfont-2.1 {TkpGetNativeFont: not native} {macOnly} {
    list [catch {font measure {} xyz} msg] $msg
} {1 {font "" doesn't exist}}
test macFont-2.2 {TkpGetNativeFont: native} {macOnly} {
    font measure system "0"
    font measure application "0"
    set x {}
} {}

test macFont-3.1 {TkpGetFontFromAttributes: no family} {macOnly} {
    font actual {-underline 1} -family
} [font actual system -family]
test macFont-3.2 {TkpGetFontFromAttributes: long family name} {macOnly} {
    set x "12345678901234567890123456789012345678901234567890"
    set x "$x$x$x$x$x$x"
    font actual "-family $x" -family
} [font actual system -family]
test macFont-3.3 {TkpGetFontFromAttributes: family} {macOnly} {
    font actual {-family Courier} -family
} {Courier}
test macFont-3.4 {TkpGetFontFromAttributes: Times fonts} {macOnly} {
    set x {}
    lappend x [font actual {-family "Times"} -family]
    lappend x [font actual {-family "Times New Roman"} -family]
} {Times Times}
test macFont-3.5 {TkpGetFontFromAttributes: Courier fonts} {macOnly} {
    set x {}
    lappend x [font actual {-family "Courier"} -family]
    lappend x [font actual {-family "Courier New"} -family]
} {Courier Courier}
test macFont-3.6 {TkpGetFontFromAttributes: Helvetica fonts} {macOnly} {
    set x {}
    lappend x [font actual {-family "Geneva"} -family]
    lappend x [font actual {-family "Helvetica"} -family]
    lappend x [font actual {-family "Arial"} -family]
} {Geneva Helvetica Helvetica}
test macFont-3.7 {TkpGetFontFromAttributes: try aliases} {macOnly} {
    font actual {arial 10} -family
} {Helvetica}    
test macFont-3.8 {TkpGetFontFromAttributes: try fallbacks} {macOnly} {
    font actual {{ms sans serif} 10} -family
} {Chicago}
test macFont-3.9 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-weight normal} -weight
} {normal}
test macFont-3.10 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-weight bold} -weight
} {bold}
test macFont-3.11 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-slant roman} -slant
} {roman}
test macFont-3.12 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-slant italic} -slant
} {italic}
test macFont-3.13 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-underline false} -underline
} {0}
test macFont-3.14 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-underline true} -underline
} {1}
test macFont-3.15 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-overstrike false} -overstrike
} {0}
test macFont-3.16 {TkpGetFontFromAttributes: styles} {macOnly} {
    font actual {-overstrike true} -overstrike
} {0}

test macFont-4.1 {TkpDeleteFont} {macOnly} {
    font actual {-family xyz}
    set x {}
} {}

test macFont-5.1 {TkpGetFontFamilies} {macOnly} {
    expr {[lsearch [font families] Geneva] > 0}
} {1}

test macFont-6.1 {TkpGetSubFonts} {testfont gothic macOnly} {
    .b.l config -text "abc\u4e4e" 
    update
    set x [testfont subfonts $fixed]
} "Monaco [font actual $gothic -family]"    

test macFont-7.1 {Tk_MeasureChars: unbounded right margin} {macOnly} {
    .b.l config -wrap 0 -text "000000"
    getsize
} "[expr $ax*6] $ay"
test macFont-7.2 {Tk_MeasureChars: static width buffer exceeded} {macOnly} {
    .b.l config -wrap 100000 -text "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    getsize
} "[expr $ax*256] $ay"
test macFont-7.3 {Tk_MeasureChars: all chars did fit} {macOnly} {
    .b.l config -wrap [expr $ax*10] -text "00000000"
    getsize
} "[expr $ax*8] $ay"
test macFont-7.4 {Tk_MeasureChars: not all chars fit} {macOnly} {
    .b.l config -wrap [expr $ax*6] -text "00000000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test macFont-7.5 {Tk_MeasureChars: already saw space in line} {macOnly} {
    .b.l config -wrap [expr $ax*12] -text "000000    0000000"
    getsize
} "[expr $ax*7] [expr $ay*2]"
test macFont-7.6 {Tk_MeasureChars: internal spaces significant} {macOnly} {
    .b.l config -wrap [expr $ax*12] -text "000  00   00000"
    getsize
} "[expr $ax*7] [expr $ay*2]"
test macFont-7.7 {Tk_MeasureChars: include last partial char} {macOnly} {
    .b.c dchars $t 0 end
    .b.c insert $t 0 "0000"
    .b.c index $t @[expr int($ax*2.5)],1
} {2}
test macFont-7.8 {Tk_MeasureChars: at least one char on line} { macOnly} {
    .b.l config -text "000000" -wrap 1
    getsize
} "$ax [expr $ay*6]"
test macFont-7.9 {Tk_MeasureChars: whole words} {macOnly} {
    .b.l config -wrap [expr $ax*8] -text "000000 0000"
    getsize
} "[expr $ax*6] [expr $ay*2]"
test macFont-7.10 {Tk_MeasureChars: make first part of word fit} {macOnly} {
    .b.l config -wrap [expr $ax*12] -text "0000000000000000"
    getsize
} "[expr $ax*12] [expr $ay*2]"
test macFont-7.11 {Tk_MeasureChars: numBytes == 0} {macOnly} {
    font measure system {}
} {0}
test macFont-7.12 {Tk_MeasureChars: maxLength < 0} {macOnly} {
    font measure $courier abcd
} "[expr $cx*4]"
test macFont-7.13 {Tk_MeasureChars: loop on each char} {macOnly} {
    font measure $courier abcd
} "[expr $cx*4]"
test macFont-7.14 {Tk_MeasureChars: p == end} {macOnly} {
    font measure $courier abcd
} "[expr $cx*4]"
test macFont-7.15 {Tk_MeasureChars: p > end} {macOnly} {
    font measure $courier abc\xc2
} "[expr $cx*4]"
test macFont-7.16 {Tk_MeasureChars: thisFamilyPtr != lastFamilyPtr} {gothic macOnly} {
    font measure $courier abc\u4e4edef
} [expr $cx*6+$mx]
test macFont-7.17 {Tk_MeasureChars: measure no chars (in loop)} {gothic macOnly} {
    font measure $courier \u4e4edef
} [expr $mx+$cx*3]
test macFont-7.18 {Tk_MeasureChars: final measure} {gothic macOnly} {
    font measure $courier \u4e4edef
} [expr $mx+$cx*3]
test macFont-7.19 {Tk_MeasureChars: final measure (no chars)} {gothic macOnly} {
    font measure $courier \u4e4e
} [expr $mx]
test macFont-7.20 {Tk_MeasureChars: maxLength >= 0} {macOnly} {
    .b.l config -wrap [expr $ax*8] -text "000"
    getsize
} "[expr $ax*3] $ay"
test macFont-7.21 {Tk_MeasureChars: loop on each char} {macOnly} {
    .b.l config -wrap [expr $ax*8] -text "000"
    getsize
} "[expr $ax*3] $ay"
test macFont-7.22 {Tk_MeasureChars: p == end} {macOnly} {
    .b.l config -wrap [expr $ax*8] -text "000"
    getsize
} "[expr $ax*3] $ay"
test macFont-7.23 {Tk_MeasureChars: p > end} {macOnly} {
    .b.l config -wrap [expr $ax*8] -text "00\xc2"
    getsize
} "[expr $ax*3] $ay"
test macFont-7.24 {Tk_MeasureChars: thisFamilyPtr != lastFamilyPtr} {gothic macOnly} {
    .b.l config -wrap [expr $ax*8] -text "00\u4e4e00"
    getsize
} "[expr $ax*4+$mx] $ay"
test macFont-7.25 {Tk_MeasureChars: measure no chars (in loop)} {gothic macOnly} {
    .b.l config -wrap [expr $ax*8] -text "\u4e4e00"
    getsize
} "[expr $mx+$ax*2] $ay"
test macFont-7.26 {Tk_MeasureChars: rest == NULL} {gothic macOnly} {
    .b.l config -wrap [expr $ax*20] -text "000000\u4e4e\u4e4e00"
    getsize
} "[expr $ax*8+$mx*2] $ay"
test macFont-7.27 {Tk_MeasureChars: rest != NULL in first segment} {gothic macOnly} {
    .b.l config -wrap [expr $ax*5] -text "000000\u4e4e\u4e4f00"
    getsize
} "[expr $ax*5] [expr $ay*3]"
test macFont-7.28 {Tk_MeasureChars: rest != NULL in next segment} {gothic macOnly} {
    # even some of the "0"s would fit after \u4e4d, they should all wrap to next line.  
    .b.l config -wrap [expr $ax*8] -text "\u4e4d\u4e4d000000\u4e4e\u4e4f00"
    getsize
} "[expr $ax*6+$mx] [expr $ay*3]"
test macFont-7.29 {Tk_MeasureChars: final measure} {gothic macOnly} {
    .b.l config -wrap [expr $ax*8] -text "\u4e4e00"
    getsize
} "[expr $mx+$ax*2] $ay"
test macFont-7.30 {Tk_MeasureChars: final measure (no chars)} {gothic macOnly} {
    .b.l config -wrap [expr $ax*8] -text "\u4e4e"
    getsize
} "$mx $ay"
test macFont-7.31 {Tk_MeasureChars: rest == NULL} {macOnly} {
    .b.l config -wrap [expr $ax*1000] -text 0000
    getsize
} "[expr $ax*4] $ay"
test macFont-7.32 {Tk_MeasureChars: rest != NULL} {macOnly} {
    .b.l config -wrap [expr $ax*6] -text "00000000"
    getsize
} "[expr $ax*6] [expr $ay*2]"

test macFont-8.1 {Tk_DrawChars procedure} {macOnly} {
    .b.l config -text "a"
    update
} {}

test macFont-9.1 {AllocMacFont: use old font} {macOnly} {
    font create xyz
    button .c -font xyz
    font configure xyz -family times
    update
    destroy .c
    font delete xyz
} {}
test macFont-9.2 {AllocMacFont: extract info from style} {macOnly} {
    font actual {Monaco 9 bold italic underline overstrike}
} {-family Monaco -size 9 -weight bold -slant italic -underline 1 -overstrike 0}
test macFont-9.3 {AllocMacFont: extract text metrics} {macOnly} {
    font metric {Geneva 10} -fixed
} {0}
test macFont-9.4 {AllocMacFont: extract text metrics} {macOnly} {
    font metric "Monaco 9" -fixed
} {1}

destroy .b

# cleanup
::tcltest::cleanupTests
return