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
|
############################################################################
#
# File: fontpick.icn
#
# Subject: Program to show the characters of a font
#
# Author: Gregg M. Townsend
#
# Date: August 23, 1995
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# Usage: fontpick [fontname]
#
# fontpick is an interactive tool for displaying fonts. Initially, the
# specified font, or the VIB default font, is displayed. To display a
# different font, type its name and press return. To exit, enter Meta-Q
# or click the QUIT button.
#
# Caveats:
# -- any character that is too large is clipped to fit its cell
# -- the window cannot be resized to handle large fonts
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: vsetup
#
############################################################################
link vsetup
global vidgets
# main procedure
procedure main(args)
Window ! put(ui_atts(), args)
vidgets := ui()
setfont(, args[1] | Font()) # display named or default font
repeat ProcessEvent(vidgets["root"], other)
end
# setfont(vidget, value) -- display the font named "value"
procedure setfont(vidget, value)
local ttl, sub, rgn, fontname, x, y, w, h, win
# ignore return if no name has been entered
if *value = 0 then
return
# get vidget handles
ttl := vidgets["title"]
sub := vidgets["subtitle"]
rgn := vidgets["region"]
# display font name in title region
EraseArea(ttl.ux, ttl.uy, ttl.uw, ttl.uh)
EraseArea(sub.ux, sub.uy, sub.uw, sub.uh)
CenterString(ttl.ux + ttl.uw / 2, ttl.uy + ttl.uh / 2, value)
# open and display the font
EraseArea(rgn.ux, rgn.uy, rgn.uw, rgn.uh)
if win := Clone("font=" || value) then {
dumpfont(win, rgn.ux, rgn.uy, rgn.uw, rgn.uh)
fontname := Font(win)
if fontname ~== value then
CenterString(sub.ux + sub.uw / 2, sub.uy + sub.uh / 2, fontname)
}
else {
CenterString(sub.ux + sub.uw / 2, sub.uy + sub.uh / 2,
"(cannot find font)")
}
# clear the text entry field to accept the next name
VSetState(vidgets["fontname"], "")
return
end
# dumpfont(win, x, y, w, h) -- display the characters of a font
procedure dumpfont(win, x, y, w, h)
local dx, dy, x1, x2, y1, y2, i, j
# calculate size of cells
dx := (w - 1.001) / 16.0
dy := (h - 1.001) / 16.0
# draw light gray lines to delimit character cells
Fg("light gray")
every x1 := x + integer(dx * (1 to 15)) do
DrawLine(x1, y, x1, y + h - 1)
every y1 := y + integer(dy * (1 to 15)) do
DrawLine(x, y1, x + w - 1, y1)
Fg("black")
# display characters, one per cell
every i := 0 to 15 do {
y1 := integer(y + i * dy)
y2 := integer(y + (i + 1) * dy)
every j := 0 to 15 do {
x1 := integer(x + j * dx)
x2 := integer(x + (j + 1) * dx)
Clip(win, x1 + 1, y1 + 1, x2 - x1 - 1, y2 - y1 - 1)
CenterString(win, (x1 + x2) / 2, (y1 + y2) / 2, char(16 * i + j))
}
}
return
end
# revent(v, e, x, y) -- pass region event to font name vidget
procedure revent(v, e, x, y)
return VEvent(vidgets["fontname"], e, x, y)
end
# other(e) -- pass event outside of regions to font name vidget
#
# Also handles meta-Q event rejected by other vidgets.
procedure other(e)
if &meta & map(e) == "q" then
exit()
return VEvent(vidgets["fontname"], e, &x, &y)
end
# quit() -- process QUIT button
procedure quit()
exit()
end
#===<<vib:begin>>=== modify using vib; do not remove this marker line
procedure ui_atts()
return ["size=512,640", "bg=pale gray"]
end
procedure ui(win, cbk)
return vsetup(win, cbk,
[":Sizer:::0,0,512,640:",],
["fontname:Text::51:5,616,444,19:font name: \\=",setfont],
["quit:Button:regular::471,615,35,20:QUIT",quit],
["subtitle:Rect:invisible::7,31,496,25:",revent],
["title:Rect:invisible::7,6,496,25:",revent],
["region:Rect:sunken::8,56,492,553:",revent],
)
end
#===<<vib:end>>=== end of section maintained by vib
|