fonts

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 16 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

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 Face added in v0.7.0

type Face struct {
	Font  *Font
	Style FontStyle
	Size  float64
	Face  font.Face
}

Face represents a font face with specific style and size

func (*Face) Close added in v0.7.0

func (f *Face) Close()

Close releases the resources used by the face

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
	FilePath    string         // Path to the font file on disk
	Filename    string         // Name of the font file
	IsMonospace bool           // Whether the font is monospaced
	Style       FontStyle      // Font style
	// contains filtered or unexported fields
}

Font represents a loaded font

func GetFallback

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

GetFallback returns either JetBrainsMono or Inter as the fallback font

func GetFont

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

GetFont returns a font with the specified name and style

func GetFontVariants

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

func (*Font) GetFace added in v0.7.0

func (f *Font) GetFace(size float64, style *FontStyle) (*Face, error)

GetFace returns a new Face with the specified style and size

func (*Font) GetMaxWidth added in v0.7.0

func (f *Font) GetMaxWidth() (fixed.Int26_6, error)

GetMaxWidth returns the maximum glyph width in the font

func (*Font) GetMonoFace added in v0.7.0

func (f *Font) GetMonoFace(size float64, cellWidth int) (*Face, error)

GetMonoFace returns a font face that will render with fixed-width characters size is the desired font size in points cellWidth is the desired cell width in pixels (if 0, uses the font's natural maximum width)

func (*Font) IsMono added in v0.7.0

func (f *Font) IsMono() bool

IsMono returns whether this font is monospaced

func (*Font) MeasureString added in v0.7.0

func (f *Font) MeasureString(s string, size float64, style *FontStyle) (fixed.Int26_6, error)

MeasureString returns the width of a string in pixels

func (*Font) ToTrueType

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

ToTrueType converts the opentype.Font to a truetype.Font

type FontStretch added in v0.7.0

type FontStretch int

FontStretch represents the width/stretch of a font

const (
	StretchUltraCondensed FontStretch = iota + 1
	StretchExtraCondensed
	StretchCondensed
	StretchSemiCondensed
	StretchNormal
	StretchSemiExpanded
	StretchExpanded
	StretchExtraExpanded
	StretchUltraExpanded
)

type FontStyle

type FontStyle struct {
	Weight    FontWeight  // Font weight
	Stretch   FontStretch // Font width/stretch
	Italic    bool        // Whether the font is italic
	Underline bool        // Whether the font should be underlined
	Mono      bool        // Whether the font is monospaced
}

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