Esempio n. 1
0
func (f *Fonts) AddFont(filePath string) error {
	fontBytes, err := ioutil.ReadFile(filePath)
	if err != nil {
		return err
	}

	font, err := truetype.Parse(fontBytes)
	if err != nil {
		return err
	}
	f.files = append(f.files, filePath)
	f.objects[filePath] = font

	return nil
}
Esempio n. 2
0
//AddFont will add a new font file to the list
func (fm *FontManager) AddFont(pathToFontFile string) error {
	fontBytes, err := ioutil.ReadFile(pathToFontFile)
	if err != nil {
		return err
	}

	font, err := truetype.Parse(fontBytes)

	if err != nil {
		return err
	}
	fm.fontFiles = append(fm.fontFiles, pathToFontFile)
	fm.fontObjects[pathToFontFile] = font

	return nil
}
Esempio n. 3
0
// ParseFont just calls the Parse function from the freetype/truetype package.
// It is provided here so that code that imports this package doesn't need
// to also include the freetype/truetype package.
func ParseFont(b []byte) (*truetype.Font, error) {
	return truetype.Parse(b)
}