Help us shape the future of Go! Take the 2026 Go Developer Survey

fontcheck

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 10 Imported by: 0

README

Fonts

Normal builds inspect already-read local font assets and final @font-face rules. CSS uses the existing parse/v2 grammar/tokenizer; no regex CSS parser, network, glyph rasterization, decompression, font conversion or new runtime dependency.

  • Sniff WOFF/WOFF2/SFNT/TTC signatures, lengths, bounded directory/table offsets; detect fvar presence without claiming supported axes or glyph coverage. Directory work caps at 1,024 entries. Collection internals remain opaque.
  • WOFF2 totalSfntSize is informational, not an exact reconstructed size or an allocation request. Nonzero WOFF2 reserved bits do not invalidate a font.
  • Container inspection cannot certify compressed payloads, checksums, shaping, glyph completeness or browser sanitizer acceptance. --release/browser testing remains useful. Full decoding libraries such as tdewolff/font do more work than this bounded screen needs; no partial sanitizer claim is made.
  • Warn on missing/invalid family/source, invalid Unicode bounds, missing/auto/block display policy, inspected source/format mismatches, no known WOFF2 alternative, preload credential/type/selection mismatches and excessive preload counts. Conditional/alternate CSS and fallback src declarations remain authored. Recognized family-wide display defaults suppress the implicit-auto advisory; conditional/layered family-policy cascade and browser support are not computed.
  • Budgets: warn above 128 KiB per retained font, 256 KiB total, or 8 MiB declared SFNT size. Totals describe retained resources, not proven network transfers.
  • Safe optimizations: content-aware MIME/packing for recognized renamed fonts; fonts >4 KiB prefer files in auto mode; missing anonymous CORS on authored font preloads; missing type for inspected local fonts; equivalent hint deduplication. Explicit credential/type choices are preserved and diagnosed, never guessed away.
  • Preserve font bytes, names, weights, axes, metrics overrides, source order, local(), format()/tech(), Unicode subsets, display timing and explicit pins. No static-text subsetting, source reordering, guessed preloads or font purging.

perf.fonts and perf.font-assets run at the exact final-byte quality gate, using the exact emitted CSS sidecars and source-attributed asset metadata. Individual rules share cached analysis and existing severity controls. The default readable report summarizes fonts and includes every actionable finding. Remote CSS/fonts and dynamic JS font construction are not statically inspected or fetched. Authored data URLs are inspected within the HTML budget but keep their explicit delivery.

Tests cover malformed containers/encodings, real TTF/WOFF2, nested/escaped CSS, Unicode boundaries, optional/variable/subset declarations, fallback sources, packing, source attribution, pin/credential preservation, rule overrides and fuzz inputs. Chromium verifies loaded pixels/geometry at 390/1280 px and one network fetch with a repaired preload. The fixture preparation tools are optional and are never invoked by builds or tests.

CSS Fonts, WOFF, WOFF2, OpenType, loading guidance.

Documentation

Overview

Package fontcheck inspects font containers and CSS without loading glyphs, decompressing font payloads, executing code, or accessing the network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FamilyKey

func FamilyKey(v string) string

func Kind

func Kind(b []byte) string

Kind sniffs only the signature, independently of filename/MIME hints. It does not promise the container, compressed payload or font is valid.

func MIME

func MIME(kind string) string

func MatchesFormat

func MatchesFormat(hint, kind string) bool

func ValidUnicodeRange

func ValidUnicodeRange(value string) bool

ValidUnicodeRange checks the descriptor's mechanical bounds, not glyph coverage or whether the page's future/dynamic text fits a subset.

Types

type Face

type Face struct {
	Offset                                       int
	Family, Display, Weight, Style, UnicodeRange string
	Sources                                      []Source
	Problems                                     []string
	Conditional                                  bool
}

func Faces

func Faces(raw []byte) ([]Face, error)

type Info

type Info struct {
	Source     string `json:"source"`
	Format     string `json:"format,omitempty"`
	Bytes      int    `json:"bytes"`
	SFNTBytes  uint32 `json:"declaredSFNTBytes,omitempty"`
	Variable   bool   `json:"hasVariationTable,omitempty"`
	Collection bool   `json:"collection,omitempty"`
	Issue      string `json:"issue,omitempty"`
	Unknown    string `json:"unknown,omitempty"`
}

func Data

func Data(ref string) Info

Data inspects authored data URLs within the existing 2 MB HTML budget.

func Inspect

func Inspect(b []byte) Info

Inspect is deliberately a bounded container screen, not a font sanitizer. No allocation is based on declared decompressed sizes. Directory work is capped at 1024 entries; WOFF2 collection internals remain opaque.

type Source

type Source struct {
	URL    string
	Format string
	Local  bool
}

type Stylesheet

type Stylesheet struct {
	Faces          []Face
	FamilyDefaults map[string]bool // a valid display policy may apply; no cascade claim
}

func ReadCSS

func ReadCSS(raw []byte) (Stylesheet, error)

ReadCSS reads the font faces of a stylesheet with the shared CSS grammar/tokenizer. It observes every src declaration (fallback declarations can intentionally target different browser support), preserving order and nested media/supports/layer conditions. It never purges.

Jump to

Keyboard shortcuts

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