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

text

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package text turns label strings into glyph outlines. Plain text is set in DejaVu Sans (matplotlib's default font) through go-opentype; TeX between dollar signs is typeset by go-tex/math, a real TeX math typesetter, except for matplotlib's \mathdefault{...} (what tick labels use), which is set in the text font with matplotlib's own superscript and subscript rules so that tick labels look like matplotlib's.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Default

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

Default is the built-in Renderer: DejaVu Sans for text, go-tex/math for TeX.

func NewDefault

func NewDefault() *Default

NewDefault returns the shared default Renderer.

func (*Default) Layout

func (d *Default) Layout(s string, sizePx float64) Layout

Layout implements Renderer.

func (*Default) LayoutPlain added in v0.2.0

func (d *Default) LayoutPlain(s string, sizePx float64) Layout

LayoutPlain implements PlainRenderer.

func (*Default) LineMetrics

func (d *Default) LineMetrics(sizePx float64) (float64, float64, float64)

LineMetrics implements Renderer.

type Layout

type Layout struct {
	Path    *render.Path
	Width   float64
	Ascent  float64 // above the baseline
	Descent float64 // below the baseline
}

Layout is a laid-out line of text. Path holds the glyph outlines in pixels with the pen origin at (0, 0) on the baseline and y pointing down.

Width, Ascent and Descent are the metrics matplotlib aligns text by. The box starts at the pen origin. For plain text the width is the advance of the string (kerned), which is what FreeType's bounding box of the rendered string comes to in matplotlib within a pixel or two (matplotlib's is hinted, each glyph a whole number of pixels); the ascent and descent are those of the ink. For math, the TeX box.

type PlainRenderer added in v0.2.0

type PlainRenderer interface {
	Renderer
	LayoutPlain(s string, sizePx float64) Layout
}

A PlainRenderer can also lay out a string as it is, with no TeX: dollar signs and backslashes are characters. Text that comes from data (a category name, a customer's label) goes through it, so that "$5 and $6" is not typeset as math and no input reaches the TeX typesetter.

type Renderer

type Renderer interface {
	Layout(s string, sizePx float64) Layout
	// LineMetrics returns the font's typographic ascent, descent and line gap
	// at sizePx: the minimum box matplotlib gives every line.
	LineMetrics(sizePx float64) (ascent, descent, gap float64)
}

A Renderer lays out one line of text at a size in pixels.

Jump to

Keyboard shortcuts

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