github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/font/font.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // Package font implements a central font registry.
     4  package font
     5  
     6  import (
     7  	"sync"
     8  
     9  	"github.com/gop9/olt/gio/text"
    10  )
    11  
    12  var (
    13  	mu          sync.Mutex
    14  	initialized bool
    15  	shaper      = new(text.Shaper)
    16  )
    17  
    18  // Default returns a singleton *text.Shaper that contains
    19  // the registered fonts.
    20  func Default() *text.Shaper {
    21  	mu.Lock()
    22  	defer mu.Unlock()
    23  	initialized = true
    24  	return shaper
    25  }
    26  
    27  // Register a face. Register panics if Default has been
    28  // called.
    29  func Register(font text.Font, face text.Face) {
    30  	mu.Lock()
    31  	defer mu.Unlock()
    32  	if initialized {
    33  		panic("Register must be called before Default")
    34  	}
    35  	shaper.Register(font, face)
    36  }