fontimg

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 18 Imported by: 2

README

fontimg Go Package

Package fontimg rasterizes font files as a preview image.

Used by github.com/kenshaw/iv to render fonts.

Documentation

Overview

Package fontimg provides a preview image of a font file (ttf, otf, woff, ...).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTemplate

func NewTemplate(text string) (*template.Template, error)

NewTemplate creates a text template.

Types

type Font

type Font struct {
	Buf        []byte
	Path       string
	Family     string
	Name       string
	Style      string
	SampleText string
	Version    string
	// contains filtered or unexported fields
}

Font is a font image.

func Match

func Match(name string, style canvas.FontStyle, sysfonts *fontpkg.SystemFonts) *Font

Match creates a font image for a matching font name from the system fonts.

func New

func New(buf []byte, path string) *Font

New creates a font image from a path.

func NewFont added in v0.1.1

func NewFont(md fontpkg.FontMetadata) *Font

NewFont creates a new font image.

func Open

func Open(name string, style canvas.FontStyle, sysfonts *fontpkg.SystemFonts) ([]*Font, error)

Open opens fonts as either a path on disk or from the system fonts. When sysfonts is nil, the default system fonts will be loaded.

func (*Font) BestName

func (font *Font) BestName() string

BestName returns the best name for a font.

func (*Font) Load

func (font *Font) Load(style canvas.FontStyle) (*canvas.FontFamily, error)

Load loads the font style.

func (*Font) Rasterize

func (font *Font) Rasterize(
	tpl *template.Template,
	fontSize int, style canvas.FontStyle, variant canvas.FontVariant,
	fg, bg color.Color,
	dpi, margin float64,
) (*image.RGBA, error)

Rasterize rasterizes the font image.

func (*Font) String

func (font *Font) String() string

String satisfies the fmt.Stringer interface.

func (*Font) WriteYAML

func (font *Font) WriteYAML(w io.Writer)

WriteYAML writes YAML information to w.

type TemplateData

type TemplateData struct {
	Size       int
	Name       string
	Style      string
	SampleText string
	Version    string
}

TemplateData is the data passed to the text template.

Jump to

Keyboard shortcuts

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