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

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  // Package gofont registers the Go fonts in the font registry.
     4  //
     5  // See https://blog.golang.org/go-fonts for a description of the
     6  // fonts, and the golang.org/x/image/font/gofont packages for the
     7  // font data.
     8  package gofont
     9  
    10  import (
    11  	"fmt"
    12  
    13  	"github.com/gop9/olt/gio/font"
    14  	"github.com/gop9/olt/gio/font/opentype"
    15  	"github.com/gop9/olt/gio/text"
    16  	"golang.org/x/image/font/gofont/gobold"
    17  	"golang.org/x/image/font/gofont/gobolditalic"
    18  	"golang.org/x/image/font/gofont/goitalic"
    19  	"golang.org/x/image/font/gofont/gomedium"
    20  	"golang.org/x/image/font/gofont/gomediumitalic"
    21  	"golang.org/x/image/font/gofont/gomono"
    22  	"golang.org/x/image/font/gofont/gomonobold"
    23  	"golang.org/x/image/font/gofont/gomonobolditalic"
    24  	"golang.org/x/image/font/gofont/gomonoitalic"
    25  	"golang.org/x/image/font/gofont/goregular"
    26  	"golang.org/x/image/font/gofont/gosmallcaps"
    27  	"golang.org/x/image/font/gofont/gosmallcapsitalic"
    28  )
    29  
    30  func Register() {
    31  	register(text.Font{}, goregular.TTF)
    32  	register(text.Font{Style: text.Italic}, goitalic.TTF)
    33  	register(text.Font{Weight: text.Bold}, gobold.TTF)
    34  	register(text.Font{Style: text.Italic, Weight: text.Bold}, gobolditalic.TTF)
    35  	register(text.Font{Weight: text.Medium}, gomedium.TTF)
    36  	register(text.Font{Weight: text.Medium, Style: text.Italic}, gomediumitalic.TTF)
    37  	register(text.Font{Variant: "Mono"}, gomono.TTF)
    38  	register(text.Font{Variant: "Mono", Weight: text.Bold}, gomonobold.TTF)
    39  	register(text.Font{Variant: "Mono", Weight: text.Bold, Style: text.Italic}, gomonobolditalic.TTF)
    40  	register(text.Font{Variant: "Mono", Style: text.Italic}, gomonoitalic.TTF)
    41  	register(text.Font{Variant: "Mono", Style: text.Italic}, gomonoitalic.TTF)
    42  	register(text.Font{Variant: "Smallcaps"}, gosmallcaps.TTF)
    43  	register(text.Font{Variant: "Smallcaps", Style: text.Italic}, gosmallcapsitalic.TTF)
    44  }
    45  
    46  func register(fnt text.Font, ttf []byte) {
    47  	face, err := opentype.Parse(ttf)
    48  	if err != nil {
    49  		panic(fmt.Sprintf("failed to parse font: %v", err))
    50  	}
    51  	fnt.Typeface = "Go"
    52  	font.Register(fnt, face)
    53  }