svg

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: BSD-3-Clause Imports: 20 Imported by: 1

Documentation

Overview

Package svg implements parsing of SVG images. It transforms SVG text files into an in-memory structure that is easy to draw. CSS is supported via the `css` package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fl

type Fl = utils.Fl

type GradientSpread added in v0.0.2

type GradientSpread uint8

GradientSpread defines how a gradient should be repeated.

const (
	NoRepeat GradientSpread = iota
	Repeat
	Reflect
)

func (GradientSpread) LinearGradient added in v0.0.2

func (spread GradientSpread) LinearGradient(positions []Fl, colors []parser.RGBA, x1, y1, dx, dy, vectorLength Fl) backend.GradientLayout

LinearGradient handle spread (repeat) for linear gradients It is used for SVG and CSS gradient rendering.

func (GradientSpread) RadialGradient added in v0.0.2

func (spread GradientSpread) RadialGradient(positions []Fl, colors []parser.RGBA, fx, fy, fr, cx, cy, r, width, height Fl) backend.GradientLayout

type ImageLoader

type ImageLoader = func(url string) (backend.Image, error)

ImageLoader is used to resolve and process image url found in SVG files.

type Rectangle

type Rectangle struct {
	X, Y, Width, Height Fl
}

type SVGImage

type SVGImage struct {
	// contains filtered or unexported fields
}

func Parse

func Parse(svg io.Reader, baseURL string, imageLoader ImageLoader, urlFetcher utils.UrlFetcher) (*SVGImage, error)

Parse parsed the given SVG source data. Warnings are logged for unsupported elements. An error is returned for invalid documents. `baseURL` is used as base path for url resources. `urlFetcher` is required to handle linked SVG documents like in <use> tags. `imageLoader` is required to handle inner images.

func ParseNode added in v0.0.2

func ParseNode(root *html.Node, baseURL string, imageLoader ImageLoader, urlFetcher utils.UrlFetcher) (*SVGImage, error)

ParseNode is the same as Parse but works with an already parsed svg input.

func (*SVGImage) DisplayedSize

func (svg *SVGImage) DisplayedSize() (width, height Value)

DisplayedSize returns the value of the "width" and "height" attributes of the <svg> root element, which discribe the displayed size of the rectangular viewport. If no value is specified, it default to 100% (auto).

func (*SVGImage) Draw

func (svg *SVGImage) Draw(dst backend.Canvas, width, height Fl, textContext text.TextLayoutContext)

Draw draws the parsed SVG image into the given `dst` output, with the given `width` and `height`. `textContext` is required to properly layout <text> tags. It may be ommited for svg content not displaying text.

func (*SVGImage) ViewBox

func (svg *SVGImage) ViewBox() *Rectangle

ViewBox returns the optional value of the "viewBox" attribute

type Unit

type Unit uint8

Unit is an enum type for units supported in SVG images.

const (
	Px Unit
	Cm
	Mm
	Pt
	In
	Q
	Pc

	// Special case : percentage (%) relative to the viewbox
	Perc
	// Special case : relative to the font size
	Em
	Rem
	// Special case : relative to the font size
	Ex
)

Units supported.

func (Unit) String added in v0.0.2

func (u Unit) String() string

type Value

type Value struct {
	V Fl
	U Unit
}

Value is a Value expressed in a unit. It may be relative, meaning that context is needed to obtain the actual Value (see the `resolve` method)

func (Value) Resolve

func (v Value) Resolve(fontSize, percentageReference Fl) Fl

Resolve convert `v` to pixels, resolving percentage and units relative to the font size.

Jump to

Keyboard shortcuts

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