Documentation
¶
Overview ¶
Package geom holds PDF user-space geometry: rectangles, transformation matrices, and the tolerance policy shared by every consumer.
PDF user space has its origin at the lower-left corner with y increasing upward, which is the opposite of most raster conventions. Nothing in this package flips that; conversion is the rasterizer's job.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultTolerance = Tolerance{
SpaceFrac: 0.30,
WideSpaceFrac: 2.50,
LineFrac: 0.50,
ParaFrac: 1.50,
SizeFrac: 1.06,
IndentFrac: 1.0,
IndentMax: 6.0,
Epsilon: 1e-6,
}
DefaultTolerance is the starting policy. The values are deliberately plain and are expected to move once the golden corpus can measure them; they are not tuned constants inherited from anywhere.
var Identity = Matrix{A: 1, D: 1}
Identity is the no-op transformation.
Functions ¶
This section is empty.
Types ¶
type Matrix ¶
type Matrix struct {
A, B, C, D, E, F float64
}
Matrix is a PDF transformation matrix. PDF writes it as the six operands [a b c d e f], standing for the affine matrix
| a b 0 | | c d 0 | | e f 1 |
with row vectors, so a point transforms as [x y 1] * M. That row-vector convention is why Mul composes left-to-right: A.Mul(B) applies A first.
func (Matrix) ApplyVec ¶
ApplyVec transforms (x, y) as a direction, ignoring translation. Use this for displacements and advance widths, where the origin offset must not apply.
func (Matrix) Mul ¶
Mul returns m composed with n such that the result applies m first, then n. For a glyph this is the natural reading order: text matrix, then CTM.
func (Matrix) ScaleFactors ¶
ScaleFactors returns the magnitude of the transformed unit x and y vectors. For text this yields the on-page size of a nominal 1-unit glyph, which is how an effective font size is recovered from a matrix that may also rotate.
type Rect ¶
type Rect struct {
X0, Y0, X1, Y1 float64
}
Rect is an axis-aligned rectangle in PDF user space, normalized so that X0 <= X1 and Y0 <= Y1. PDF permits either corner order in a /MediaBox array, so construct via NewRect rather than by literal.
func (Rect) Intersect ¶
Intersect returns the overlap of r and s, or the zero Rect if they are disjoint.
type Tolerance ¶
type Tolerance struct {
// SpaceFrac is the fraction of a font's nominal space advance that a
// horizontal gap must exceed before an inter-word space is inferred.
// Below 1.0 because many producers emit slightly tightened spacing.
SpaceFrac float64
// WideSpaceFrac is the multiple of nominal space advance above which a gap
// is treated as column or tab separation rather than a single space.
WideSpaceFrac float64
// LineFrac is the fraction of font size that a baseline must shift
// vertically before a new line is started.
LineFrac float64
// ParaFrac is the multiple of line height above which a vertical gap is
// treated as a paragraph break rather than a line break.
ParaFrac float64
// SizeFrac is the ratio between two consecutive lines' dominant type sizes
// above which they are treated as separate blocks even when the vertical step
// says otherwise. A heading set at ordinary leading is the case: the step alone
// cannot see it, and without this the heading fuses into the paragraph below.
//
// It is a ratio of larger to smaller, so 1.0 would split on any difference at
// all and is not a usable setting — OCR output reports the same line of type at
// sizes differing by a few percent. Zero means the default.
SizeFrac float64
// IndentFrac is the number of space widths a line must be indented past its
// block's own margin, while repeating the indent that block's first line was set
// with, before it is read as starting a new paragraph.
//
// This is the paragraph break that has no vertical evidence: a document setting
// no space between paragraphs steps down by exactly one line at a boundary, so
// ParaFrac cannot see it and SizeFrac has nothing to compare. Expressed in space
// widths rather than points so a footnote and a heading are judged alike. Zero
// means off, which is a usable setting — the rule is the least certain of the
// three and a caller who wants only vertical evidence can have it.
IndentFrac float64
// IndentMax is the number of space widths beyond which an indent is column or
// cell placement rather than a paragraph's first line, and is ignored.
IndentMax float64
// Epsilon is the absolute tolerance for coordinate comparison in user-space
// units, absorbing float noise from matrix composition.
Epsilon float64
}
Tolerance is the single place where "close enough" is decided.
It exists because inferring a space from a coordinate gap is the one judgement that determines whether extracted text reads as prose or as one 4000-character word. Scattering epsilons through the extractor makes that judgement untunable and unmeasurable, so every threshold lives here and is benchmarked as a unit.
func (Tolerance) NearlyEqual ¶
NearlyEqual reports whether a and b are within the absolute epsilon.