...
Package plan9font
In the call graph viewer below, each node
is a function belonging to this package
and its children are the functions it
calls—perhaps dynamically.
The root nodes are the entry points of the
package: functions that may be called from
outside the package.
There may be non-exported or anonymous
functions among them if they are called
dynamically from another package.
Click a node to visit that function's source code.
From there you can visit its callers by
clicking its declaring func
token.
Functions may be omitted if they were
determined to be unreachable in the
particular programs or tests that were
analyzed.
func ParseFont(data []byte, readFile func(relFilename string) ([]byte, error)) (font.Face, error)
ParseFont parses a Plan 9 font file. data is the contents of that font file,
which gives relative filenames for subfont files. readFile returns the
contents of those subfont files. It is similar to io/ioutil's ReadFile
function, except that it takes a relative filename instead of an absolute
one.
▾ Example
Code:
readFile := func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.FromSlash(path.Join("../testdata/fixed", name)))
}
fontData, err := readFile("unicode.7x13.font")
if err != nil {
log.Fatal(err)
}
face, err := plan9font.ParseFont(fontData, readFile)
if err != nil {
log.Fatal(err)
}
ascent := face.Metrics().Ascent.Ceil()
dst := image.NewRGBA(image.Rect(0, 0, 4*7, 13))
draw.Draw(dst, dst.Bounds(), image.Black, image.Point{}, draw.Src)
d := &font.Drawer{
Dst: dst,
Src: image.White,
Face: face,
Dot: fixed.P(0, ascent),
}
d.DrawString("SΣ∫さ")
var out []byte
b := dst.Bounds()
for y := b.Min.Y; y < b.Max.Y; y++ {
out = append(out, '0'+byte(y%10), ' ')
for x := b.Min.X; x < b.Max.X; x++ {
if dst.RGBAAt(x, y).R > 0 {
out = append(out, 'X')
} else {
out = append(out, '.')
}
}
if y == ascent-1 {
out = append(out, '_')
}
out = append(out, '\n')
}
os.Stdout.Write(out)
Output:
0 ..................X.........
1 .................X.X........
2 .XXXX..XXXXXX....X.....XXX..
3 X....X.X.........X....XX.XX.
4 X.......X........X....X.X.X.
5 X........X.......X....XXX.X.
6 .XXXX.....X......X....XX.XX.
7 .....X...X.......X....XX.XX.
8 .....X..X........X....XXXXX.
9 X....X.X.........X....XX.XX.
0 .XXXX..XXXXXX....X.....XXX.._
1 ...............X.X..........
2 ................X...........
func ParseSubfont(data []byte, firstRune rune) (font.Face, error)
ParseSubfont parses a Plan 9 subfont file.
firstRune is the first rune in the subfont file. For example, the
Phonetic.6.0 subfont, containing glyphs in the range U+0250 to U+02E9, would
set firstRune to '\u0250'.