svg

package
v1.17.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package svg parses SVG documents into a tree of resolved drawing commands.

It is the parser and the painter of Glutter's SVG support (SPEC §26, D27): Parse reads a document into a tree, and (*Document).Picture records the tree into a ui.Picture (paint*.go; text, masks, filters and markers come in step 29.3). The package svg at the root of the module (flutter_svg's widgets) comes last. The package is plain Go and uses only the standard library (encoding/xml) and Glutter's own ui and software renderer (which makes the tiles of patterns).

What Parse does

  • It reads the XML into a light element tree (xml.go): elements and attributes of the SVG and xlink namespaces, CDATA and entities. Elements of other namespaces, and unknown elements, are skipped with their children.
  • It runs the CSS cascade (css.go, style.go): presentation attributes, then the rules of the <style> sheets by specificity and order, then the style attribute; !important beats all of them. The properties that inherit are inherited down the tree.
  • It resolves the values (values.go, affine.go, pathdata.go): lengths with every unit, colors, paints, transforms, viewBox, preserveAspectRatio and path data (as ui.Path).
  • It builds the tree of Node (build.go, resources.go, textnode.go): use is expanded with cycles cut and a limit, symbol and nested svg become viewports, switch keeps its first child whose conditions hold, and the references by id (gradients, patterns, clip paths, masks, filters, markers) become pointers.

Where units resolve

A length is a user-space number in the tree wherever the parser can know it: px, pt, pc, mm, cm and in at parse time, em, ex and rem with the element's computed font size (the root's is Theme.FontSize), and a percentage against the nearest viewport in its dimension. What stays a Length with its unit is what depends on the object a paint server or a resource is applied to: the coordinates of gradients, patterns, masks and filters (a fraction of the bounding box under objectBoundingBox, a length of the viewport under userSpaceOnUse), which the painter resolves with Length.Resolve. A document whose root has neither a viewBox nor a width and a height has no viewport: its percentages are invalid and ignored.

currentColor is resolved at parse time with the color property (Theme.CurrentColor at the root), so a Document is made for one Theme, and the cache of package svg is keyed by source and theme.

Source of the behavior

The code follows the SVG 1.1 and SVG 2 specifications and CSS 2.1; comments name the section they implement, in place of "Flutter:".

Index

Constants

View Source
const (
	// TagSvgInvalidValue is the tag of the error for a value that must be valid and is not, such as a viewBox with a
	// negative size; the metadata are "attribute" and "value". Invalid values of other attributes are ignored.
	TagSvgInvalidValue = "SvgInvalidValue"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const (
	// TagSvgNotSvg is the tag of the error for a document whose root element is not svg; the metadata is "element".
	TagSvgNotSvg = "SvgNotSvg"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

View Source
const (
	// TagSvgParseFailed is the tag of the error for a document whose XML is not well formed (or is empty, compressed
	// wrongly or in an encoding that is not supported); the metadata are "line" and "column".
	TagSvgParseFailed = "SvgParseFailed"
)

The tags of the errors that this file makes (rm4n0s/errors, R5).

Variables

DefaultPaintOrder is fill, stroke, markers.

View Source
var Identity = Affine{A: 1, D: 1}

Identity is the transform that moves nothing.

Functions

func ParseColor

func ParseColor(s string) (c ui.Color, current, ok bool)

ParseColor parses a color: a keyword, #rgb, #rgba, #rrggbb, #rrggbbaa, rgb()/rgba(), hsl()/hsla() or "transparent". currentColor is reported by the second result and has no color.

SVG 1.1: types.html#DataTypeColor; SVG 2: painting.html#SpecifyingPaint

func ParseNumberList

func ParseNumberList(s string) ([]float64, bool)

ParseNumberList parses a list of numbers separated by white space and commas, such as the values of a feColorMatrix or of stdDeviation. It returns false if anything else is in the text.

SVG 1.1: types.html#DataTypeList

func ParsePathData

func ParsePathData(d string) (*ui.Path, bool)

ParsePathData parses the d attribute of a path into a ui.Path with the commands M, L, H, V, C, S, Q, T, A and Z, absolute and relative. Numbers may be written as the specification allows ("1.5.5" is 1.5 and .5, "-1-2" is -1 and -2, and the flags of an arc may follow each other without separators). Parsing stops at the first error, as browsers do, and the path keeps what came before it; the second result is false in that case. Data that does not start with a moveto gives an empty path.

SVG 1.1: paths.html#PathDataBNF; SVG 2: paths.html#PathDataErrorHandling

Types

type Affine

type Affine struct {
	A, B, C, D, E, F float64
}

Affine is a 2D affine transform in the order of SVG's matrix(a b c d e f): a point (x, y) goes to (A·x + C·y + E, B·x + D·y + F).

SVG 1.1: coords.html#TransformMatrixDefined

func ParseTransform

func ParseTransform(s string) (Affine, bool)

ParseTransform parses a transform list (matrix, translate, scale, rotate, skewX and skewY, separated by white space and commas). A list with an error is not valid as a whole, and the result is false.

SVG 1.1: coords.html#TransformAttribute

func Rotate

func Rotate(deg float64) Affine

Rotate returns a rotation by deg degrees about the origin.

func Scale

func Scale(sx, sy float64) Affine

Scale returns a scale.

func Translate

func Translate(tx, ty float64) Affine

Translate returns a translation.

func ViewBoxTransform

func ViewBoxTransform(vb ViewBox, par PreserveAspectRatio, w, h float64) Affine

ViewBoxTransform returns the transform that places a viewBox in a viewport of w x h, as preserveAspectRatio says: none stretches it, meet scales it to fit inside, and slice to cover the viewport, and the alignment places the viewBox in the room that is left.

SVG 1.1: coords.html#PreserveAspectRatioAttribute

func (Affine) Apply

func (m Affine) Apply(x, y float64) (float64, float64)

Apply maps a point.

func (Affine) Det

func (m Affine) Det() float64

Det returns the determinant of the linear part.

func (Affine) Invert

func (m Affine) Invert() (Affine, bool)

Invert returns the inverse transform, or false if the transform has none (a zero determinant).

func (Affine) IsIdentity

func (m Affine) IsIdentity() bool

IsIdentity reports whether the transform moves nothing.

func (Affine) Matrix4

func (m Affine) Matrix4() *ui.Matrix4

Matrix4 returns the transform as the 4x4 matrix that ui.Canvas.Transform takes.

func (Affine) Mul

func (m Affine) Mul(n Affine) Affine

Mul returns the transform that applies n first and then m (the matrix product m·n). A transform list is the product of its items from left to right.

SVG 1.1: coords.html#TransformAttribute

type Align

type Align uint8

Align is the alignment part of preserveAspectRatio. The zero value is xMidYMid, the default.

SVG 1.1: coords.html#PreserveAspectRatioAttribute

const (
	// AlignXMidYMid is xMidYMid, the default.
	AlignXMidYMid Align = iota
	// AlignNone is none: the content is stretched to the viewport.
	AlignNone
	// AlignXMinYMin is xMinYMin.
	AlignXMinYMin
	// AlignXMidYMin is xMidYMin.
	AlignXMidYMin
	// AlignXMaxYMin is xMaxYMin.
	AlignXMaxYMin
	// AlignXMinYMid is xMinYMid.
	AlignXMinYMid
	// AlignXMaxYMid is xMaxYMid.
	AlignXMaxYMid
	// AlignXMinYMax is xMinYMax.
	AlignXMinYMax
	// AlignXMidYMax is xMidYMax.
	AlignXMidYMax
	// AlignXMaxYMax is xMaxYMax.
	AlignXMaxYMax
)

The alignments of preserveAspectRatio.

type ClipPath

type ClipPath struct {
	// Units is clipPathUnits (userSpaceOnUse by default).
	Units Units
	// Transform is the transform of the clipPath element.
	Transform Affine
	// ClipPath is the clip-path property of the clipPath element itself, or nil: the intersection of both clips.
	ClipPath *ClipPath
	// Children are the shapes, texts and uses that make the clip, as nodes. Their Path has the clip-rule as its fill
	// type, and the nodes with display: none or visibility: hidden are not in the list.
	Children []*Node
}

ClipPath is a clipPath element.

SVG 1.1: masking.html#EstablishingANewClippingPath

type ColorInterpolation

type ColorInterpolation uint8

ColorInterpolation is color-interpolation-filters.

SVG 1.1: painting.html#ColorInterpolationFiltersProperty

const (
	// ColorInterpolationLinearRGB is linearRGB, the default of filters.
	ColorInterpolationLinearRGB ColorInterpolation = iota
	// ColorInterpolationSRGB is sRGB (and auto).
	ColorInterpolationSRGB
)

type Document

type Document struct {
	// Root is the root svg element, a NodeSvg whose Viewport has the size of the document.
	Root *Node
	// Theme is the theme that the document was parsed with, with the defaults filled in.
	Theme Theme
	// Title and Desc are the text of the first title and desc elements that are children of the root; the semantics
	// label of the picture when the app gives none.
	Title, Desc string
	// contains filtered or unexported fields
}

Document is a parsed SVG document: a tree of nodes for one Theme. It is never changed after Parse returns, so it can be drawn from several goroutines.

SVG 1.1: struct.html#NewDocument

func Parse

func Parse(data []byte, opts ...ParseOpts) (*Document, error)

Parse reads an SVG document (XML, optionally gzip-compressed) and builds its tree. The errors are SvgParseFailed (the XML is not well formed), SvgNotSvg (the root is not an svg element) and SvgInvalidValue (a viewBox with a negative size); anything else that is wrong in the document is ignored, as browsers do.

SVG 1.1: struct.html#NewDocument

func (*Document) ApproximateBytes

func (d *Document) ApproximateBytes() int

ApproximateBytes estimates the memory that the document holds, in bytes: its nodes, paths, resources and images. It is meant to decide how many documents a cache keeps, not to account for memory exactly.

SVG 1.1: no counterpart

func (*Document) ContentBounds

func (d *Document) ContentBounds() ui.Rect

ContentBounds returns the bounds of the shapes of the document in the user space of the root (the fill geometry: no strokes, no text, no images). It is the empty rectangle for a document with no shape.

func (*Document) Picture

func (d *Document) Picture() *ui.Picture

Picture records the document into a ui.Picture in the document's own size (Size): the root viewport transform (viewBox and preserveAspectRatio) is applied inside it, so whoever draws the picture scales it to a widget. The picture is not clipped to the document; the widget clips it (SPEC §26.1).

It is PictureAt with a scale of 1.

SVG 1.1: render.html

func (*Document) PictureAt

func (d *Document) PictureAt(scale float64) *ui.Picture

PictureAt is Picture for a picture that will be drawn scale device pixels to one unit of the document. The scale matters only to what the picture rasterizes (the tiles of patterns are made with that many pixels, so that they stay sharp) and to vector-effect: non-scaling-stroke (a stroke is that many device pixels wide); everything else is vector and scales by itself. A scale that is not positive is 1.

SVG 1.1: pservers.html#Patterns; SVG 2: coords.html#VectorEffectProperty

func (*Document) PictureWith

func (d *Document) PictureWith(opts PictureOpts) *ui.Picture

PictureWith is PictureAt with the text engine of the app: the glyphs of the text are laid out by it, and recorded into the picture as outlines, so that replaying the picture needs no fonts.

SVG 1.1: render.html

func (*Document) ScaleDependent

func (d *Document) ScaleDependent() bool

ScaleDependent says whether the picture that the document records depends on the scale it is recorded at: it has a pattern (whose tile is rasterized at the device scale), a filter (whose buffer is), a stroke that does not scale, or an SVG image (which may have any of these). A picture of a document that is not scale dependent is the same at every scale, so a widget records it once and scales it; the others are recorded at the scale they are drawn at.

SVG 1.1: pservers.html#Patterns, filters.html

func (*Document) Size

func (d *Document) Size() ui.Size

Size returns the size of the document in user units: the picture's intrinsic size, as flutter_svg takes it from the width and height of the root or, without them, from the viewBox. It is zero if the document draws nothing that has a size.

A width or height that is a percentage counts as absent. A missing one comes from the viewBox with its aspect ratio; with no viewBox it comes from the bounds of the shapes (without strokes and text).

SVG 1.1: coords.html#IntrinsicSizing; SVG 2: coords.html#SizingSVGInCSS

func (*Document) ViewBox

func (d *Document) ViewBox() (ViewBox, bool)

ViewBox returns the viewBox of the root, or false if there is none.

type FillRule

type FillRule uint8

FillRule is fill-rule and clip-rule.

SVG 1.1: painting.html#FillRuleProperty

const (
	// FillRuleNonZero is nonzero, the default.
	FillRuleNonZero FillRule = iota
	// FillRuleEvenOdd is evenodd.
	FillRuleEvenOdd
)

type Filter

type Filter struct {
	// X, Y, Width and Height are the filter region (-10%, -10%, 120%, 120% by default).
	X, Y, Width, Height Length
	// Units is filterUnits (objectBoundingBox by default) and PrimitiveUnits is primitiveUnits (userSpaceOnUse by
	// default).
	Units, PrimitiveUnits Units
	// Primitives are the filter primitives in order, with the attributes and children of a filter that this one
	// refers to with href merged in as the specification says.
	Primitives []*FilterPrimitive
}

Filter is a filter element.

SVG 1.1: filters.html#FilterElement

type FilterPrimitive

type FilterPrimitive struct {
	// Name is the element's name ("feGaussianBlur").
	Name string
	// In and In2 are the in and in2 attributes ("" if not given: the previous result, or SourceGraphic for the
	// first primitive), and Result is the result attribute.
	In, In2, Result string
	// X, Y, Width and Height are the subregion; a nil pointer is not given (the default is the filter region, or the
	// union of the inputs' subregions).
	X, Y, Width, Height *Length
	// Attrs are the other attributes of the element as written ("stdDeviation", "dx", "values", "operator"), for the
	// painter to read with ParseNumberList, ParseLength and the like.
	Attrs map[string]string
	// Style has the color-interpolation-filters of the primitive (inherited from its filter), and Color,
	// Opacity are the flood-color and flood-opacity, or the lighting-color, resolved (black and 1 by default).
	Style        *Style
	FloodColor   ui.Color
	FloodOpacity float64
	// Children are the feMergeNode and feFunc elements, the light sources of lighting filters.
	Children []*FilterPrimitive
}

FilterPrimitive is one filter primitive element (feGaussianBlur, feOffset, ...).

SVG 1.1: filters.html#FilterPrimitivesOverview

type FontStyle

type FontStyle uint8

FontStyle is font-style.

const (
	// FontStyleNormal is normal, the default.
	FontStyleNormal FontStyle = iota
	// FontStyleItalic is italic.
	FontStyleItalic
	// FontStyleOblique is oblique.
	FontStyleOblique
)

type Gradient

type Gradient struct {
	// Radial is true for a radialGradient.
	Radial bool
	// X1, Y1, X2 and Y2 are the vector of a linear gradient (0%, 0%, 100%, 0% by default).
	X1, Y1, X2, Y2 Length
	// CX, CY, R, FX, FY and FR are the circles of a radial gradient (50%, 50%, 50%, then CX, CY and 0 by default).
	CX, CY, R, FX, FY, FR Length
	// Units says what the coordinates are relative to; a percentage under ObjectBoundingBox is a fraction of the
	// bounding box (Length.Resolve with ref 1), under UserSpaceOnUse of the viewport.
	Units Units
	// Transform is gradientTransform.
	Transform Affine
	// Spread is spreadMethod.
	Spread Spread
	// Stops are the stops with offsets in [0, 1] that never decrease, and the stop-opacity applied to the color.
	Stops []Stop
}

Gradient is a linearGradient or a radialGradient with the attributes it inherits through href already merged in: every field has its final value.

SVG 1.1: pservers.html#Gradients

type Image

type Image struct {
	// X, Y, Width and Height are the rectangle the image is fitted in. Width or Height is 0 when it is auto (not
	// given): the painter then takes the size of the image.
	X, Y, Width, Height float64
	// PreserveAspectRatio says how the image fits in the rectangle.
	PreserveAspectRatio PreserveAspectRatio
	// MIME is the media type of the data URL, in lower case ("image/png", "image/svg+xml").
	MIME string
	// Data is the decoded content of the URL.
	Data []byte
}

Image is an image element whose href is a data: URL.

SVG 1.1: struct.html#ImageElement

type Length

type Length struct {
	Value float64
	Unit  Unit
}

Length is a number with a unit.

SVG 1.1: types.html#DataTypeLength

func ParseLength

func ParseLength(s string) (Length, bool)

ParseLength parses a length with any unit (a number, or a number with px, pt, pc, mm, cm, in, em, ex, rem or %). White space around it is allowed.

SVG 1.1: types.html#DataTypeLength

func (Length) Resolve

func (l Length) Resolve(ref float64) float64

Resolve returns the length in user units. ref is what a percentage is a percentage of (the width of the viewport, or 1 for the fraction of a bounding box); a length with another unit than a percentage ignores it. A relative unit that is still in the length (em, ex, rem) resolves as the parser would with the default theme, which only happens for a Length made by ParseLength.

SVG 1.1: coords.html#Units

type LineCap

type LineCap uint8

LineCap is stroke-linecap.

SVG 1.1: painting.html#StrokeLinecapProperty

const (
	// LineCapButt is butt, the default.
	LineCapButt LineCap = iota
	// LineCapRound is round.
	LineCapRound
	// LineCapSquare is square.
	LineCapSquare
)

type LineJoin

type LineJoin uint8

LineJoin is stroke-linejoin.

SVG 1.1: painting.html#StrokeLinejoinProperty

const (
	// LineJoinMiter is miter, the default (miter-clip and arcs are drawn as miter).
	LineJoinMiter LineJoin = iota
	// LineJoinRound is round.
	LineJoinRound
	// LineJoinBevel is bevel.
	LineJoinBevel
)

type Marker

type Marker struct {
	// RefX and RefY are the point of the marker's content that is placed on the vertex, in the marker's content
	// units (viewBox units if there is a viewBox).
	RefX, RefY float64
	// Width and Height are markerWidth and markerHeight (3 by default).
	Width, Height float64
	// StrokeWidthUnits is true for markerUnits="strokeWidth" (the default): the marker is scaled by the stroke
	// width.
	StrokeWidthUnits bool
	// Orient is the orient attribute: OrientAuto, OrientAutoStartReverse or an angle in degrees in Angle.
	Orient OrientKind
	Angle  float64
	// ViewBox and PreserveAspectRatio place the content in Width and Height.
	ViewBox             *ViewBox
	PreserveAspectRatio PreserveAspectRatio
	// Overflow is true if the content is not clipped to the marker viewport.
	Overflow bool
	// Children are the content.
	Children []*Node
}

Marker is a marker element.

SVG 1.1: painting.html#MarkerElement

type Mask

type Mask struct {
	// X, Y, Width and Height are the region of the mask (-10%, -10%, 120%, 120% by default).
	X, Y, Width, Height Length
	// Units is maskUnits (objectBoundingBox by default) and ContentUnits is maskContentUnits (userSpaceOnUse by
	// default).
	Units, ContentUnits Units
	// Type is the mask-type property of the mask element.
	Type MaskType
	// Mask is the mask property of the mask element itself, or nil.
	Mask *Mask
	// Children are the content of the mask.
	Children []*Node
}

Mask is a mask element.

SVG 1.1: masking.html#Masking

type MaskType

type MaskType uint8

MaskType is mask-type.

SVG 2: masking.html#MaskTypeProperty

const (
	// MaskLuminance is luminance, the default.
	MaskLuminance MaskType = iota
	// MaskAlpha is alpha.
	MaskAlpha
)

type Node

type Node struct {
	Kind NodeKind
	// Name is the element's name in the source ("g", "rect", "use").
	Name string
	// ID is the id attribute, or "". A use gives its copies the id of the use (the copies of the referenced element
	// have none).
	ID string
	// Transform is the transform attribute (or the CSS transform property); for a use it includes the translation
	// by x and y.
	Transform Affine
	// Style is the computed style that inherits. It is shared between nodes that have the same one: do not change
	// it.
	Style *Style
	// Opacity is the opacity property (1 by default); it does not inherit.
	Opacity float64
	// ClipPath is the clip-path property, or nil. Missing references are ignored.
	ClipPath *ClipPath
	// Mask is the mask property, or nil.
	Mask *Mask
	// Filters are the url() references of the filter property, in order. References to a filter that does not
	// exist are dropped; an element with a filter function (blur(), ...) is drawn as if it had no filter.
	Filters []*Filter
	// VectorEffect is the vector-effect property; it does not inherit.
	VectorEffect VectorEffect
	// Children are the nodes drawn inside a NodeGroup or a NodeSvg, in order.
	Children []*Node
	// Path is the geometry of a NodeShape. Its fill type is the fill-rule of the style (the clip-rule inside a
	// clip path).
	Path *ui.Path
	// Shape says which element the NodeShape came from.
	Shape ShapeKind
	// Vertices are the vertices of a path, line, polyline or polygon, where its markers go; set only when the style has
	// a marker property.
	Vertices []Vertex
	// Viewport is set for a NodeSvg.
	Viewport *Viewport
	// Text is set for a NodeText.
	Text *TextSpan
	// Image is set for a NodeImage.
	Image *Image
}

Node is one drawable element of the tree. The parser has resolved its style, its geometry and its references, so that the painter draws it without reading any text again.

A node is drawn like this (SVG 1.1: render.html#RenderingOrder): apply Transform; clip to the viewport if it is a NodeSvg; if the node has ClipPath, Mask, Filters or an Opacity below 1, draw the content into a layer that these are applied to; draw the content: a shape fills and strokes Path with Style, a group draws its Children.

type NodeKind

type NodeKind uint8

NodeKind is the kind of a Node.

const (
	// NodeGroup draws its children in order: g, a, a use (its content is the child), and the child chosen by a
	// switch.
	NodeGroup NodeKind = iota
	// NodeSvg is a viewport: the root svg element, a nested svg, or a symbol that a use instantiated.
	NodeSvg
	// NodeShape is a path, rect, circle, ellipse, line, polyline or polygon, as a ui.Path in user units.
	NodeShape
	// NodeText is a text element.
	NodeText
	// NodeImage is an image with a data: URL.
	NodeImage
)

The kinds of nodes.

type OrientKind

type OrientKind uint8

OrientKind is the kind of value that the orient attribute of a marker has.

const (
	// OrientAngle is a fixed angle (Marker.Angle).
	OrientAngle OrientKind = iota
	// OrientAuto is auto.
	OrientAuto
	// OrientAutoStartReverse is auto-start-reverse.
	OrientAutoStartReverse
)

type Paint

type Paint struct {
	Kind  PaintKind
	Color ui.Color
	// Server is a *Gradient or a *Pattern when Kind is PaintKindServer.
	Server PaintServer
}

Paint is the value of fill and stroke.

SVG 1.1: painting.html#SpecifyingPaint

type PaintKind

type PaintKind uint8

PaintKind is the kind of a Paint.

const (
	// PaintKindNone draws nothing: the value none, a missing server without a fallback, or an invalid value.
	PaintKindNone PaintKind = iota
	// PaintKindColor is a color (currentColor is resolved to a color).
	PaintKindColor
	// PaintKindServer is a gradient or a pattern.
	PaintKindServer
)

type PaintLayer

type PaintLayer uint8

PaintLayer is one of the three things that paint-order orders.

const (
	// PaintLayerFill is fill.
	PaintLayerFill PaintLayer = iota
	// PaintLayerStroke is stroke.
	PaintLayerStroke
	// PaintLayerMarkers is markers.
	PaintLayerMarkers
)

type PaintServer

type PaintServer interface {
	// contains filtered or unexported methods
}

PaintServer is a Gradient or a Pattern.

type ParseOpts

type ParseOpts struct {
	// Theme gives currentColor, the font size and the x-height; the zero value is flutter_svg's default theme.
	Theme Theme
	// Locale picks the child of a switch by its systemLanguage; the zero value is "en".
	Locale ui.Locale
}

ParseOpts are the optional arguments of Parse.

type Pattern

type Pattern struct {
	// X, Y, Width and Height are the tile (0 by default).
	X, Y, Width, Height Length
	// Units is patternUnits (objectBoundingBox by default) and ContentUnits is patternContentUnits (userSpaceOnUse by
	// default).
	Units, ContentUnits Units
	// Transform is patternTransform.
	Transform Affine
	// ViewBox and PreserveAspectRatio place the content in the tile.
	ViewBox             *ViewBox
	PreserveAspectRatio PreserveAspectRatio
	// Children are the content of the tile.
	Children []*Node
}

Pattern is a pattern with the attributes and the children it inherits through href already merged in.

SVG 1.1: pservers.html#Patterns

type PictureOpts

type PictureOpts struct {
	// Scale is the number of device pixels to a unit of the document, as in PictureAt (1 if it is not positive).
	Scale float64
	// Text is the text engine that lays out the text of the document, with the fonts of the app (the dispatcher's
	// TextEngine). With nil the document lays its text out with the fonts that Glutter bundles (Roboto), so that
	// text works with no running app.
	Text ui.ParagraphFactory
}

PictureOpts are the arguments of PictureWith.

Flutter: no counterpart

type PreserveAspectRatio

type PreserveAspectRatio struct {
	Align Align
	// Slice is "slice" (the viewBox covers the viewport); false is "meet" (the viewBox fits in it).
	Slice bool
}

PreserveAspectRatio says how a viewBox fits its viewport. The zero value is "xMidYMid meet".

SVG 1.1: coords.html#PreserveAspectRatioAttribute

func ParsePreserveAspectRatio

func ParsePreserveAspectRatio(s string) (PreserveAspectRatio, bool)

ParsePreserveAspectRatio parses the value of preserveAspectRatio: an optional "defer", the alignment, and an optional "meet" or "slice". The text is case sensitive in SVG, but the alignment is matched without regard to case here, as browsers' tolerance goes no further than that.

SVG 1.1: coords.html#PreserveAspectRatioAttribute

type ShapeKind

type ShapeKind uint8

ShapeKind is the element a NodeShape came from.

const (
	ShapePath ShapeKind = iota
	ShapeRect
	ShapeCircle
	ShapeEllipse
	ShapeLine
	ShapePolyline
	ShapePolygon
)

The shape elements.

type ShapeRendering

type ShapeRendering uint8

ShapeRendering is shape-rendering.

SVG 1.1: painting.html#ShapeRenderingProperty

const (
	// ShapeRenderingAuto is auto (and optimizeSpeed and geometricPrecision), the default.
	ShapeRenderingAuto ShapeRendering = iota
	// ShapeRenderingCrispEdges is crispEdges: no anti-aliasing.
	ShapeRenderingCrispEdges
)

type Spread

type Spread uint8

Spread is spreadMethod.

SVG 1.1: pservers.html#GradientSpreadMethod

const (
	// SpreadPad is pad, the default.
	SpreadPad Spread = iota
	// SpreadReflect is reflect.
	SpreadReflect
	// SpreadRepeat is repeat.
	SpreadRepeat
)

type Stop

type Stop struct {
	Offset float64
	Color  ui.Color
}

Stop is a gradient stop.

SVG 1.1: pservers.html#GradientStops

type Style

type Style struct {
	// Color is the color property, the value of currentColor (Theme.CurrentColor at the root).
	Color ui.Color
	// Fill and Stroke are the paints; the initial Fill is black and the initial Stroke is none.
	Fill, Stroke Paint
	// FillOpacity and StrokeOpacity are in [0, 1].
	FillOpacity, StrokeOpacity float64
	// FillRule and ClipRule are the winding rules.
	FillRule, ClipRule FillRule
	// StrokeWidth is in user units (1 by default).
	StrokeWidth float64
	// LineCap and LineJoin are the stroke's.
	LineCap  LineCap
	LineJoin LineJoin
	// MiterLimit is stroke-miterlimit (4 by default).
	MiterLimit float64
	// DashArray is stroke-dasharray in user units: nil for none, otherwise an even number of values that are not all
	// zero (an odd list is repeated twice, as the specification says).
	DashArray []float64
	// DashOffset is stroke-dashoffset in user units.
	DashOffset float64
	// Visible is false for visibility: hidden and collapse.
	Visible bool
	// ShapeRendering is shape-rendering.
	ShapeRendering ShapeRendering
	// PaintOrder is paint-order (DefaultPaintOrder by default).
	PaintOrder [3]PaintLayer
	// MarkerStart, MarkerMid and MarkerEnd are the marker properties, or nil.
	MarkerStart, MarkerMid, MarkerEnd *Marker
	// ColorInterpolationFilters is color-interpolation-filters.
	ColorInterpolationFilters ColorInterpolation

	// FontFamily is the font-family list, quotes removed; generic names such as sans-serif are kept as written.
	FontFamily []string
	// FontSize is the computed font size in user units.
	FontSize float64
	// FontWeight is the weight from 1 to 1000 (400 normal, 700 bold).
	FontWeight int
	// FontStyle is font-style.
	FontStyle FontStyle
	// TextAnchor is text-anchor.
	TextAnchor TextAnchor
	// TextDecoration is the lines of text-decoration. Deviation: the property does not inherit in CSS, but the lines
	// are drawn on the descendants of the text, so it is kept here.
	TextDecoration TextDecoration
	// LetterSpacing and WordSpacing are in user units (0 for normal).
	LetterSpacing, WordSpacing float64
}

Style is the computed style of the properties that inherit. Nodes that inherit everything share one Style, so it is never changed after the parser has made it.

SVG 1.1: styling.html; CSS 2.1: cascade.html#inheritance

type TextAnchor

type TextAnchor uint8

TextAnchor is text-anchor.

SVG 1.1: text.html#TextAnchorProperty

const (
	// TextAnchorStart is start, the default.
	TextAnchorStart TextAnchor = iota
	// TextAnchorMiddle is middle.
	TextAnchorMiddle
	// TextAnchorEnd is end.
	TextAnchorEnd
)

type TextDecoration

type TextDecoration uint8

TextDecoration is the set of lines of text-decoration.

const (
	TextDecorationUnderline TextDecoration = 1 << iota
	TextDecorationOverline
	TextDecorationLineThrough
)

The lines of a text decoration; they combine.

type TextItem

type TextItem struct {
	Text string
	Span *TextSpan
}

TextItem is a string or a span inside a span. The strings have the white space handled as xml:space says (collapsed by default).

type TextSpan

type TextSpan struct {
	// Name is "text", "tspan", "textPath" or "tref".
	Name string
	// X, Y, Dx, Dy and Rotate are the lists of the attributes, in user units (degrees for Rotate); the nth value
	// applies to the nth character of the element and of its descendants, counting from the start of the text
	// element. A nil list is an absent attribute.
	X, Y, Dx, Dy, Rotate []float64
	// TextLength is the textLength attribute, or 0 if not given, and AdjustGlyphs is lengthAdjust="spacingAndGlyphs".
	TextLength   float64
	AdjustGlyphs bool
	// Style is the computed style of the span.
	Style *Style
	// Items are the content in order: strings and spans.
	Items []TextItem
	// PathData is the geometry that a textPath follows, in the user space of the text element (the transform of the
	// path element applied), or nil. StartOffset is startOffset in user units, or a fraction of the path's length
	// if StartOffsetFraction is true.
	PathData            *ui.Path
	StartOffset         float64
	StartOffsetFraction bool
}

TextSpan is a text, tspan, textPath or tref: a run of text with its position lists and its own style.

SVG 1.1: text.html#TextElement

type Theme

type Theme struct {
	// CurrentColor is the value of currentColor at the root (black by default: the zero Color means the default).
	CurrentColor ui.Color
	// FontSize is the font size of the root in user units and the value of 1em there (14 by default).
	FontSize float64
	// XHeight is the value of 1ex at the root (half of the font size by default).
	XHeight float64
}

Theme is the part of the theme of the widget (flutter_svg's SvgTheme) that the parser uses.

SVG 1.1: styling.html#ColorProperty

type Unit

type Unit uint8

Unit is the unit of a Length.

SVG 1.1: types.html#DataTypeLength

const (
	// UnitPx is a user unit: a plain number, or a length in px.
	UnitPx Unit = iota
	// UnitPercent is a percentage of the reference length of the attribute, as Value/100 of it.
	UnitPercent
	// UnitPt is 1/72 inch.
	UnitPt
	// UnitPc is 1/6 inch.
	UnitPc
	// UnitMm is a millimeter.
	UnitMm
	// UnitCm is a centimeter.
	UnitCm
	// UnitIn is an inch, 96 user units.
	UnitIn
	// UnitEm is the computed font size of the element.
	UnitEm
	// UnitEx is the x-height of the element's font.
	UnitEx
	// UnitRem is the font size of the root.
	UnitRem
)

The units of lengths. After parsing, a Length in the tree has the unit UnitPx (a number of user units) or UnitPercent; the others are converted when the length is parsed (see the package documentation).

type Units

type Units uint8

Units is the value of gradientUnits, patternUnits, clipPathUnits, maskUnits and the like.

SVG 1.1: coords.html#ObjectBoundingBox

const (
	// UnitsObjectBoundingBox is objectBoundingBox.
	UnitsObjectBoundingBox Units = iota
	// UnitsUserSpaceOnUse is userSpaceOnUse.
	UnitsUserSpaceOnUse
)

type VectorEffect

type VectorEffect uint8

VectorEffect is the vector-effect property.

SVG 2: coords.html#VectorEffectProperty

const (
	// VectorEffectNone is none.
	VectorEffectNone VectorEffect = iota
	// VectorEffectNonScalingStroke is non-scaling-stroke: the stroke width is in the device's pixels.
	VectorEffectNonScalingStroke
)

type Vertex

type Vertex struct {
	X, Y float64
	// In is the direction of the path arriving at the vertex and Out the direction leaving it; HasIn and HasOut say
	// whether there is one (the first vertex has no In, the last no Out, and a segment of no length has none).
	In, Out       [2]float64
	HasIn, HasOut bool
}

Vertex is a vertex of a shape, where a marker may be drawn: its position and the directions of the path that arrives at it and leaves it.

SVG 1.1: painting.html#MarkerOrientAttribute

type ViewBox

type ViewBox struct {
	X, Y, Width, Height float64
}

ViewBox is the user-space rectangle that a viewport shows.

SVG 1.1: coords.html#ViewBoxAttribute

func (ViewBox) Rect

func (v ViewBox) Rect() ui.Rect

Rect returns the view box as a ui.Rect.

type Viewport

type Viewport struct {
	// X and Y are the position of the viewport in the user space of its parent (0 for the root and for a symbol).
	X, Y float64
	// Width and Height are the size of the viewport in the parent's user units. For the root they are the document's
	// size (Document.Size); for a nested svg or a symbol they are width and height resolved against the parent
	// viewport (100% by default).
	Width, Height float64
	// ViewBox is the viewBox, or nil.
	ViewBox *ViewBox
	// PreserveAspectRatio says how ViewBox fits in the viewport.
	PreserveAspectRatio PreserveAspectRatio
	// Overflow is true if the content is not clipped to the viewport (overflow: visible or auto). It is false by
	// default for a nested svg and a symbol; the root is not clipped by the document, the widget clips it.
	Overflow bool
	// Root is true for the root svg element.
	Root bool
}

Viewport is the viewport that an svg element, or a symbol, establishes.

SVG 1.1: coords.html#EstablishingANewSVGViewport

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL