fonts

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AxisWeight      = "wght" // Weight axis
	AxisWidth       = "wdth" // Width axis
	AxisSlant       = "slnt" // Slant axis
	AxisItalic      = "ital" // Italic axis
	AxisOpticalSize = "opsz" // Optical size axis
	AxisTexture     = "TXTR" // Texture healing
	AxisLigatures   = "liga" // Ligatures
)

Common variable font axis tags

View Source
const (
	MonaspaceWeightMin = 200
	MonaspaceWeightMax = 800
	MonaspaceWidthMin  = 100
	MonaspaceWidthMax  = 125
	MonaspaceSlantMin  = -11
	MonaspaceSlantMax  = 1
)

Monaspace specific ranges

Variables

This section is empty.

Functions

func ClearCache

func ClearCache()

ClearCache clears the font cache

func FontFS

func FontFS() fs.FS

FontFS returns a filesystem containing all available fonts

func IsFontAvailable

func IsFontAvailable(name string) bool

IsFontAvailable is a super fast check to see if the given font is available on the system

func ListFonts

func ListFonts() []string

Types

type FallbackVariant added in v0.3.0

type FallbackVariant string

FallbackVariant represents the type of fallback font to use

const (
	FallbackSans FallbackVariant = "sans"
	FallbackMono FallbackVariant = "mono"
)

type Font

type Font struct {
	Name     string         // Name of the font family
	Font     *opentype.Font // Parsed font
	Style    FontStyle      // Style information for this font variant
	FilePath string         // Path to the font file on disk
	Filename string         // Name of the font file
}

Font represents a loaded font with its metadata

func GetFallback

func GetFallback(variant FallbackVariant) (*Font, error)

GetFallback returns either Monaspace Argon or Neon as the fallback font

func GetFont

func GetFont(name string, style *FontStyle) (*Font, error)

func GetFontVariants

func GetFontVariants(name string) ([]*Font, error)

func (*Font) GetFontFace

func (f *Font) GetFontFace(size float64) (font.Face, error)

GetFontFace returns a font.Face with the specified size

func (*Font) ToTrueType

func (f *Font) ToTrueType() (*truetype.Font, error)

ToTrueType converts the opentype.Font to a truetype.Font

type FontStyle

type FontStyle struct {
	Weight     FontWeight         // Font weight
	Italic     bool               // Whether the font is italic
	Condensed  bool               // Whether the font is condensed
	Mono       bool               // Whether the font is monospaced
	Variations map[string]float32 // Variable font variations
}

FontStyle represents the style of a font

type FontWeight

type FontWeight int

FontWeight represents the weight of a font

const (
	WeightThin       FontWeight = iota + 1 // Thinnest font weight
	WeightExtraLight                       // Extra light font weight
	WeightLight                            // Light font weight
	WeightRegular                          // Regular (normal) font weight
	WeightMedium                           // Medium font weight
	WeightSemiBold                         // Semi-bold font weight
	WeightBold                             // Bold font weight
	WeightExtraBold                        // Extra bold font weight
	WeightBlack                            // Black font weight
	WeightHeavy                            // Heaviest font weight
)

Font weight constants represent standard font weights from thin to heavy

Jump to

Keyboard shortcuts

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