Пример #1
0
func loadDictionaryFromFile(size int) (*gui.Dictionary, error) {
	name := fmt.Sprintf("dict_%d.gob", size)
	f, err := os.Open(filepath.Join(datadir, "fonts", name))
	var d *gui.Dictionary
	if err == nil {
		d, err = gui.LoadDictionary(f)
		f.Close()
	}
	return d, err
}
Пример #2
0
func GetDictionary(font string) *gui.Dictionary {
	dictionary_mutex.Lock()
	defer dictionary_mutex.Unlock()
	if font_dict == nil {
		font_dict = make(map[string]*gui.Dictionary)
	}
	if _, ok := font_dict[font]; !ok {
		path := filepath.Join(datadir, "fonts", font+".gob")
		f, err := os.Open(path)
		if err != nil {
			Error().Printf("Unable to open file '%s': %v\n", path, err)
			return nil
		}
		defer f.Close()
		dict, err := gui.LoadDictionary(f)
		if err != nil {
			Error().Printf("Unable to load dictionary from '%s': %v\n", path, err)
			return nil
		}
		font_dict[font] = dict
	}
	return font_dict[font]
}