Documentation
¶
Overview ¶
Package render is the drawing seam between the figure model and its output formats. A figure is laid out once, in pixels with y pointing down, and drawn through the Renderer interface; Raster and SVG implement it.
Index ¶
- Variables
- type Affine
- type Cap
- type Image
- type Join
- type Op
- type Path
- func (p *Path) Append(q *Path, m Affine)
- func (p *Path) Bounds() (x0, y0, x1, y1 float64, ok bool)
- func (p *Path) Circle(cx, cy, r float64)
- func (p *Path) Close()
- func (p *Path) CubicTo(c1x, c1y, c2x, c2y, x, y float64)
- func (p *Path) LineTo(x, y float64)
- func (p *Path) MoveTo(x, y float64)
- func (p *Path) QuadTo(cx, cy, x, y float64)
- func (p *Path) Rect(x, y, w, h float64)
- type Pt
- type Raster
- type Renderer
- type SVG
- type Seg
- type Style
Constants ¶
This section is empty.
Variables ¶
var Identity = Affine{A: 1, D: 1}
Identity is the identity transform.
Functions ¶
This section is empty.
Types ¶
type Affine ¶
type Affine struct{ A, B, C, D, E, F float64 }
Affine is the transform x' = A*x + C*y + E, y' = B*x + D*y + F.
type Image ¶
Image is a raster placed in the figure: Pix is drawn into the rectangle (X, Y, W, H) in pixels, with nearest-neighbour sampling.
type Path ¶
type Path struct{ Segs []Seg }
Path is an outline in pixel coordinates.
func (*Path) Bounds ¶
Bounds returns the bounding box of the path's points (control points included), or ok false for an empty path.
type Raster ¶
Raster renders into an RGBA image. Shapes are rasterised to anti-aliased coverage by go-gfx/gfx/vector (which draws every cap, join and dash a matplotlib line can have) and composited through go-widgets/painter's PixelPainter as a coverage mask under its clip stack; images go through the painter's DrawImage.
func NewRaster ¶
NewRaster returns a Raster of w x h pixels filled with nothing (transparent); the figure paints its own background.
func (*Raster) BeginGroup ¶
BeginGroup implements Renderer; a raster keeps no structure.
func (*Raster) DrawImage ¶
DrawImage implements Renderer: the rectangle is rounded to whole pixels and the painter scales the image into it, nearest neighbour.
type Renderer ¶
type Renderer interface {
// Size is the figure size in pixels.
Size() (w, h int)
// DrawPath paints a path.
DrawPath(p *Path, s Style)
// DrawImage paints a raster.
DrawImage(im Image)
// PushClip restricts drawing to a rectangle (intersected with any
// enclosing clip) until the matching PopClip.
PushClip(x, y, w, h float64)
PopClip()
// Group brackets a logical object (an artist) for formats that keep
// structure; id is a stable identifier such as "line2d_3". Raster
// formats ignore it.
BeginGroup(id string)
EndGroup()
}
A Renderer draws a figure. Coordinates are pixels, y down, origin at the top-left corner of the figure.
type SVG ¶
type SVG struct {
// contains filtered or unexported fields
}
SVG renders a figure as an SVG document. Coordinates are written in pixels at the figure's dpi, in a viewBox whose physical size is given in points, as matplotlib does; text arrives here already turned into glyph outlines, so the document needs no font.
type Style ¶
type Style struct {
Fill colors.RGBA
EvenOdd bool // fill rule; nonzero otherwise
Stroke colors.RGBA
Width float64 // pixels
Cap Cap // ignored for closed subpaths
Join Join //
Dash []float64 // on/off lengths in pixels; nil is solid
Offset float64 // dash offset in pixels
// Snap rounds the vertices of a path made only of horizontal and vertical
// segments to the pixel grid so that its strokes are crisp, as
// matplotlib's path snapping does for spines, ticks and grid lines.
Snap bool
}
Style says how a path is painted. A zero Fill.A paints no fill; a zero Width or Stroke.A paints no stroke. The fill is painted first.