MCPcopy
hub / github.com/tdewolff/canvas / LoadFont

Function LoadFont

font.go:274–305  ·  view source on GitHub ↗

LoadFont loads a font from memory.

(b []byte, index int, style FontStyle)

Source from the content-addressed store, hash-verified

272
273// LoadFont loads a font from memory.
274func LoadFont(b []byte, index int, style FontStyle) (*Font, error) {
275 SFNT, err := font.ParseSFNT(b, index)
276 if err != nil {
277 return nil, err
278 }
279
280 shaper, err := text.NewShaperSFNT(SFNT)
281 if err != nil {
282 return nil, err
283 }
284
285 name := ""
286NameLoop:
287 for _, id := range []int{6, 4, 1} {
288 for _, record := range SFNT.Name.Get(font.NameID(id)) {
289 name = record.String()
290 break NameLoop
291 }
292 }
293 if name == "" {
294 name = fmt.Sprintf("f%d", nonameFonts)
295 nonameFonts++
296 }
297
298 font := &Font{
299 SFNT: SFNT,
300 name: name,
301 style: style,
302 shaper: shaper,
303 }
304 return font, nil
305}
306
307// Destroy should be called when using HarfBuzz to free the C resources.
308func (f *Font) Destroy() {

Callers 3

LoadFontFileFunction · 0.85
LoadFontCollectionFunction · 0.85
LoadFontMethod · 0.85

Calls 3

NewShaperSFNTFunction · 0.92
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected