Documentation
¶
Overview ¶
Package officecanvas records a laid-out page as the editable objects an office presentation is made of — filled shapes, gradient-filled shapes, lines of text in text boxes, and pictures — instead of drawing it. It is a paint.Canvas: PageLayout.PaintVector draws through it exactly as it draws a PDF page through pdfcanvas, so an editable slide has the layout of the image and PDF exports by construction. The recorded Page is format-neutral, in device pixels; a writer maps it to DrawingML (PresentationML) or to ODF draw elements.
What a slide format cannot hold the paint layer already turned into pictures (an element under opacity, a filter, a blurred shadow); those arrive here as images, with their text as invisible runs over them.
Things a slide cannot do that a page can: clip. A gradient or a picture inside a clip takes the clip's outline (a rounded box) or is cropped to its bounds; a filled shape ignores the clips around it, which are the overflow clips of its ancestors and cut nothing on a slide that fits.
Index ¶
- func SFNT(f *opentype.Font) []byte
- type Canvas
- func (c *Canvas) Clip(p *paint.Path, evenOdd bool)
- func (c *Canvas) Fill(p *paint.Path, col css.Color, evenOdd bool)
- func (c *Canvas) Glyphs(run *paint.GlyphRun)
- func (c *Canvas) Image(img image.Image, dst paint.Rect)
- func (c *Canvas) Page() Page
- func (c *Canvas) Restore()
- func (c *Canvas) Save()
- func (c *Canvas) Shade(s paint.Shading)
- type Face
- type Gradient
- type Kind
- type Link
- type Page
- type Run
- type Shape
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SFNT ¶
SFNT reassembles a parsed font into a font file — the offset table, the table directory with each table's checksum, the tables padded to four bytes — from the tables it carries (OpenType "Organization of an OpenType Font"), so that the very font a page was laid out with can be embedded whole. It returns nil for a font past 32 MiB.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas records a page. Build one per page with New; it is not safe for concurrent use.
func New ¶
New starts recording a page of the given device-pixel size. links are the page's clickable areas (engine.PageLayout.Links). faces, shared across the pages of one document, maps each font to its Face; nil gets a fresh map.
func (*Canvas) Clip ¶
Clip implements paint.Canvas: the clip is remembered, to shape what is drawn in it.
func (*Canvas) Glyphs ¶
Glyphs implements paint.Canvas: the run becomes text, joined to the line being built when it continues it — the same baseline, a word's space further — so that a line of words is one editable text box.
func (*Canvas) Image ¶
Image implements paint.Canvas: a picture, cropped to the innermost clip's bounds when the clip cuts it (a background image sized to cover its box).
type Face ¶
type Face struct {
Font *opentype.Font
Family string // the name a document names it by (name ID 1)
Bold, Italic bool // its style within that family (name ID 2)
// Embeddable is false when the font's OS/2 fsType forbids embedding it
// in an editable document (restricted, or preview & print only).
Embeddable bool
}
Face is a font face the runs are set in.
type Gradient ¶
type Gradient struct {
Radial bool
Angle float64
Center [2]float64
Stops []paint.GradientStop
Shadings []paint.Shading
}
Gradient is a gradient fill in office terms: stops along a direction across the shape's box, or around a centre.
Linear: Angle is the direction of colour change in degrees clockwise from the x axis (y down), and the stops run across the projection of the box on that direction — DrawingML's unscaled a:lin, and CSS's gradient line. Radial: the stops run from Center (fractions of the box) outwards.
Shadings are the paint-level shadings it was made from, for a writer that cannot express it and draws it as a picture (Shape.Render).
type Page ¶
type Page struct {
// Background is the colour of a fill covering the whole page drawn
// before anything else: the slide's background. Nil when there is none.
Background *css.Color
Shapes []Shape
}
Page is what was drawn on one page.
type Run ¶
type Run struct {
Text string
Face *Face
Size float64
Color css.Color
Link string
Invisible bool
// Spacing is the space added after each character beyond its own
// advance (CSS letter-spacing), in device pixels.
Spacing float64
}
Run is a stretch of a text line in one face, size and colour. Size is in device pixels. Invisible text is there to be found and copied over a picture of the same words; it is drawn with zero alpha.
type Shape ¶
type Shape struct {
Kind Kind
Bounds paint.Rect
// Path is the outline of a fill or gradient, absolute, and EvenOdd its
// rule (overlaps are holes). Rect is set when the outline is Bounds
// itself.
Path *paint.Path
EvenOdd bool
Rect bool
Color css.Color // KindFill
Gradient *Gradient // KindGradient
Runs []Run // KindText
Image image.Image // KindImage
// Crop is what to remove from the picture's left, top, right and
// bottom, as fractions, before it is stretched over Bounds.
Crop [4]float64
}
Shape is one recorded object. Bounds is its box in device pixels.
func (*Shape) Render ¶
Render draws a gradient shape as a picture of its Bounds, scale pixels per device pixel: the shadings it was made from, through its outline, antialiased, transparent outside. It is for a format whose gradients cannot say what this one says (more than two stops, varying opacity). It returns nil for another kind of shape, or one past 16 Mpx.