Documentation
¶
Overview ¶
Package svg renders an SVG drawing. It is a document the way the other formats of this module are: a file opens, it has one page, and the page runs onto the same gfx.Device a PDF page draws through.
What is drawn is the static picture: shapes and paths, transforms and viewports, the three paint servers, clips, masks, markers, filters, and text on a path or down the page, shaped and reordered. Scripting, animation and interaction are not a picture and are not read.
Index ¶
- Variables
- func Decode(r io.Reader) (image.Image, error)
- func DecodeConfig(r io.Reader) (image.Config, error)
- type Device
- type Document
- func Load(b []byte) (*Document, error)
- func LoadWith(b []byte, o *LoadOptions) (*Document, error)
- func NewReader(r io.ReaderAt, size int64) (*Document, error)
- func NewStream(r io.Reader) (*Document, error)
- func NewStreamWith(r io.Reader, o *LoadOptions) (*Document, error)
- func Open(name string) (*Document, error)
- type Link
- type LoadOptions
- type Metadata
- type Options
- type Page
- func (p *Page) Bounds() raster.Rect
- func (p *Page) DeviceBounds(dpi float64) raster.Rect
- func (p *Page) HTML() (string, error)
- func (p *Page) Image() (*image.RGBA, error)
- func (p *Page) ImageDPI(dpi float64) (*image.RGBA, error)
- func (p *Page) ImageSize(w, h int) (*image.RGBA, error)
- func (p *Page) Links() []Link
- func (p *Page) Matrix(dpi float64) raster.Matrix
- func (p *Page) Render(ctm raster.Matrix, o *Options) (*raster.Pixmap, error)
- func (p *Page) RenderTo(dst draw.Image, ctm raster.Matrix, o *Options) error
- func (p *Page) Run(dev Device, ctm raster.Matrix) error
- func (p *Page) SVG() (string, error)
- func (p *Page) StructuredText() (*TextPage, error)
- func (p *Page) StructuredTextOptions(o *TextOptions) (*TextPage, error)
- func (p *Page) Text() (string, error)
- func (p *Page) WriteHTML(w io.Writer) error
- func (p *Page) WriteSVG(w io.Writer) error
- type Quad
- type TextBlock
- type TextChar
- type TextLine
- type TextOptions
- type TextPage
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalid = errors.New("svg: invalid") ErrUnsupported = errors.New("svg: unsupported") )
Errors returned by this package. A file that is not SVG at all, or whose XML does not parse, is ErrInvalid; one this cannot draw is ErrUnsupported.
Functions ¶
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is one SVG file.
func LoadWith ¶
func LoadWith(b []byte, o *LoadOptions) (*Document, error)
LoadWith reads an SVG drawing out of memory, resolving what it names through a loader and sizing it against the box a container gives it.
func NewStream ¶ added in v0.2.0
NewStream reads a drawing from a stream that cannot be seeked, which means reading all of it into memory first. A caller with an untrusted source bounds it with io.LimitReader.
func NewStreamWith ¶ added in v0.2.0
func NewStreamWith(r io.Reader, o *LoadOptions) (*Document, error)
NewStreamWith is NewStream with the options LoadWith takes.
type Link ¶ added in v0.2.0
type Link struct {
// Rect is the area the link covers, in the drawing's own coordinates.
Rect raster.Rect
// URI is where a link out of the drawing points, and "" for one inside.
URI string
// Fragment is the element a link inside the drawing names.
Fragment string
}
Link is a link in a drawing: the area it covers, and where following it goes.
type LoadOptions ¶
type LoadOptions struct {
// Open resolves an address the drawing names, relative to the drawing
// itself, which is how one inside a container reaches a picture beside
// it. A nil Open resolves nothing but a data URL.
Open func(name string) ([]byte, error)
// Width and Height are the box the drawing is placed in, which is what a
// percentage size on the root element measures against.
Width, Height float32
}
LoadOptions are what a caller says about a drawing before it is read. A nil pointer, and a zero field, is the default.
type Metadata ¶ added in v0.2.0
type Metadata struct {
// Title and Description are the title and desc elements of the root.
Title string
Description string
}
Metadata is what a drawing says about itself.
type Options ¶
type Options struct {
// PixelLimit bounds the pixel area a drawing may allocate. Zero is the
// default of 2^28 and a negative number is no limit at all.
PixelLimit int
// Alpha keeps the background transparent rather than filling it white,
// which is what a drawing meant to sit on something else wants.
Alpha bool
// Flatness is how far a curve may sit from the lines that stand in for
// it, in device pixels.
Flatness float32
}
Options are what a caller may change about a render; nil is the defaults.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page is the drawing.
func (*Page) Bounds ¶
Bounds is how big the drawing is, in CSS pixels, which is what a viewer draws it at when it is not told otherwise.
func (*Page) DeviceBounds ¶
DeviceBounds is the area the page covers at a resolution.
func (*Page) Image ¶ added in v0.2.0
Image renders the drawing at the size it asks to be, a pixel per pixel.
func (*Page) ImageDPI ¶
ImageDPI renders the drawing at a resolution, where 96 is the pixel its lengths are written in.
func (*Page) ImageSize ¶
ImageSize renders the drawing into an image of exactly w by h pixels, scaling it to fit and keeping its aspect ratio, which is what an icon at the size a caller has room for wants. A zero side is taken from the other.
func (*Page) Links ¶ added in v0.2.0
Links returns the links the drawing carries, one for every anchor element that covers something, in the order they are written.
func (*Page) Matrix ¶
Matrix is the transform that puts the drawing on a device at a resolution, where 96 is the pixel an SVG length is written in.
func (*Page) RenderTo ¶
RenderTo draws the drawing into a destination the caller owns, with ctm mapping it onto that image's coordinates. This is how an icon is composited onto something already drawn rather than handed back on its own.
func (*Page) StructuredText ¶
StructuredText returns the drawing's text with the box every character, line and block occupies, in the coordinates the drawing is written in.
func (*Page) StructuredTextOptions ¶
func (p *Page) StructuredTextOptions(o *TextOptions) (*TextPage, error)
StructuredTextOptions is StructuredText with options.
func (*Page) Text ¶
Text returns the drawing's text: a newline after every line and a blank line after every block.
type TextOptions ¶
type TextOptions = gfx.TextOptions
TextOptions configure what StructuredTextOptions collects.