Documentation
¶
Overview ¶
Package pdf writes small, self-contained PDF documents for CipherHorizon's reports: A4 pages, the four standard fonts (no font files to embed), filled and stroked shapes, links and a flat outline. It needs nothing beyond the standard library and x/text, which the module already uses.
The API places things from the top-left corner of the page, in points (1/72 inch), the way a layout is designed; the writer converts to PDF's bottom-left coordinates.
Index ¶
- Constants
- func ChipHeight(c Chip) float64
- func ChipWidth(c Chip) float64
- func Clean(s string) string
- func DrawChip(p *Page, x, y float64, c Chip) float64
- func DrawLine(p *Page, spans []Span, l Line, x, y float64, align int)
- func Encode(s string) []byte
- func Width(f Font, size float64, s string) float64
- type Block
- type BoxStyle
- type Cell
- type Chip
- type Col
- type Color
- type Custom
- type Doc
- type Flow
- type Font
- type Gap
- type Line
- type Page
- func (p *Page) Circle(cx, cy, r float64, fill Color)
- func (p *Page) Index() int
- func (p *Page) Line(x1, y1, x2, y2, lw float64, c Color)
- func (p *Page) Link(x, y, w, h float64, url string)
- func (p *Page) Polygon(fill Color, pts ...[2]float64)
- func (p *Page) Rect(x, y, w, h float64, fill Color)
- func (p *Page) RoundRect(x, y, w, h, r float64, fill Color, lw float64, stroke Color)
- func (p *Page) StrokeRect(x, y, w, h, lw float64, c Color)
- func (p *Page) Text(x, y float64, f Font, size float64, c Color, s string)
- func (p *Page) TextRight(x, y float64, f Font, size float64, c Color, s string)
- type Para
- type Span
- type TableStyle
Constants ¶
const ( PageWidth = 595.28 PageHeight = 841.89 )
A4 in points.
Variables ¶
This section is empty.
Functions ¶
func DrawLine ¶
DrawLine draws a wrapped line with its left edge at x and its baseline at y. align: 0 left, 1 right (x is then the right edge), 2 centre (x is the centre).
Types ¶
type Block ¶
Block is something a Flow places: it knows its height at a width and how to draw itself with its top-left corner at x, y.
type BoxStyle ¶
type BoxStyle struct {
Fill, Border, Accent Color
HasFill, HasBorder bool
AccentWidth float64 // a coloured bar down the left edge
Pad float64
Radius float64
After float64
}
BoxStyle styles a boxed group of blocks.
type Col ¶
type Col struct {
Title string
W float64 // a share of the table width
Align int // 0 left, 1 right, 2 centre
}
Col is a table column.
type Color ¶
type Color struct{ R, G, B float64 }
Color is an RGB colour with components from 0 to 1.
type Doc ¶
type Doc struct {
Title string
Subject string
Creator string
Created time.Time
// contains filtered or unexported fields
}
Doc is a document being written.
type Flow ¶
type Flow struct {
Doc *Doc
Page *Page
Left, Right, Top, Bottom float64
Y float64
// Header, when set, runs on every page the flow starts and may move Y.
Header func(f *Flow)
}
Flow places blocks down the page and starts new pages as needed.
func (*Flow) Add ¶
Add places blocks in order. A paragraph that does not fit continues on the next page line by line; other blocks move whole.
func (*Flow) Box ¶
Box draws blocks inside a box. A box taller than a page is drawn without its frame so that it can break.
type Line ¶
type Line struct {
Width float64
Size float64 // the largest font size on the line
// contains filtered or unexported fields
}
Line is one wrapped line of a paragraph.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is one page; draw on it with its methods.
func (*Page) Link ¶
Link makes a rectangle (top-left x, y) open url when clicked. Only http and https addresses are linked.
func (*Page) Polygon ¶
Polygon fills the closed shape through the points (x, y pairs, top-left origin).
func (*Page) RoundRect ¶
RoundRect fills a rectangle with rounded corners of radius r; with lw > 0 it also strokes it in stroke.
func (*Page) StrokeRect ¶
StrokeRect outlines a rectangle.
type Para ¶
type Para struct {
Spans []Span
Leading float64 // line height as a multiple of the font size; 1.35 when zero
Indent float64 // left indent
After float64 // space after the paragraph
Bullet string // drawn in the indent, e.g. "•" or "1."
Align int
}
Para is a paragraph block.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pdfcheck reads back the PDFs package pdf writes, for tests: it checks the cross-reference table points at every object, then returns the page count, the text shown, the links and the outline titles.
|
Package pdfcheck reads back the PDFs package pdf writes, for tests: it checks the cross-reference table points at every object, then returns the page count, the text shown, the links and the outline titles. |