svg

package
v2.20.20 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 11 Imported by: 104

Documentation

Overview

Package svg minifies SVG1.1 following the specifications at http://www.w3.org/TR/SVG11/.

Index

Examples

Constants

This section is empty.

Variables

View Source
var HashMap = map[string]Hash{}/* 110 elements not displayed */

Functions

func Minify

func Minify(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error

Minify minifies SVG data, it reads from r and writes to w.

Example
m := minify.New()
m.AddFunc("image/svg+xml", Minify)
m.AddFunc("text/css", css.Minify)

if err := m.Minify("image/svg+xml", os.Stdout, os.Stdin); err != nil {
	panic(err)
}
Output:

Types

type Hash added in v2.7.0

type Hash uint32

Hash defines perfect hashes for a predefined list of strings

const (
	A                            Hash = 0x101   // a
	Alignment_Baseline           Hash = 0x2e12  // alignment-baseline
	BaseProfile                  Hash = 0xb     // baseProfile
	Baseline_Shift               Hash = 0x380e  // baseline-shift
	Buffered_Rendering           Hash = 0x5212  // buffered-rendering
	Clip                         Hash = 0x6404  // clip
	Clip_Path                    Hash = 0x6409  // clip-path
	Clip_Rule                    Hash = 0x8009  // clip-rule
	Color                        Hash = 0xd805  // color
	Color_Interpolation          Hash = 0xd813  // color-interpolation
	Color_Interpolation_Filters  Hash = 0xd81b  // color-interpolation-filters
	Color_Profile                Hash = 0x1f70d // color-profile
	Color_Rendering              Hash = 0x2320f // color-rendering
	ContentScriptType            Hash = 0xa011  // contentScriptType
	ContentStyleType             Hash = 0xb110  // contentStyleType
	Cursor                       Hash = 0xc106  // cursor
	D                            Hash = 0x5901  // d
	Defs                         Hash = 0x36904 // defs
	Direction                    Hash = 0x30c09 // direction
	Display                      Hash = 0x9807  // display
	Dominant_Baseline            Hash = 0x19211 // dominant-baseline
	Enable_Background            Hash = 0x8811  // enable-background
	FeImage                      Hash = 0x14507 // feImage
	Fill                         Hash = 0xc904  // fill
	Fill_Opacity                 Hash = 0x33d0c // fill-opacity
	Fill_Rule                    Hash = 0xc909  // fill-rule
	Filter                       Hash = 0xec06  // filter
	Flood_Color                  Hash = 0xd20b  // flood-color
	Flood_Opacity                Hash = 0x1050d // flood-opacity
	Font                         Hash = 0x11404 // font
	Font_Family                  Hash = 0x1140b // font-family
	Font_Size                    Hash = 0x11f09 // font-size
	Font_Size_Adjust             Hash = 0x11f10 // font-size-adjust
	Font_Stretch                 Hash = 0x1370c // font-stretch
	Font_Style                   Hash = 0x14c0a // font-style
	Font_Variant                 Hash = 0x1560c // font-variant
	Font_Weight                  Hash = 0x1620b // font-weight
	ForeignObject                Hash = 0x16d0d // foreignObject
	G                            Hash = 0x1601  // g
	Glyph_Orientation_Horizontal Hash = 0x1d31c // glyph-orientation-horizontal
	Glyph_Orientation_Vertical   Hash = 0x161a  // glyph-orientation-vertical
	Height                       Hash = 0x6c06  // height
	Href                         Hash = 0x14204 // href
	Image                        Hash = 0x17a05 // image
	Image_Rendering              Hash = 0x17a0f // image-rendering
	Kerning                      Hash = 0x1bc07 // kerning
	Letter_Spacing               Hash = 0x90e   // letter-spacing
	Lighting_Color               Hash = 0x1ee0e // lighting-color
	Line                         Hash = 0x3c04  // line
	Marker                       Hash = 0x18906 // marker
	Marker_End                   Hash = 0x1890a // marker-end
	Marker_Mid                   Hash = 0x1a30a // marker-mid
	Marker_Start                 Hash = 0x1ad0c // marker-start
	Mask                         Hash = 0x1b904 // mask
	Metadata                     Hash = 0x1c308 // metadata
	Missing_Glyph                Hash = 0x1cb0d // missing-glyph
	Opacity                      Hash = 0x10b07 // opacity
	Overflow                     Hash = 0x26208 // overflow
	Paint_Order                  Hash = 0x2ae0b // paint-order
	Path                         Hash = 0x6904  // path
	Pattern                      Hash = 0x20407 // pattern
	Pointer_Events               Hash = 0x20b0e // pointer-events
	Points                       Hash = 0x22706 // points
	Polygon                      Hash = 0x24107 // polygon
	Polyline                     Hash = 0x24808 // polyline
	PreserveAspectRatio          Hash = 0x25013 // preserveAspectRatio
	Rect                         Hash = 0x30e04 // rect
	Rx                           Hash = 0x4f02  // rx
	Ry                           Hash = 0xc602  // ry
	Script                       Hash = 0xf206  // script
	Shape_Rendering              Hash = 0x2180f // shape-rendering
	Solid_Color                  Hash = 0x22c0b // solid-color
	Solid_Opacity                Hash = 0x36c0d // solid-opacity
	Stop_Color                   Hash = 0x12d0a // stop-color
	Stop_Opacity                 Hash = 0x2740c // stop-opacity
	Stroke                       Hash = 0x28006 // stroke
	Stroke_Dasharray             Hash = 0x28010 // stroke-dasharray
	Stroke_Dashoffset            Hash = 0x29011 // stroke-dashoffset
	Stroke_Linecap               Hash = 0x2a10e // stroke-linecap
	Stroke_Linejoin              Hash = 0x2b90f // stroke-linejoin
	Stroke_Miterlimit            Hash = 0x2c811 // stroke-miterlimit
	Stroke_Opacity               Hash = 0x2d90e // stroke-opacity
	Stroke_Width                 Hash = 0x2e70c // stroke-width
	Style                        Hash = 0x15105 // style
	Svg                          Hash = 0x2f303 // svg
	Switch                       Hash = 0x2f606 // switch
	Symbol                       Hash = 0x2fc06 // symbol
	Text_Anchor                  Hash = 0x450b  // text-anchor
	Text_Decoration              Hash = 0x710f  // text-decoration
	Text_Rendering               Hash = 0xf70e  // text-rendering
	Type                         Hash = 0x11004 // type
	Unicode_Bidi                 Hash = 0x3020c // unicode-bidi
	Use                          Hash = 0x31503 // use
	Vector_Effect                Hash = 0x3180d // vector-effect
	Version                      Hash = 0x32507 // version
	ViewBox                      Hash = 0x32c07 // viewBox
	Viewport_Fill                Hash = 0x3340d // viewport-fill
	Viewport_Fill_Opacity        Hash = 0x33415 // viewport-fill-opacity
	Visibility                   Hash = 0x3490a // visibility
	White_Space                  Hash = 0x2690b // white-space
	Width                        Hash = 0x2ee05 // width
	Word_Spacing                 Hash = 0x3530c // word-spacing
	Writing_Mode                 Hash = 0x35f0c // writing-mode
	X                            Hash = 0x4701  // x
	X1                           Hash = 0x5002  // x1
	X2                           Hash = 0x33202 // x2
	Xml_Space                    Hash = 0x37909 // xml:space
	Y                            Hash = 0x1801  // y
	Y1                           Hash = 0x9e02  // y1
	Y2                           Hash = 0xc702  // y2
)

Identifiers for the hashes associated with the text in the comments.

func ToHash added in v2.7.0

func ToHash(s []byte) Hash

ToHash returns a hash Hash for a given []byte. Hash is a uint32 that is associated with the text in []byte. It returns zero if no match found.

func (Hash) Bytes added in v2.7.3

func (i Hash) Bytes() []byte

Bytes returns the text associated with the hash.

func (Hash) String added in v2.7.0

func (i Hash) String() string

String returns the text associated with the hash.

type Minifier

type Minifier struct {
	KeepComments bool
	Precision    int // number of significant digits
	// contains filtered or unexported fields
}

Minifier is an SVG minifier.

func (*Minifier) Minify

func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]string) error

Minify minifies SVG data, it reads from r and writes to w.

type PathData

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

PathData represents a path data string.

func NewPathData

func NewPathData(o *Minifier) *PathData

NewPathData returns a new PathData.

func (*PathData) ShortenPathData

func (p *PathData) ShortenPathData(b []byte) []byte

ShortenPathData takes a full pathdata string and returns a shortened version. The original string is overwritten. It parses all commands (M, A, Z, ...) and coordinates (numbers) and calls copyInstruction for each command.

type PathDataState

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

PathDataState is the state of the current path.

type Token

type Token struct {
	xml.TokenType
	Hash    Hash
	Data    []byte
	Text    []byte
	AttrVal []byte
	Offset  int
}

Token is a single token unit with an attribute value (if given) and hash of the data.

type TokenBuffer

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

TokenBuffer is a buffer that allows for token look-ahead.

func NewTokenBuffer

func NewTokenBuffer(r *parse.Input, l *xml.Lexer) *TokenBuffer

NewTokenBuffer returns a new TokenBuffer.

func (*TokenBuffer) Attributes

func (z *TokenBuffer) Attributes(hashes ...Hash) []*Token

Attributes extracts the gives attribute hashes from a tag. It returns in the same order pointers to the requested token data or nil.

func (*TokenBuffer) Peek

func (z *TokenBuffer) Peek(pos int) *Token

Peek returns the ith element and possibly does an allocation. Peeking past an error will panic.

func (*TokenBuffer) Shift

func (z *TokenBuffer) Shift() *Token

Shift returns the first element and advances position.

Jump to

Keyboard shortcuts

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