t1build

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package t1build assembles a Type 1 font program in the PFA form from nothing, for tests.

It exists for the reason internal/cffbuild does: a test that needs a font either redistributes one it may not, skips in a clone, or builds what it needs, and font and render/native both need the same bytes.

The program is laid out the way the producers in the corpus write one: a clear-text font dictionary ending in "currentfile eexec", then the binary eexec-encrypted Private dictionary, Subrs, and CharStrings, with no trailer, since a PDF's FontFile carries none.

Not in a _test.go file, because an internal package cannot export from one. Internal so it cannot become part of the module's surface by accident.

On the overflow annotations below

A charstring's number forms and the cipher are defined on the bits of a value cast down to a byte, and a scanner reads each cast as a possible overflow. The annotations carry this one explanation; every input is a literal or a small value from this file or a caller's test data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CS

func CS(items ...any) []byte

CS encodes a charstring from integer operands, operators, and Raw bytes, in order. An integer takes the shortest form of §6.2 of the format: one byte for -107..107, two for ±108..1131, and the 255 form with a 32-bit integer otherwise. Panics on any other type.

func Square

func Square() []byte

Square is a program whose A (code 65) is the square (100,100)-(600,600), advance 700.

Types

type Builder

type Builder struct {
	Glyphs []Glyph
	Subrs  [][]byte // plain; a nil entry leaves that index undefined

	// Encoding is the built-in encoding, code to glyph name; nil writes StandardEncoding.
	Encoding map[byte]string

	// NoEncoding omits the /Encoding key entirely, for a font that declares none. Encoding is
	// ignored when this is set.
	NoEncoding bool

	// NoCharStrings omits the /CharStrings key entirely, for a font that declares none. Glyphs
	// and CharStringsExtra are ignored when this is set.
	NoCharStrings bool

	// LenIV, when set, is written as /lenIV and used for the Subrs and CharStrings; otherwise
	// the default of 4 is used and no key is written.
	LenIV *int

	FontMatrix string // the /FontMatrix value; empty writes [0.001 0 0 0.001 0 0]

	// FontExtra and PrivateExtra are PostScript written verbatim at the end of the clear-text
	// font dictionary and at the start of the Private dictionary.
	FontExtra, PrivateExtra string

	// CharStringsExtra is written verbatim after the last CharStrings entry, before its end.
	CharStringsExtra string
}

Builder describes a program. The zero value of each field is the ordinary choice.

func (Builder) Build

func (b Builder) Build() (program []byte, length1 int)

Build returns the program and its clear-text length, the stream's /Length1.

type Glyph

type Glyph struct {
	Name string
	CS   []byte // plain; Build encrypts it
}

Glyph is one CharStrings entry.

type Op

type Op int

Op is a Type 1 charstring operator. An escaped operator is 1200 plus its second byte.

const (
	HStem     Op = 1
	VStem     Op = 3
	VMoveTo   Op = 4
	RLineTo   Op = 5
	HLineTo   Op = 6
	VLineTo   Op = 7
	RRCurveTo Op = 8
	ClosePath Op = 9
	CallSubr  Op = 10
	Return    Op = 11
	HSBW      Op = 13
	EndChar   Op = 14
	RMoveTo   Op = 21
	HMoveTo   Op = 22
	VHCurveTo Op = 30
	HVCurveTo Op = 31

	DotSection      Op = 1200
	VStem3          Op = 1201
	HStem3          Op = 1202
	Seac            Op = 1206
	SBW             Op = 1207
	Div             Op = 1212
	CallOtherSubr   Op = 1216
	Pop             Op = 1217
	SetCurrentPoint Op = 1233
)

type Raw

type Raw []byte

Raw is bytes written into a charstring verbatim, for a malformed one.

Jump to

Keyboard shortcuts

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