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

glyph

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Artistic-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package glyph gives the outlines of characters in the standard fonts, so text can be drawn as shapes - the same in every browser, whatever fonts it has.

Where the URW base-35 fonts are installed as OpenType (Debian's fonts-urw-base35, which Ghostscript needs), it uses them: the very glyphs Ghostscript embeds when epstopdf turns OneFit's EPS into its PDF, so the preview is the PDF. They are read at run time from the system, never shipped. Otherwise it uses the Liberation fonts it carries, whose advance widths are those of Helvetica, Times and Courier; the Symbol font's letters are then Liberation Serif's Greek. OFE_URW_FONTS names another directory holding the URW OpenType files. On macOS the onefite-go formula installs them in Homebrew's share/fonts/urw-base35, and the font-urw-base35 cask in ~/Library/Fonts; both are searched.

The Liberation fonts are distributed under the SIL Open Font License 1.1 (see FontLicense).

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed OFL.txt
	FontLicense string
	//go:embed go-fonts-LICENSE
	PackageLicense string
)

The Liberation fonts' license (SIL Open Font License 1.1) and that of the go-fonts package carrying them (BSD), which must go with the fonts - they are embedded in every plot-go binary: plot-go -notices prints these.

View Source
var (
	//go:embed x-image-LICENSE
	XImageLicense string
	//go:embed x-image-PATENTS
	XImagePatents string
	//go:embed x-text-LICENSE
	XTextLicense string
	//go:embed x-text-PATENTS
	XTextPatents string
)

The licenses (BSD) and patent grants of golang.org/x/image, which reads and draws the fonts, and golang.org/x/text, which it uses: compiled into every plot-go binary, so plot-go -notices prints them too.

View Source
var SymbolGreek = map[byte]rune{
	'A': 'Α', 'B': 'Β', 'C': 'Χ', 'D': 'Δ', 'E': 'Ε', 'F': 'Φ', 'G': 'Γ', 'H': 'Η',
	'I': 'Ι', 'J': 'ϑ', 'K': 'Κ', 'L': 'Λ', 'M': 'Μ', 'N': 'Ν', 'O': 'Ο', 'P': 'Π',
	'Q': 'Θ', 'R': 'Ρ', 'S': 'Σ', 'T': 'Τ', 'U': 'Υ', 'V': 'ς', 'W': 'Ω', 'X': 'Ξ',
	'Y': 'Ψ', 'Z': 'Ζ',
	'a': 'α', 'b': 'β', 'c': 'χ', 'd': 'δ', 'e': 'ε', 'f': 'φ', 'g': 'γ', 'h': 'η',
	'i': 'ι', 'j': 'ϕ', 'k': 'κ', 'l': 'λ', 'm': 'μ', 'n': 'ν', 'o': 'ο', 'p': 'π',
	'q': 'θ', 'r': 'ρ', 's': 'σ', 't': 'τ', 'u': 'υ', 'v': 'ϖ', 'w': 'ω', 'x': 'ξ',
	'y': 'ψ', 'z': 'ζ',
}

SymbolGreek is the Symbol font's letters as the Greek characters they draw (Adobe's Symbol.afm names them: Alpha, Beta, Chi, ...; theta1, sigma1, phi1, omega1 are the variant forms).

Functions

func Ink added in v0.1.6

func Ink(name string, m *afm.Font, str string) afm.Box

Ink is the box of the ink str leaves in font name (whose Adobe metrics are m), in ems, the pen starting at 0: each character's box from the URW font where it is installed - gracebat lays its text out with the URW glyphs, whose ink differs from Adobe's by up to 0.02 em - else from Adobe's metrics. The advance widths are Adobe's either way (the URW fonts are metric compatible).

func Rune

func Rune(font string, c byte) rune

Rune is the character byte c draws in a standard font: Symbol letters are Greek, 39 is quoteright (gracebat's text encoding), the rest Latin-1.

func Source

func Source(name string) string

Source is where a standard font's outlines come from: the URW file's path, or "Liberation" (the fonts plot-go carries).

func URWInk added in v0.1.6

func URWInk(fontName string, c byte) (llx, lly, urx, ury float64, ok bool)

URWInk is the box of the ink character c leaves in a standard font, in ems, from the URW font when it is installed - the glyphs gracebat lays its text out with. ok is false without the URW font (or for a character it has no glyph for): the caller keeps Adobe's metrics then.

Types

type Op

type Op byte

Op is a path operator: move, line, quadratic or cubic curve.

const (
	MoveTo Op = 'M'
	LineTo Op = 'L'
	QuadTo Op = 'Q'
	CubeTo Op = 'C'
)

type Seg

type Seg struct {
	Op  Op
	Pts [][2]float64
}

Seg is one piece of an outline: its operator and its points, in ems, y up, from the character's origin on the baseline.

func Outline

func Outline(fontName string, c byte) ([]Seg, error)

Outline is the outline of character c in a standard font, in ems. A character the font has no glyph for has an empty outline.

Jump to

Keyboard shortcuts

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