9fans.net/go@v0.0.5/draw/subfont.go (about) 1 package draw 2 3 // AllocSubfont allocates a subfont on the server. The subfont will have the 4 // specified name, total height, ascent (height above the baseline), and 5 // character info. 6 func (d *Display) _AllocSubfont(name string, height, ascent int, info []Fontchar, i *Image) *subfont { 7 d.mu.Lock() 8 defer d.mu.Unlock() 9 return d.allocSubfont(name, height, ascent, info, i) 10 } 11 12 func (d *Display) allocSubfont(name string, height, ascent int, info []Fontchar, i *Image) *subfont { 13 f := &subfont{ 14 Name: name, 15 N: len(info) - 1, 16 Height: height, 17 Ascent: ascent, 18 Bits: i, 19 ref: 1, 20 Info: info, 21 } 22 if name != "" { 23 /* 24 * if already caching this subfont, leave older 25 * (and hopefully more widely used) copy in cache. 26 * this case should not happen -- we got called 27 * because cachechars needed this subfont and it 28 * wasn't in the cache. 29 */ 30 cf := lookupsubfont(i.Display, name) 31 if cf == nil { 32 installsubfont(name, f) 33 } else { 34 cf.free() /* drop ref we just picked up */ 35 } 36 } 37 return f 38 }