func setupFontDictionaries(sizes ...int) { dictionary_mutex.Lock() defer dictionary_mutex.Unlock() if font_dict == nil { font_dict = make(map[int]*gui.Dictionary) } font, err := loadFont() if err != nil { Error().Fatalf("Failed to load font: %v", err) } // render.Init() for _, size := range sizes { d, err := loadDictionaryFromFile(size) if err == nil { font_dict[size] = d } else { d = gui.MakeDictionary(font, size) font_dict[size] = d err = saveDictionaryToFile(d, size) if err != nil { Warn().Printf("Unable to save dictionary (%d) to file: %v\n", size, err) } } } }
func GetDictionary(size int) *gui.Dictionary { dictionary_mutex.Lock() defer dictionary_mutex.Unlock() if font_dict == nil { font_dict = make(map[int]*gui.Dictionary) } if _, ok := font_dict[size]; !ok { d, err := loadDictionaryFromFile(size) if err == nil { font_dict[size] = d } else { Warn().Printf("Unable to load dictionary (%d) from file: %v", size, err) font, err := loadFont() if err != nil { Error().Fatalf("Unable to load font: %v", err) } d = gui.MakeDictionary(font, size) err = saveDictionaryToFile(d, size) if err != nil { Warn().Printf("Unable to save dictionary (%d) to file: %v", size, err) } font_dict[size] = d } } return font_dict[size] }