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
|
############################################################################
#
# File: tryfont.icn
#
# Subject: Program to demonstrate X font rankings
#
# Author: Gregg M. Townsend
#
# Date: July 18, 1995
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# tryfont repeatedly reads a font specification from standard input
# and displays, with their scores, a windowfull of available fonts that
# best match that specification. The window can be resized when tryfont
# is paused at a prompt; the new size is used for the next list.
#
# Note that tryfont uses the library procedure BestFont() for ranking;
# this can differ from the rankings used by the Icon runtime system's
# font selection logic.
#
# tryfont can also be run in ASCII mode, without using X windows, by
# passing a file name as a command argument. The file should contain
# a list of X fonts, such as from the xlsfonts program. The number of
# fonts printed on standard output can be specified as a second argument.
#
# For details of font specifications, see BestFont().
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: options, optwindw, xbfont, graphics
#
############################################################################
link options
link optwindw
link xbfont
link graphics
procedure main(args)
if *args > 0 & args[1][1] ~== "-" then
filemode(args)
else
windowmode(args)
end
procedure filemode(args)
local fname, limit, f, fontlist, request, a
fname := args[1]
limit := integer(args[2]) | 20
f := open(fname) | stop("can't open ", fname)
every put(fontlist := [], !f)
repeat {
writes("> ")
request := trim(read()) | return
if *request = 0 then
next
every a := RankFonts(fontlist, request) \ limit do
write(right(a.val, 5), "\t", a.str)
write()
}
end
procedure windowmode(args)
local opts, win, fwin, request, a, h, y
opts := options(args, winoptions())
/opts["W"] := 900
/opts["H"] := 300
/opts["M"] := -1
win := optwindow(opts, "cursor=off", "echo=off")
fwin := Clone(win)
&error := 1
WAttrib(win, "resize=on")
&error := 0
repeat {
writes("> ")
request := trim(read()) | return
if *request = 0 then
next
h := WAttrib(win, "height")
y := 0
EraseArea(win)
every a := RankFonts(win, request) do {
Font(fwin, a.str)
y +:= WAttrib(fwin, "fheight") - WAttrib(fwin, "descent")
GotoXY(win, 10, y)
writes(win, right(a.val, 4), " ")
writes(fwin, a.str)
y +:= WAttrib(fwin, "descent")
if y >= h then
break
}
}
end
|