fonts

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

README

go-opentype/fonts

CI Go Reference Go Report Card License

Six legible, permissively-licensed TrueType fonts, embedded as []byte payloads with a two-line API — no downloading, no sourcing a .ttf yourself. Built for go-opentype/opentype, the pure-Go, stdlib-only TrueType engine, but the raw bytes work with any parser that accepts a .ttf.

import (
	"github.com/go-opentype/fonts"
)

f, err := fonts.Parse(fonts.MostLegible()) // *opentype.Font
face := f.NewFace(16)                      // 16px face

Install

go get github.com/go-opentype/fonts

Pure Go, no cgo, no external assets to fetch at build or run time — the fonts are //go:embedded into the module.

Bundled fonts

Name Kind License Copyright Upstream
Atkinson Hyperlegible Sans OFL-1.1 Copyright 2020 Braille Institute of America, Inc. https://brailleinstitute.org/freefont
Inter Sans OFL-1.1 Copyright 2020 The Inter Project Authors https://github.com/rsms/inter
Go Sans BSD-3-Clause Copyright (c) 2016 Bigelow & Holmes Inc. All rights reserved. https://go.dev/blog/go-fonts
Lora Serif OFL-1.1 Copyright 2011 The Lora Project Authors, with Reserved Font Name "Lora" https://github.com/cyrealtype/Lora-Cyrillic
Go Mono Mono BSD-3-Clause Copyright (c) 2016 Bigelow & Holmes Inc. All rights reserved. https://go.dev/blog/go-fonts
JetBrains Mono Mono OFL-1.1 Copyright 2020 The JetBrains Mono Project Authors https://github.com/JetBrains/JetBrainsMono

Full license texts are bundled verbatim under licenses/: AtkinsonHyperlegible-OFL.txt, Inter-OFL.txt, Lora-OFL.txt, JetBrainsMono-OFL.txt (SIL Open Font License 1.1) and GoFonts-LICENSE.txt (BSD-3-Clause, Bigelow & Holmes).

Atkinson Hyperlegible is the standout pick when legibility itself is the goal: it was designed by the Braille Institute specifically to maximize character distinction for readers with low vision, benefiting every reader in the process. MostLegible() returns it.

Inter, Lora, and JetBrains Mono are variable fonts upstream; the bundled .ttf files are pinned at each family's default master (static instance). go-opentype has no variable-font support, so it always renders that default instance — OpenType Variations axes are not applied.

API

type Kind int

const (
	KindSans Kind = iota
	KindSerif
	KindMono
)

type Family struct {
	Name    string // e.g. "Atkinson Hyperlegible"
	Kind    Kind
	License string // SPDX id: "OFL-1.1" or "BSD-3-Clause"
	TTF     []byte // raw .ttf bytes
}

func AtkinsonHyperlegible() []byte
func Inter() []byte
func GoRegular() []byte
func Lora() []byte
func GoMono() []byte
func JetBrainsMono() []byte

func MostLegible() []byte                    // == AtkinsonHyperlegible()
func All() []Family                          // every bundled family, stable order
func ByName(name string) ([]byte, bool)      // case-insensitive lookup by Family.Name
func Parse(ttf []byte) (*opentype.Font, error) // convenience wrapper over opentype.Parse

See the full package documentation on pkg.go.dev.

License

The Go source code in this repository (everything outside ttf/ and licenses/) is BSD-3-Clause — see LICENSE.

The bundled font files keep their own upstream licenses; see the table above and licenses/ for the full texts, copyright notices, and (for the OFL fonts) their Reserved Font Names.

Documentation

Overview

Package fonts bundles several legible, permissively-licensed TrueType fonts as embedded []byte payloads, ready to feed into github.com/go-opentype/opentype without sourcing a font file yourself.

Six families are included: Atkinson Hyperlegible, Inter, Go, Lora, Go Mono and JetBrains Mono. Call All to enumerate them, an accessor such as AtkinsonHyperlegible or Inter to fetch one directly, ByName to look one up by name, or MostLegible for the family the Braille Institute designed specifically for maximum legibility (including for low-vision readers). Parse is a thin convenience wrapper around opentype.Parse.

Inter, Lora and JetBrains Mono are variable fonts upstream; the bundled .ttf files are pinned at each family's default master (static instance). go-opentype has no variable-font support, so it always renders that default instance — OpenType Variations axes are not applied.

The Go code in this repository is BSD-3-Clause (see LICENSE). Each bundled font keeps its own upstream license — see the "Bundled fonts" table in README.md and the full texts under licenses/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtkinsonHyperlegible

func AtkinsonHyperlegible() []byte

AtkinsonHyperlegible returns the raw TrueType bytes of Atkinson Hyperlegible Regular, designed by the Braille Institute for maximum legibility, including for low-vision readers. Licensed OFL-1.1.

func ByName

func ByName(name string) (ttf []byte, ok bool)

ByName looks up a bundled family by its Family.Name, case-insensitively. ok is false when no family matches.

func GoMono

func GoMono() []byte

GoMono returns the raw TrueType bytes of Go Mono, the Go project's monospace companion to Go Regular. Licensed BSD-3-Clause.

func GoRegular

func GoRegular() []byte

GoRegular returns the raw TrueType bytes of Go Regular, the Go project's screen sans-serif designed by Bigelow & Holmes. Licensed BSD-3-Clause.

func Inter

func Inter() []byte

Inter returns the raw TrueType bytes of Inter Regular, a UI sans-serif designed for computer screens. Licensed OFL-1.1.

Inter is a variable font upstream; the bundled file is pinned at its default master (static instance). go-opentype renders that default instance only — variation axes are not applied.

func JetBrainsMono

func JetBrainsMono() []byte

JetBrainsMono returns the raw TrueType bytes of JetBrains Mono Regular, a monospace face designed for code. Licensed OFL-1.1.

JetBrains Mono is a variable font upstream; the bundled file is pinned at its default master (static instance). go-opentype renders that default instance only — variation axes are not applied.

func Lora

func Lora() []byte

Lora returns the raw TrueType bytes of Lora Regular, a contemporary serif with roots in calligraphy. Licensed OFL-1.1.

Lora is a variable font upstream; the bundled file is pinned at its default master (static instance). go-opentype renders that default instance only — variation axes are not applied.

func MostLegible

func MostLegible() []byte

MostLegible returns Atkinson Hyperlegible, the bundled font with the strongest legibility credentials: it was designed by the Braille Institute specifically to maximize character distinction for readers with low vision, and it benefits every reader in the process. Prefer it whenever legibility, not brand voice, is the deciding factor.

func Parse

func Parse(ttf []byte) (*opentype.Font, error)

Parse decodes ttf (typically the return value of a Family accessor, or Family.TTF) into a *opentype.Font, ready for NewFace and rendering. It is a thin convenience wrapper around opentype.Parse:

f, err := fonts.Parse(fonts.MostLegible())

Types

type Family

type Family struct {
	Name    string // display name, e.g. "Atkinson Hyperlegible"
	Kind    Kind
	License string // SPDX identifier: "OFL-1.1" or "BSD-3-Clause"
	TTF     []byte // raw .ttf file contents, ready for opentype.Parse
}

Family describes one bundled font: its display name, general style, the SPDX identifier of the license it ships under, and its raw TrueType bytes.

func All

func All() []Family

All returns every bundled Family, in a stable order.

type Kind

type Kind int

Kind classifies a Family by its general letterform style.

const (
	// KindSans is an upright, low-contrast sans-serif.
	KindSans Kind = iota
	// KindSerif is a text serif.
	KindSerif
	// KindMono is a fixed-width (monospace) face.
	KindMono
)

func (Kind) String

func (k Kind) String() string

String returns the lower-case name of k ("sans", "serif", "mono"), or "unknown" for any other value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL