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
|
// text: prove the font layer draws glyphs on the raw screen.
package main
import (
"fmt"
"os"
"time"
"9front/gui/draw"
)
const fontpath = "/lib/font/bit/lucidasans/unicode.8.font"
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "text: %v\n", err)
os.Exit(1)
}
}
func run() error {
d, err := draw.Init("/dev")
if err != nil {
return err
}
defer d.Close()
scr := d.Screen
r := scr.Rect()
f, err := d.OpenFont(fontpath)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "text: font h=%d ascent=%d\n", f.Height, f.Ascent)
// acme's palette: a 25% mix over white, per allocimagemix.
bg, err := d.Color(0xFFFFEAFF)
if err != nil {
return err
}
ink, err := d.Color(0x000000FF)
if err != nil {
return err
}
rule, err := d.Color(0x99994CFF)
if err != nil {
return err
}
draw.Draw(scr, r, bg, nil, draw.ZP)
y := r.Min.Y + 20
for _, s := range []string{
"Go on Plan 9: glyphs from /lib/font/bit, no libdraw.",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz",
"0123456789 !@#$%^&*()-=[]{};'\\:\"|,./<>?",
"width(\"hello\") = " + fmt.Sprint(f.Width("hello")) + " px",
time.Now().Format("Mon 2 Jan 2006 15:04:05"),
} {
f.String(scr, draw.Point{X: r.Min.X + 20, Y: y}, ink, s)
y += int32(f.Height) + 6
}
draw.Draw(scr, draw.Rect(r.Min.X+20, y+8, r.Min.X+520, y+9), rule, nil, draw.ZP)
d.Flush()
time.Sleep(90 * time.Second)
return nil
}
|