Add adds a whole collection of font Faces to the font cache. If the cache is empty, the first font Face in the collection is set to be the default one.
(coll Collection)
| 222 | // If the cache is empty, the first font Face in the collection is set |
| 223 | // to be the default one. |
| 224 | func (c *Cache) Add(coll Collection) { |
| 225 | c.mu.Lock() |
| 226 | defer c.mu.Unlock() |
| 227 | |
| 228 | if c.faces == nil { |
| 229 | c.faces = make(map[Font]*opentype.Font, len(coll)) |
| 230 | } |
| 231 | for i, f := range coll { |
| 232 | if i == 0 && c.def == "" { |
| 233 | c.def = f.Font.Typeface |
| 234 | } |
| 235 | fnt := f.Font |
| 236 | fnt.Size = 0 // store all font descriptors with the same size. |
| 237 | c.faces[fnt] = f.Face |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // Lookup returns the font Face corresponding to the provided Font descriptor, |
| 242 | // with the provided font size set. |