Documentation
¶
Overview ¶
Package prawn is a pure-Go (CGO=0), MRI-faithful reimplementation of Ruby's prawn PDF-generation gem.
It mirrors prawn's public DSL — Prawn::Document and its text / font / color / graphics / image / table / transformation / grid / page-management methods, plus the Prawn::Errors tree — and writes the PDF with its own native, pure-Go PDF object model and content-stream writer (see pdfcore.go / content.go). The emitted content-stream operators match Ruby prawn / PDF::Core operator-for-operator (BT/ET, Td, Tf, kerned TJ, re/l/m/c, S/f/b, cs/scn, CS/SCN, cm, Do, gs), so a PDF::Inspector-style parse of the output yields the same operator tree. Nothing here uses cgo or a Ruby runtime, so the whole module builds and runs with CGO disabled on every supported 64-bit target and compiles to WebAssembly.
Mapping from Ruby to Go ¶
Ruby's block-form generator
Prawn::Document.generate("hello.pdf") do |pdf|
pdf.text "Hello World", size: 24, style: :bold
pdf.move_down 20
pdf.stroke_rectangle [0, pdf.cursor], 200, 100
end
becomes
prawn.Generate("hello.pdf", func(pdf *prawn.Document) error {
pdf.Text("Hello World", &prawn.TextOptions{Size: 24, Style: prawn.StyleBold, StyleSet: true})
pdf.MoveDown(20)
pdf.StrokeRectangle(0, pdf.Cursor(), 200, 100)
return nil
})
Ruby keyword-argument hashes map to option structs (nil selects prawn's defaults); Ruby symbols map to typed Go constants (Style*, Align*, page-size and layout string constants). Coordinates use PDF points (1/72 inch) with prawn's native origin: the lower-left corner of the current bounding box, y up.
Fonts ¶
The 14 standard PDF (AFM/Core-14) fonts are supported with prawn's exact glyph-advance and kerning metrics (WinAnsi/cp1252 encoding, kerned TJ output). TrueType fonts are embedded the way prawn/ttfunk does: parsed, subset down to the used glyphs (following composite-glyph references), and written as a Type0 / CIDFontType2 font with Identity-H encoding, a FontFile2 stream, a per-CID /W width array and a /ToUnicode CMap (see RegisterFontTTF).
Verification ¶
Every PDF is a well-formed PDF that round-trips through the pure-Go rsc.io/pdf reader. The library is validated against the real Ruby prawn gem with a PDF::Inspector-style differential oracle: for a set of scenarios, the content-stream operators this package emits are compared, operator-for-operator (numbers normalized), against the gem's output for the same script. The gem's output is captured into testdata/oracle/*.content and committed so the oracle runs in CI without Ruby; a skip-gated test re-verifies those fixtures against a live gem when one is installed. See prawn_diff_test.go and prawn_gem_test.go.
Determinism ¶
The PDF /CreationDate and file /ID are derived from a package clock seam (see SetClock) rather than the wall clock, so output is reproducible and timezone independent. The bytes are big-endian/little-endian independent (the format is byte-oriented and all binary parsing is explicitly big-endian), so the s390x lane exercises the same code path as the little-endian ones.
Scope ¶
Implemented: document + page management (Generate/New, Render, RenderFile, StartNewPage, Cursor, Bounds, MoveDown/Up, Pad, page sizes and layout, SkipPageCreation, stream compression); text (Text, DrawText, TextBox with truncate/expand/error overflow, Font/FontSize/Leading, alignment, kerning, WidthOfString); formatted text (FormattedText runs and TextInline <b>/<i>/ <color> markup); Core-14 AFM fonts and TrueType embedding with subsetting; color (RGB and CMYK fill/stroke via cs/scn, CS/SCN); vector graphics (MoveTo/LineTo/CurveTo, Rectangle, Line, Polygon, Circle/Ellipse, Stroke/Fill/ FillAndStroke/CloseAndStroke, LineWidth, Cap/Join style, Dash); bounding boxes; the column/row grid; affine transformations (Rotate/Scale/Translate, with origin, and TransformationMatrix) plus save/restore graphics state and transparency; PNG (with alpha → SMask) and JPEG images; repeaters and page numbering; and the Prawn::Errors tree.
Deferred (named): prawn-table's advanced features (row/column spanning, per-cell style callbacks, automatic table pagination); TrueType 'kern'-table and GPOS kerning for embedded fonts (AFM kerning is complete); OpenType/CFF (glyf-based TrueType only); soft-hyphen/CJK line breaking; and SVG.
Index ¶
- Variables
- func Generate(path string, block func(*Document) error) error
- func GenerateTo(w io.Writer, block func(*Document) error) error
- func GenerateWith(path string, o Options, block func(*Document) error) error
- func SetClock(fn func() time.Time) (previous func() time.Time)
- type Align
- type Bounds
- type Document
- func (d *Document) BoundingBox(x, y, width, height float64, block func())
- func (d *Document) Bounds() Bounds
- func (d *Document) CapStyle(style int)
- func (d *Document) Circle(x, y, r float64)
- func (d *Document) CloseAndStroke()
- func (d *Document) ClosePath()
- func (d *Document) Cursor() float64
- func (d *Document) CurveTo(destX, destY, c1x, c1y, c2x, c2y float64)
- func (d *Document) Dash(on, off, phase float64)
- func (d *Document) DefineGrid(columns, rows int, gutter float64) *Grid
- func (d *Document) DrawText(s string, x, y float64, opts *TextOptions)
- func (d *Document) Ellipse(x, y, rx, ry float64)
- func (d *Document) Error() error
- func (d *Document) Fill()
- func (d *Document) FillAndStroke()
- func (d *Document) FillCircle(x, y, r float64)
- func (d *Document) FillColor(hex string)
- func (d *Document) FillColorCMYK(c, m, y, k float64)
- func (d *Document) FillColorValue() string
- func (d *Document) FillEllipse(x, y, rx, ry float64)
- func (d *Document) FillPolygon(points ...[2]float64)
- func (d *Document) FillRectangle(x, y, w, h float64)
- func (d *Document) Font(name string, style Style)
- func (d *Document) FontFamily() string
- func (d *Document) FontSize(size float64)
- func (d *Document) FontSizeValue() float64
- func (d *Document) FontStyle() Style
- func (d *Document) FormattedText(frags []FormattedFragment, opts *TextOptions)
- func (d *Document) Image(path string, o ImageOptions) ImageResult
- func (d *Document) ImageReader(r io.Reader, tp string, o ImageOptions) ImageResult
- func (d *Document) JoinStyle(style int)
- func (d *Document) KerningEnabled() bool
- func (d *Document) Leading(n float64)
- func (d *Document) LeadingValue() float64
- func (d *Document) Line(x1, y1, x2, y2 float64)
- func (d *Document) LineTo(x, y float64)
- func (d *Document) LineWidth(n float64)
- func (d *Document) LineWidthValue() float64
- func (d *Document) MoveCursorTo(y float64)
- func (d *Document) MoveDown(n float64)
- func (d *Document) MoveTo(x, y float64)
- func (d *Document) MoveUp(n float64)
- func (d *Document) NumberPages(format string, x, y float64, opts *TextOptions)
- func (d *Document) Pad(n float64, block func())
- func (d *Document) PadBottom(n float64, block func())
- func (d *Document) PadTop(n float64, block func())
- func (d *Document) PageCount() int
- func (d *Document) PageHeight() float64
- func (d *Document) PageNumber() int
- func (d *Document) PageWidth() float64
- func (d *Document) Polygon(points ...[2]float64)
- func (d *Document) Rectangle(x, y, w, h float64)
- func (d *Document) RegisterFontOTF(name string, data []byte, opts *OTFOptions) error
- func (d *Document) RegisterFontTTF(name string, data []byte) error
- func (d *Document) Render() ([]byte, error)
- func (d *Document) RenderFile(path string) error
- func (d *Document) Repeat(filter func(page, total int) bool, block func())
- func (d *Document) RepeatPageCount() int
- func (d *Document) RepeatPageNumber() int
- func (d *Document) RestoreGraphicsState()
- func (d *Document) Rotate(angle float64, block func())
- func (d *Document) RotateAbout(angle, ox, oy float64, block func())
- func (d *Document) SaveGraphicsState()
- func (d *Document) Scale(factor float64, block func())
- func (d *Document) ScaleAbout(factor, ox, oy float64, block func())
- func (d *Document) SetKerning(on bool)
- func (d *Document) StartNewPage()
- func (d *Document) Stroke()
- func (d *Document) StrokeBounds()
- func (d *Document) StrokeCircle(x, y, r float64)
- func (d *Document) StrokeColor(hex string)
- func (d *Document) StrokeColorCMYK(c, m, y, k float64)
- func (d *Document) StrokeColorValue() string
- func (d *Document) StrokeEllipse(x, y, rx, ry float64)
- func (d *Document) StrokeLine(x1, y1, x2, y2 float64)
- func (d *Document) StrokePolygon(points ...[2]float64)
- func (d *Document) StrokeRectangle(x, y, w, h float64)
- func (d *Document) Table(data [][]string, o TableOptions) TableResult
- func (d *Document) Text(s string, opts *TextOptions)
- func (d *Document) TextBox(s string, o TextBoxOptions) string
- func (d *Document) TextInline(s string, opts *TextOptions)
- func (d *Document) TransformationMatrix(a, b, c, e, f, g float64, block func())
- func (d *Document) Translate(x, y float64, block func())
- func (d *Document) Transparency(fill, stroke float64, block func())
- func (d *Document) Undash()
- func (d *Document) WidthOfString(s string) float64
- type FormattedFragment
- type Grid
- type ImageOptions
- type ImageResult
- type OTFOptions
- type Options
- type Overflow
- type Style
- type TableOptions
- type TableResult
- type TextBoxOptions
- type TextOptions
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCannotFit mirrors Prawn::Errors::CannotFit — content is too large for // the space it must occupy (e.g. a word wider than the available width). ErrCannotFit = &prawnError{kind: "CannotFit"} // ErrUnknownFont mirrors Prawn::Errors::UnknownFont — a font was requested // by a name that has not been registered. ErrUnknownFont = &prawnError{kind: "UnknownFont"} // ErrInvalidPageLayout mirrors Prawn::Errors::InvalidPageLayout — a page // layout other than :portrait or :landscape was requested. ErrInvalidPageLayout = &prawnError{kind: "InvalidPageLayout"} // ErrUnsupportedImageType mirrors Prawn::Errors::UnsupportedImageType — an // image whose format is neither PNG nor JPEG was supplied. ErrUnsupportedImageType = &prawnError{kind: "UnsupportedImageType"} // ErrEmptyGraphicStateStack mirrors Prawn::Errors::EmptyGraphicStateStack — // restore_graphics_state was called with no matching save_graphics_state. ErrEmptyGraphicStateStack = &prawnError{kind: "EmptyGraphicStateStack"} // ErrIncompatibleStringEncoding mirrors // Prawn::Errors::IncompatibleStringEncoding — a string cannot be rendered // with the current font (here: invalid UTF-8). ErrIncompatibleStringEncoding = &prawnError{kind: "IncompatibleStringEncoding"} )
Sentinel errors mirror the parameterless Prawn::Errors classes. They are returned directly (or wrapped) so callers can use errors.Is.
Functions ¶
func GenerateTo ¶
GenerateTo mirrors Prawn::Document.generate(io) { |pdf| … } for a writer.
func GenerateWith ¶
GenerateWith is Generate with explicit document options.
Types ¶
type Align ¶
type Align int
Align mirrors a prawn alignment symbol (:left, :center, :right, :justify).
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document mirrors Prawn::Document. It owns a native PDF object model (no cgo, no third-party PDF writer) and tracks prawn's drawing state so the emitted content-stream operators match Ruby prawn's.
func (*Document) BoundingBox ¶
BoundingBox mirrors Prawn::Document#bounding_box([x, y], width:, height:) { … }. (x, y) is the top-left corner in the current bounds' coordinates. Inside the block, bounds and the cursor are relative to the new box; afterwards the document cursor is left at the box's bottom, as prawn does.
func (*Document) CapStyle ¶
CapStyle mirrors Prawn::Document#cap_style: 0 butt, 1 round, 2 projecting.
func (*Document) CloseAndStroke ¶
func (d *Document) CloseAndStroke()
CloseAndStroke mirrors Prawn::Document#close_and_stroke: paints with "s".
func (*Document) ClosePath ¶
func (d *Document) ClosePath()
ClosePath mirrors Prawn::Document#close_path: emits "h".
func (*Document) CurveTo ¶
CurveTo mirrors Prawn::Document#curve_to(dest, bounds: [c1, c2]): emits the two control points and the destination followed by "c".
func (*Document) Dash ¶
Dash mirrors Prawn::Document#dash(length, space:, phase:): sets a dash of alternating on/off lengths and writes the "[on off] phase d" operator.
func (*Document) DefineGrid ¶
DefineGrid mirrors Prawn::Document#define_grid(columns:, rows:, gutter:).
func (*Document) DrawText ¶
func (d *Document) DrawText(s string, x, y float64, opts *TextOptions)
DrawText mirrors Prawn::Document#draw_text(string, at: [x, y]): one line at an absolute (bounds-relative) point, no wrapping, cursor unchanged. The point is the text baseline, as in prawn.
func (*Document) Ellipse ¶
Ellipse mirrors Prawn::Document#ellipse([x, y], rx, ry): four Bézier arcs around the centre, ending with a MoveTo back to the centre (prawn's exact construction).
func (*Document) Fill ¶
func (d *Document) Fill()
Fill mirrors Prawn::Document#fill: paints the current path with "f".
func (*Document) FillAndStroke ¶
func (d *Document) FillAndStroke()
FillAndStroke mirrors Prawn::Document#fill_and_stroke: paints with "b".
func (*Document) FillCircle ¶
FillCircle mirrors Prawn::Document#fill_circle([x, y], r).
func (*Document) FillColor ¶
FillColor mirrors Prawn::Document#fill_color = "RRGGBB": it sets the fill color (used for shapes and text) and emits the color-space + scn operators.
func (*Document) FillColorCMYK ¶
FillColorCMYK mirrors Prawn::Document#fill_color(c, m, y, k) with 0..100 components.
func (*Document) FillColorValue ¶
FillColorValue and StrokeColorValue return the current colors as hex strings.
func (*Document) FillEllipse ¶
FillEllipse mirrors Prawn::Document#fill_ellipse([x, y], rx, ry).
func (*Document) FillPolygon ¶
FillPolygon mirrors Prawn::Document#fill_polygon.
func (*Document) FillRectangle ¶
FillRectangle mirrors Prawn::Document#fill_rectangle.
func (*Document) Font ¶
Font mirrors Prawn::Document#font(name, style:). It selects a Core-14 built-in family or a previously embedded TTF family by name and an optional style.
func (*Document) FontFamily ¶
FontFamily returns the current font's PostScript/base name.
func (*Document) FontSize ¶
FontSize sets the current font size in points (Prawn::Document#font_size=).
func (*Document) FontSizeValue ¶
FontSizeValue returns the current font size (Prawn::Document#font_size).
func (*Document) FormattedText ¶
func (d *Document) FormattedText(frags []FormattedFragment, opts *TextOptions)
FormattedText mirrors Prawn::Document#formatted_text(array): it lays a sequence of styled runs as flowing, wrapping text starting at the cursor, advancing it downward. Runs are laid out inline; a run wraps to the next line when it no longer fits the bounding-box width.
func (*Document) Image ¶
func (d *Document) Image(path string, o ImageOptions) ImageResult
Image mirrors Prawn::Document#image(path, options): embeds a PNG or JPEG.
func (*Document) ImageReader ¶
func (d *Document) ImageReader(r io.Reader, tp string, o ImageOptions) ImageResult
ImageReader mirrors Prawn::Document#image(io, options): embeds an image from a reader. tp is "png", "jpg" or "jpeg".
func (*Document) JoinStyle ¶
JoinStyle mirrors Prawn::Document#join_style: 0 miter, 1 round, 2 bevel.
func (*Document) KerningEnabled ¶
KerningEnabled reports whether kerning is on.
func (*Document) Leading ¶
Leading sets the document-wide extra leading (Prawn::Document#default_leading).
func (*Document) LeadingValue ¶
LeadingValue returns the current default leading.
func (*Document) LineWidth ¶
LineWidth mirrors Prawn::Document#line_width = n: sets and writes "n w".
func (*Document) LineWidthValue ¶
LineWidthValue mirrors Prawn::Document#line_width (reader).
func (*Document) MoveCursorTo ¶
MoveCursorTo mirrors Prawn::Document#move_cursor_to.
func (*Document) NumberPages ¶
func (d *Document) NumberPages(format string, x, y float64, opts *TextOptions)
NumberPages mirrors Prawn::Document#number_pages(string, options): stamps a page number onto every page. In the format string, "<page>" and "<total>" are replaced with the current page number and total page count. The text baseline is placed at the bounds-relative point (x, y).
func (*Document) PageHeight ¶
PageHeight returns the current page height in points.
func (*Document) PageNumber ¶
PageNumber returns the current (1-based) page number.
func (*Document) Polygon ¶
Polygon mirrors Prawn::Document#polygon(points…): MoveTo the first point, LineTo the rest and back to the first, then "h".
func (*Document) Rectangle ¶
Rectangle mirrors Prawn::Document#rectangle([x, y], w, h): (x, y) is the upper-left corner; emits "x (y-h) w h re".
func (*Document) RegisterFontOTF ¶
func (d *Document) RegisterFontOTF(name string, data []byte, opts *OTFOptions) error
RegisterFontOTF parses a TrueType or OpenType font with the go-opentype stack and registers it under family name, gaining CFF/OTF embedding plus optional complex-script shaping and variable-font instancing (see OTFOptions). Subsequent Font(name, …) calls select it, exactly like a font registered with RegisterFontTTF. A nil opts means the default, Prawn-compatible behaviour.
func (*Document) RegisterFontTTF ¶
RegisterFontTTF parses a TrueType font and registers it under the given family name (Prawn::Document#font_families/#font with a TTF file). Subsequent Font(name, …) calls select it.
func (*Document) Render ¶
Render mirrors Prawn::Document#render: it finalizes the document (running any repeaters / page numbering, balancing each page's graphics state) and returns the finished PDF as bytes. Any accumulated build error is returned here.
func (*Document) RenderFile ¶
RenderFile mirrors Prawn::Document#render_file(path).
func (*Document) Repeat ¶
Repeat mirrors Prawn::Document#repeat(filter) { … }: the block is executed on each page (at render time) for which filter(pageNumber, totalPages) is true.
func (*Document) RepeatPageCount ¶
RepeatPageCount returns the total page count while a repeater block runs.
func (*Document) RepeatPageNumber ¶
RepeatPageNumber returns the current page number while a repeater/NumberPages block runs (1-based); 0 outside a repeater.
func (*Document) RestoreGraphicsState ¶
func (d *Document) RestoreGraphicsState()
RestoreGraphicsState mirrors Prawn::Document#restore_graphics_state: emits "Q". Calling it without a matching save records ErrEmptyGraphicStateStack.
func (*Document) RotateAbout ¶
RotateAbout mirrors Prawn::Document#rotate(angle, origin: [ox, oy]) { … }.
func (*Document) SaveGraphicsState ¶
func (d *Document) SaveGraphicsState()
SaveGraphicsState mirrors Prawn::Document#save_graphics_state: emits "q".
func (*Document) Scale ¶
Scale mirrors Prawn::Document#scale(factor) { … } (uniform scale about the coordinate origin).
func (*Document) ScaleAbout ¶
ScaleAbout mirrors Prawn::Document#scale(factor, origin: [ox, oy]) { … }.
func (*Document) SetKerning ¶
SetKerning enables or disables kerning for subsequent text (prawn default on).
func (*Document) StartNewPage ¶
func (d *Document) StartNewPage()
StartNewPage mirrors Prawn::Document#start_new_page. Pages are closed (their content balanced) only at render time, so repeaters and page numbering can still draw onto any page.
func (*Document) Stroke ¶
func (d *Document) Stroke()
Stroke mirrors Prawn::Document#stroke: paints the current path with "S".
func (*Document) StrokeBounds ¶
func (d *Document) StrokeBounds()
StrokeBounds mirrors Prawn::Document#stroke_bounds: outline the bounding box.
func (*Document) StrokeCircle ¶
StrokeCircle mirrors Prawn::Document#stroke_circle([x, y], r).
func (*Document) StrokeColor ¶
StrokeColor mirrors Prawn::Document#stroke_color = "RRGGBB".
func (*Document) StrokeColorCMYK ¶
StrokeColorCMYK mirrors Prawn::Document#stroke_color(c, m, y, k).
func (*Document) StrokeColorValue ¶
func (*Document) StrokeEllipse ¶
StrokeEllipse mirrors Prawn::Document#stroke_ellipse([x, y], rx, ry).
func (*Document) StrokeLine ¶
StrokeLine mirrors Prawn::Document#stroke_line([x1, y1], [x2, y2]).
func (*Document) StrokePolygon ¶
StrokePolygon mirrors Prawn::Document#stroke_polygon.
func (*Document) StrokeRectangle ¶
StrokeRectangle mirrors Prawn::Document#stroke_rectangle.
func (*Document) Table ¶
func (d *Document) Table(data [][]string, o TableOptions) TableResult
Table mirrors Prawn::Document#table(data, options): draws a grid of string cells and advances the cursor past it. An empty data set is a no-op.
func (*Document) Text ¶
func (d *Document) Text(s string, opts *TextOptions)
Text mirrors Prawn::Document#text: flowing, wrapping, auto-paginating text that starts at the cursor and advances it downward.
func (*Document) TextBox ¶
func (d *Document) TextBox(s string, o TextBoxOptions) string
TextBox mirrors Prawn::Document#text_box: lays flowing text into a positioned rectangle and returns the portion that did not fit. It leaves the cursor unchanged.
func (*Document) TextInline ¶
func (d *Document) TextInline(s string, opts *TextOptions)
TextInline mirrors Prawn::Document#text(string, inline_format: true): it parses <b>/<i>/<u> and <color rgb="…">/<font size="…"> tags into formatted fragments and renders them.
func (*Document) TransformationMatrix ¶
TransformationMatrix mirrors Prawn::Document#transformation_matrix(a,b,c,d,e,f): concatenates the matrix onto the CTM. When block is non-nil it is wrapped in q/Q; when nil the caller manages the graphics state.
func (*Document) Transparency ¶
Transparency mirrors Prawn::Document#transparency(fill, stroke): sets the alpha for fill (and stroke) drawing within block via an ExtGState.
func (*Document) Undash ¶
func (d *Document) Undash()
Undash mirrors Prawn::Document#undash: clears the dash pattern ("[] 0 d").
func (*Document) WidthOfString ¶
WidthOfString measures a UTF-8 string at the current font and size, applying the document kerning flag (Prawn::Document#width_of).
type FormattedFragment ¶
type FormattedFragment struct {
Text string
Bold bool
Italic bool
Size float64 // 0 = document size
Color string // "" = current fill color
Font string // "" = current family
}
FormattedFragment is one styled run of a formatted-text array (prawn's { text:, styles:, size:, color:, font: } hash).
type Grid ¶
Grid mirrors Prawn::Document#define_grid / #grid: a regular columns×rows grid with a uniform gutter, laid over the current bounding box.
func (*Grid) Box ¶
Box runs block inside the bounding box of grid cell (row, col), 0-indexed from the top-left, mirroring Prawn::Document::Grid::GridBox.
func (*Grid) ColumnWidth ¶
ColumnWidth returns the width of a single grid column.
type ImageOptions ¶
type ImageOptions struct {
AtX, AtY float64
AtSet bool
Width float64
Height float64
FitW, FitH float64
}
ImageOptions mirror the keyword arguments of Prawn::Document#image (:at, :width, :height, :fit).
type ImageResult ¶
type ImageResult struct {
Width, Height float64
}
ImageResult reports the placed geometry of an embedded image.
type OTFOptions ¶
type OTFOptions struct {
// Shape enables the complex-text shaper (github.com/go-opentype/shape) for
// every run drawn with this font: GSUB substitution (ligatures, Arabic
// joining forms, Indic reordering) and GPOS positioning (kerning, mark
// attachment). With it off the run is the plain cmap glyph mapping, byte-for
// -byte the same as the default Prawn text path.
Shape bool
// Script forces the shaping script tag ("arab", "deva", "latn", …). Empty
// auto-detects from the text. Ignored when Shape is false.
Script string
// Vertical selects vertical (CJK tategaki) shaping. Ignored when Shape is
// false.
Vertical bool
// Variation, when non-empty, instances a variable font at the given
// user-space axis coordinates (keyed by axis tag, e.g. {"wght": 700}). Axes
// absent from the map keep their default. An unknown axis tag is an error.
Variation map[string]float64
}
OTFOptions mirror the per-font keyword arguments prawn accepts when a TrueType or OpenType file is registered through the go-opentype backend. The zero value selects the default, Prawn-compatible behaviour: no shaping (each rune maps straight through the cmap), no variation (the font's default master).
type Options ¶
type Options struct {
// PageSize names a standard page size ("LETTER", "LEGAL", "A4", …). Empty
// means "LETTER". Ignored when PageWidth and PageHeight are both > 0.
PageSize string
// PageWidth and PageHeight give an explicit custom page size in points; when
// both are > 0 they override PageSize (prawn's page_size: [w, h]).
PageWidth, PageHeight float64
// PageLayout is "portrait" (default) or "landscape".
PageLayout string
// Margin, when non-nil, sets all four margins to the same value in points.
Margin *float64
// Margins, when non-nil, sets the four margins explicitly as
// [top, right, bottom, left] in points (prawn's margin: [t, r, b, l]).
Margins *[4]float64
// SkipPageCreation suppresses the initial page (prawn skip_page_creation).
SkipPageCreation bool
// CompressStreams enables FlateDecode on content streams (prawn compress).
CompressStreams bool
}
Options mirror the keyword arguments of Prawn::Document.new (:page_size, :page_layout, :margin). A zero Options selects prawn's defaults: US Letter, portrait, 36pt (0.5in) margins on every side.
type Style ¶
type Style int
Style mirrors a prawn font style symbol (:normal, :bold, :italic, :bold_italic).
const ( // StyleNormal is the upright roman style (prawn :normal). StyleNormal Style = iota // StyleBold is the bold style (prawn :bold). StyleBold // StyleItalic is the italic/oblique style (prawn :italic). StyleItalic // StyleBoldItalic is the combined bold + italic style (prawn :bold_italic). StyleBoldItalic )
type TableOptions ¶
type TableOptions struct {
ColumnWidths []float64
Header bool
CellPadding float64
BorderWidth float64
FontSize float64
RowHeight float64
AtX, AtY float64
AtSet bool
}
TableOptions mirror the frequently used options of prawn-table's table method.
type TableResult ¶
TableResult reports the geometry of a rendered table.
type TextBoxOptions ¶
type TextBoxOptions struct {
X, Y float64
Width float64
Height float64
Align Align
Overflow Overflow
Size float64
Style Style
StyleSet bool
Font string
Leading float64
Color string
}
TextBoxOptions mirror the keyword arguments of Prawn::Document#text_box.
type TextOptions ¶
type TextOptions struct {
Size float64
Style Style
StyleSet bool
Font string
Align Align
Leading float64
Color string
// Kerning, when KerningSet is true, overrides the document kerning flag.
Kerning bool
KerningSet bool
}
TextOptions mirror the per-call keyword arguments of Prawn::Document#text / #draw_text (:size, :style, :align, :leading, :color, :kerning, and a per-call font family). Zero-value fields keep the document's current settings.
