Documentation
¶
Overview ¶
Package export turns a built deck into images and documents without a browser: go-webengine lays each slide out and paints it, go-pdfkit writes the PDF. Marp CLI drives a headless Chrome for the same outputs.
The slides are rendered in the box frame (deck.FrameBox), which needs neither <foreignObject> nor generated content from the layout engine.
Index ¶
- func DefaultWorkers() int
- func Each(ctx context.Context, b *slides.Build, opts Options, ...) error
- func EachEncoded(ctx context.Context, b *slides.Build, opts Options, format string, ...) error
- func EachLayout(ctx context.Context, b *slides.Build, opts Options, ...) error
- func JPEG(w io.Writer, img image.Image, opts Options) error
- func ODP(w io.Writer, b *slides.Build, images []*image.RGBA) error
- func PDF(w io.Writer, b *slides.Build, images []*image.RGBA) error
- func PNG(w io.Writer, img image.Image) error
- func PPTX(w io.Writer, b *slides.Build, images []*image.RGBA) error
- func Rasterize(ctx context.Context, b *slides.Build, opts Options) ([]*image.RGBA, error)
- func VectorPDF(ctx context.Context, w io.Writer, b *slides.Build, opts Options) error
- type ODPWriter
- type Options
- type PDFWriter
- type PPTXWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultWorkers ¶ added in v0.3.0
func DefaultWorkers() int
DefaultWorkers is how many slides Each renders at once by default: the number of CPUs Go may use, at most 4. The slides are independent, so more workers render a deck faster; each holds one slide's layout and image, so more workers also hold more memory. Measured on 10 slides (BENCHMARKS.md): 1 → 2 workers saves 47 % of the time, 2 → 4 another 27 %, 4 → 8 only 21 % for 15 % more heap; 4 keeps the heap near one worker's.
func Each ¶ added in v0.3.0
func Each(ctx context.Context, b *slides.Build, opts Options, emit func(i int, img *image.RGBA) error) error
Each renders every slide of b, which must have been rendered in deck.FrameBox, and calls emit with each image in slide order, from one goroutine. Up to opts.Workers slides are rendered concurrently, and no more images than that exist at once: a slide starts only when the image of the one that many places before it has been emitted. emit may keep the image. An error from a slide or from emit stops the render and is returned.
func EachEncoded ¶ added in v0.3.0
func EachEncoded(ctx context.Context, b *slides.Build, opts Options, format string, emit func(i int, data []byte) error) error
EachEncoded is Each with every image encoded, as "png" or "jpeg", by the worker that rendered it, so that encoding runs in parallel too and only the encoded bytes wait for their turn.
func EachLayout ¶ added in v0.4.0
func EachLayout(ctx context.Context, b *slides.Build, opts Options, emit func(i int, l *engine.PageLayout) error) error
EachLayout lays every slide of b out, as Each does, and calls emit with each layout in slide order, from one goroutine, unpainted: the caller paints it — as vectors, for a PDF (see PDFWriter.AddLayout). Up to opts.Workers slides are laid out concurrently, and no more layouts than that exist at once.
func ODP ¶ added in v0.3.0
ODP writes an OpenDocument presentation through go-odf: each slide is a full-slide picture at the slide's size, with the slide's speaker notes, as PPTX does. Render at Scale 2 for a sharp deck.
func PDF ¶
PDF writes one page per slide, each drawn from its image (see PDFWriter.Add; VectorPDF draws them as vectors). A page is the slide's size, a CSS pixel being 3/4 of a point, as Chrome prints Marp's @page size. The outline lists each slide and, under it, its headings (marp --pdf-outlines).
func PPTX ¶ added in v0.2.0
PPTX writes a PowerPoint deck through go-ooxml: each slide is a full-slide picture, at the slide's size, with the slide's speaker notes, as marp-cli's --pptx does. The pictures are PNG; render them at Scale 2 for a sharp deck (marp-cli's default for PPTX).
Types ¶
type ODPWriter ¶ added in v0.3.0
type ODPWriter struct {
// contains filtered or unexported fields
}
ODPWriter builds the deck ODP writes one slide at a time, from each slide's PNG (EachEncoded gives them), so that the deck is never held as images.
func NewODP ¶ added in v0.3.0
NewODP starts the OpenDocument deck of b. go-odf takes the size in CSS pixels.
type Options ¶
type Options struct {
// BaseURL resolves the deck's relative URLs (images, backgrounds):
// typically "file:///path/to/deck/dir/".
BaseURL string
// NoFonts leaves out the fonts bundled for the built-in themes.
NoFonts bool
// JPEGQuality is the JPEG quality, 1 to 100; 0 means 85, marp-cli's.
JPEGQuality int
// Scale is the number of device pixels per CSS pixel: 2 renders a
// 1280×720 slide as 2560×1440, text and vectors drawn at that density
// rather than enlarged. 0 means 1 (marp-cli's --image-scale).
Scale float64
// FileRoot, when set, lets the slides load file: URLs from under this
// directory and nowhere else; empty refuses every local file, as
// marp-cli does without --allow-local-files.
FileRoot string
// Workers is how many slides are rendered at once: 0 means
// DefaultWorkers(). It also bounds memory, since Each holds at most
// this many slide images at a time.
Workers int
}
Options configures the export.
type PDFWriter ¶ added in v0.3.0
type PDFWriter struct {
// Stats adds up what AddLayout drew as vectors and what it had to
// draw as bitmaps (paint.VectorStats).
Stats paint.VectorStats
// contains filtered or unexported fields
}
PDFWriter builds a PDF one slide at a time, so that a deck is never held whole: each page is drawn when it is added — from an image (Add) or from a layout, as vectors (AddLayout) — and what it was drawn from can be dropped.
func (*PDFWriter) AddLayout ¶ added in v0.4.0
func (p *PDFWriter) AddLayout(l *engine.PageLayout) error
AddLayout adds the next slide's page, drawn from its layout as vectors: text as text in the fonts the slide was laid out with (subset-embedded, selectable and searchable), backgrounds, borders and gradients as paths and shadings, images placed once per document however many slides show them, and every link a clickable area. What has no vector form here — an element under opacity, a filter, a blurred shadow — is drawn as a bitmap of just that element (paint.PaintVector).
type PPTXWriter ¶ added in v0.3.0
type PPTXWriter struct {
// contains filtered or unexported fields
}
PPTXWriter builds the deck PPTX writes one slide at a time, from each slide's PNG (EachEncoded gives them), so that the deck is never held as images.
func NewPPTX ¶ added in v0.3.0
func NewPPTX(b *slides.Build) *PPTXWriter
NewPPTX starts the PowerPoint deck of b.
func (*PPTXWriter) Add ¶ added in v0.3.0
func (w *PPTXWriter) Add(png []byte)
Add adds the next slide, its picture given as PNG bytes.
func (*PPTXWriter) AddLayout ¶ added in v0.5.0
func (w *PPTXWriter) AddLayout(l *engine.PageLayout) error
AddLayout adds the next slide as editable content: its text in text boxes set in the slide's own fonts (embedded), its backgrounds, borders and gradients as shapes, its pictures each stored once — drawn from the slide's layout, so at the positions of the image and PDF exports. What a slide cannot hold is a picture of that element (see officecanvas).