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
|
// Copyright ©2017 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !js
package vg
import (
"go/build"
"os"
"path/filepath"
)
const (
// importString is the import string expected for
// this package. It is used to find the font
// directory included with the package source.
importString = "gonum.org/v1/plot/vg"
)
func init() {
FontDirs = initFontDirs()
}
// InitFontDirs returns the initial value for the FontDirectories variable.
func initFontDirs() []string {
dirs := filepath.SplitList(os.Getenv("VGFONTPATH"))
if pkg, err := build.Import(importString, "", build.FindOnly); err == nil {
p := filepath.Join(pkg.Dir, "fonts")
if _, err := os.Stat(p); err == nil {
dirs = append(dirs, p)
}
}
if len(dirs) == 0 {
dirs = []string{"./fonts"}
}
return dirs
}
|