package svg
import "github.com/tdewolff/minify/v2/svg"
Package svg minifies SVG1.1 following the specifications at http://www.w3.org/TR/SVG11/.
Index ¶
- Variables
- func Minify(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error
- type Hash
- type Minifier
- type PathData
- type PathDataState
- type Token
- type TokenBuffer
Examples ¶
Variables ¶
var DefaultMinifier = &Minifier{}
DEPRECATED: DefaultMinifier is the default minifier.
Functions ¶
func Minify ¶
Minify minifies SVG data, it reads from r and writes to w.
Code:
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)
}
}
Types ¶
type Hash ¶
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 = 0x1ea0d // color-profile Color_Rendering Hash = 0x2250f // color-rendering ContentScriptType Hash = 0xa011 // contentScriptType ContentStyleType Hash = 0xb110 // contentStyleType Cursor Hash = 0xc106 // cursor D Hash = 0x5901 // d Defs Hash = 0x35c04 // defs Direction Hash = 0x2ff09 // direction Display Hash = 0x9807 // display Dominant_Baseline Hash = 0x18511 // dominant-baseline Enable_Background Hash = 0x8811 // enable-background FeImage Hash = 0x14507 // feImage Fill Hash = 0xc904 // fill Fill_Opacity Hash = 0x3300c // 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 G Hash = 0x1601 // g Glyph_Orientation_Horizontal Hash = 0x1c61c // glyph-orientation-horizontal Glyph_Orientation_Vertical Hash = 0x161a // glyph-orientation-vertical Height Hash = 0x6c06 // height Href Hash = 0x14204 // href Image Hash = 0x16d05 // image Image_Rendering Hash = 0x16d0f // image-rendering Kerning Hash = 0x1af07 // kerning Letter_Spacing Hash = 0x90e // letter-spacing Lighting_Color Hash = 0x1e10e // lighting-color Line Hash = 0x3c04 // line Marker Hash = 0x17c06 // marker Marker_End Hash = 0x17c0a // marker-end Marker_Mid Hash = 0x1960a // marker-mid Marker_Start Hash = 0x1a00c // marker-start Mask Hash = 0x1ac04 // mask Metadata Hash = 0x1b608 // metadata Missing_Glyph Hash = 0x1be0d // missing-glyph Opacity Hash = 0x10b07 // opacity Overflow Hash = 0x25508 // overflow Paint_Order Hash = 0x2a10b // paint-order Path Hash = 0x6904 // path Pattern Hash = 0x1f707 // pattern Pointer_Events Hash = 0x1fe0e // pointer-events Points Hash = 0x21a06 // points Polygon Hash = 0x23407 // polygon Polyline Hash = 0x23b08 // polyline PreserveAspectRatio Hash = 0x24313 // preserveAspectRatio Rect Hash = 0x30104 // rect Rx Hash = 0x4f02 // rx Ry Hash = 0xc602 // ry Script Hash = 0xf206 // script Shape_Rendering Hash = 0x20b0f // shape-rendering Solid_Color Hash = 0x21f0b // solid-color Solid_Opacity Hash = 0x35f0d // solid-opacity Stop_Color Hash = 0x12d0a // stop-color Stop_Opacity Hash = 0x2670c // stop-opacity Stroke Hash = 0x27306 // stroke Stroke_Dasharray Hash = 0x27310 // stroke-dasharray Stroke_Dashoffset Hash = 0x28311 // stroke-dashoffset Stroke_Linecap Hash = 0x2940e // stroke-linecap Stroke_Linejoin Hash = 0x2ac0f // stroke-linejoin Stroke_Miterlimit Hash = 0x2bb11 // stroke-miterlimit Stroke_Opacity Hash = 0x2cc0e // stroke-opacity Stroke_Width Hash = 0x2da0c // stroke-width Style Hash = 0x15105 // style Svg Hash = 0x2e603 // svg Switch Hash = 0x2e906 // switch Symbol Hash = 0x2ef06 // 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 = 0x2f50c // unicode-bidi Use Hash = 0x30803 // use Vector_Effect Hash = 0x30b0d // vector-effect Version Hash = 0x31807 // version ViewBox Hash = 0x31f07 // viewBox Viewport_Fill Hash = 0x3270d // viewport-fill Viewport_Fill_Opacity Hash = 0x32715 // viewport-fill-opacity Visibility Hash = 0x33c0a // visibility White_Space Hash = 0x25c0b // white-space Width Hash = 0x2e105 // width Word_Spacing Hash = 0x3460c // word-spacing Writing_Mode Hash = 0x3520c // writing-mode X Hash = 0x4701 // x X1 Hash = 0x5002 // x1 X2 Hash = 0x32502 // x2 Xml_Space Hash = 0x36c09 // xml:space Y Hash = 0x1801 // y Y1 Hash = 0x9e02 // y1 Y2 Hash = 0xc702 // y2 )
Unique hash definitions to be used instead of strings
func ToHash ¶
ToHash returns the hash whose name is s. It returns zero if there is no such hash. It is case sensitive.
func (Hash) String ¶
String returns the hash' name.
type Minifier ¶
type Minifier struct { Decimals int // DEPRECATED Precision int // number of significant digits // contains filtered or unexported fields }
Minifier is an SVG minifier.
func (*Minifier) Minify ¶
Minify minifies SVG data, it reads from r and writes to w.
type PathData ¶
type PathData struct {
// contains filtered or unexported fields
}
func NewPathData ¶
func (*PathData) ShortenPathData ¶
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
}
type Token ¶
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(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.
Source Files ¶
buffer.go hash.go pathdata.go svg.go table.go
- Version
- v2.7.2
- Published
- Jan 14, 2020
- Platform
- darwin/amd64
- Imports
- 10 packages
- Last checked
- 2 hours ago –
Tools for package owners.