text/draw.go

Functions Structs

Functions

func Draw

Draw renders text to a destination image.

Position (x, y) is the baseline origin.

Supports sourceFace, MultiFace, and FilteredFace.

func Draw(dst draw.Image, text string, face Face, x, y float64, col color.Color) {
	if text == "" || face == nil {
		return
	}

	// Expand tabs to spaces for bitmap rendering.
	// font.Drawer maps \t to .notdef (tofu) because fonts lack a tab glyph.
	// Tab = globalTabWidth spaces (default: 8, matching CSS/Pango/POSIX).
	text = expandTabs(text)

	switch f := face.(type) {
	case *sourceFace:
		drawSourceFace(dst, text, f, x, y, col)
	case *MultiFace:
		drawMultiFace(dst, text, f, x, y, col)
	case *FilteredFace:
		drawFilteredFace(dst, text, f, x, y, col)
	}
}

func Measure

Measure returns the dimensions of text.

Width is the horizontal advance, height is the font's line height.

func Measure(text string, face Face) (width, height float64) {
	if text == "" || face == nil {
		return 0, 0
	}

	// Get advance width
	width = face.Advance(text)

	// Get line height from metrics
	metrics := face.Metrics()
	height = metrics.LineHeight()

	return width, height
}

Structs

type DrawOptions struct

DrawOptions provides advanced options for text drawing.

Reserved for future enhancements.

type DrawOptions struct {
	// Color for the text (default: black)
	Color color.Color
}