badge

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: AGPL-3.0, AGPL-3.0-only Imports: 10 Imported by: 0

Documentation

Overview

Package badge provides a configurable SVG badge engine with dynamic font measurement.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusColor

func StatusColor(status string) string

StatusColor maps a status keyword to a badge hex color.

Types

type Badge

type Badge struct {
	Label string // left side text
	Value string // right side text
	Color string // hex color for right side (e.g. "#4c1")
}

Badge defines the content and appearance of a single badge.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine generates SVG badges using a specific font.

func New

func New(metrics *FontMetrics) *Engine

New creates a badge engine with the given font metrics.

func (*Engine) Generate

func (e *Engine) Generate(b Badge) string

Generate produces a shields.io-compatible SVG badge string.

type FontMetrics

type FontMetrics struct {
	// contains filtered or unexported fields
}

FontMetrics holds measured glyph widths and font data for SVG embedding.

func LoadBuiltinFont

func LoadBuiltinFont(name string, size float64) (*FontMetrics, error)

LoadBuiltinFont loads an embedded font by config name.

func LoadFont

func LoadFont(name string, data []byte, size float64) (*FontMetrics, error)

LoadFont loads a TTF/OTF from raw bytes and measures glyph advances at the given size. This is the single code path for ALL fonts — built-in and custom alike.

func LoadFontFile

func LoadFontFile(path string, size float64) (*FontMetrics, error)

LoadFontFile loads a TTF/OTF from a filesystem path.

func (*FontMetrics) FontData

func (m *FontMetrics) FontData() []byte

FontData returns the raw font bytes for SVG embedding.

func (*FontMetrics) FontName

func (m *FontMetrics) FontName() string

FontName returns the font family name.

func (*FontMetrics) FontSize

func (m *FontMetrics) FontSize() float64

FontSize returns the configured point size.

func (*FontMetrics) TextWidth

func (m *FontMetrics) TextWidth(s string) float64

TextWidth returns the pixel width of s using measured glyph advances.

Jump to

Keyboard shortcuts

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