glyphless

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package glyphless is a minimal TrueType font whose glyphs carry no outlines: every character prints nothing, but still occupies exactly as much horizontal space as a normal proportional glyph would. This is the asset byb-b4 (StampTextLayer) needs to write invisible text -- an OCR-style layer at PDF text render mode 3 -- without a reader complaining that the font is broken or a naive one drawing black boxes.

The font is built once by gen.go and the resulting glyphless.ttf is committed. Nothing in this package constructs a font at runtime: gen.go is build-tagged //go:build ignore, the same convention testdata/oracle/gen.go uses, so it never compiles into the module and CI never runs it. See gen.go for how to regenerate the asset (never necessary unless the glyph coverage or width table changes).

Index

Constants

View Source
const (
	FirstRune = ' ' // 0x20
	LastRune  = '~' // 0x7E
)

FirstRune and LastRune bound the codepoints this font covers: printable ASCII, space through tilde. That is what an invisible OCR text layer needs to reproduce recognized words; it is not meant to cover the codepoints a visible body font would.

View Source
const NumGlyphs = LastRune - FirstRune + 2

NumGlyphs is the font's glyph count: one glyph per covered rune, plus glyph 0, which every TrueType font reserves for .notdef (ISO/IEC 14496-22 / OpenType spec, "glyf" table). GlyphID never returns 0 for a covered rune.

View Source
const UnitsPerEm = 1000

UnitsPerEm is the font's design grid. It is 1000, not the TrueType-typical 2048, so that a glyph's PDF /Widths entry -- always expressed in 1000ths of text space per ISO 32000-1 9.2.4 -- equals its hmtx advance width with no conversion at the call site that embeds this font.

Variables

View Source
var Font []byte

Functions

func GlyphID

func GlyphID(r rune) (uint16, bool)

GlyphID returns r's glyph index in Font. Glyphs are assigned in rune order starting at 1 (0 is .notdef), which is also the order gen.go writes hmtx entries in and the order its cmap segment maps -- see gen.go's single cmap segment, built on exactly this arithmetic.

func Width

func Width(r rune) (uint16, bool)

Width returns r's advance width in font units (UnitsPerEm == 1000), the same value gen.go wrote into Font's hmtx table for r's glyph.

Types

This section is empty.

Jump to

Keyboard shortcuts

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