native

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 native rasterizes a page in Go, with no borrowed engine.

It is the first half of DESIGN.md §8's Phase 6 and it is deliberately incomplete: what exists here is the rasterizer *core* — path construction, the two fill rules, clipping, anti-aliased coverage — and the thing every page in the corpus also needs, glyph outlines, does not. So this backend refuses a page it cannot draw in full rather than returning a partial image. That is the whole of its safety argument: a rasterizer that silently omits the text is indistinguishable from one that rendered a page with no text on it, and this repo has already paid once for a silent omission — see doc.Page.Failed and the cover page it was written for.

Why a scanline rasterizer and not an analytic one

Coverage is sampled on 16 scanlines per pixel row and computed exactly along each of them. The vertical direction is sampled because a polygon's intersection with a pixel is a general polygon and the exact area of it is a clipping problem per pixel; the horizontal direction is exact because along one scanline it is just an interval, so there is nothing to approximate and no reason to.

The split was measured rather than assumed, against render/pdfium on three shapes that exercise what a fill rule has to get right — a convex triangle, a five-pointed star drawn as one self-intersecting subpath (nonzero fills its middle, even-odd hollows it, so the shape says which rule ran), and a closed pair of cubic Béziers. At 16 samples the mean absolute difference from pdfium is **0.06 of 255**, the maximum is 28 on a handful of edge pixels, no pixel differs by more than 32, and the total ink agrees to 1.000. Quantizing per subsample instead of accumulating exact area and scaling once put the mean at 3.47 and the ink ratio at 0.941 — 255/16 is 15, so a fully covered pixel came out 240 — which is the kind of error that hides as "slightly light" forever.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.New("render/native: page needs an operator this backend does not implement")

ErrUnsupported reports that a page draws something this backend cannot draw.

Its own error rather than a generic one, because the caller's reaction is specific: fall back to another Rasterizer for that page. Nothing in this repo does that yet — cmd/pdfspec still constructs render/pdfium unconditionally — so the sentinel is what a fallback will be built on rather than something one already uses, and saying so is the difference between a plan and a claim.

Functions

func New

func New(s objects.Store, opts ...Option) render.Rasterizer

New returns a Rasterizer over s.

The interface rather than the concrete type, which is what render/pdfium's Open returns and what keeps the two adapters substitutable: a caller that named the type would be choosing a backend at compile time, where the whole point of the interface is choosing one at run time.

The Store is borrowed: Close does not close it, because the caller opened it and is still using it for text. One consequence worth stating, since render.Rasterizer's own comment says implementations are not safe for concurrent use: page-level parallelism needs one Store per worker, which spends back some of the single-parse saving this backend has over the borrowed one.

Types

type Option

type Option func(*rasterizer)

Option configures a rasterizer.

func WithFaces

func WithFaces(src font.FaceSource) Option

WithFaces supplies the source of substitute font programs.

Without it, a page whose font embeds no program is refused with the reason, which is the default because a refusal is honest where a silently wrong typeface is not. The cost of that choice, stated rather than discovered: **this backend draws 1,232 of the corpus's 1,251 pages when a font.FaceSource is supplied, and 95 without one.** Every claim about what it renders carries that qualifier. cmd/pdfspec is where this repo supplies them, from internal/liberation.

type Unsupported

type Unsupported struct {
	Page int
	Ops  []string
}

Unsupported names what stopped a page, so a report can say which feature is missing rather than that something was.

The operator names are what the page actually used, deduplicated and sorted, because the actionable question when this arrives in a log over a thousand pages is which *feature* to implement next — and a list of operators answers it where a count does not.

func (*Unsupported) Error

func (u *Unsupported) Error() string

func (*Unsupported) Unwrap

func (u *Unsupported) Unwrap() error

Jump to

Keyboard shortcuts

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