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 ¶
- 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 ¶
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 = 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 = 0x35d04 // defs Direction Hash = 0x30009 // 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 = 0x3310c // 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 = 0x2a20b // 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 = 0x30204 // 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 = 0x3600d // solid-opacity Stop_Color Hash = 0x12d0a // stop-color Stop_Opacity Hash = 0x37a0c // stop-opacity Stroke Hash = 0x27406 // stroke Stroke_Dasharray Hash = 0x27410 // stroke-dasharray Stroke_Dashoffset Hash = 0x28411 // stroke-dashoffset Stroke_Linecap Hash = 0x2950e // stroke-linecap Stroke_Linejoin Hash = 0x2ad0f // stroke-linejoin Stroke_Miterlimit Hash = 0x2bc11 // stroke-miterlimit Stroke_Opacity Hash = 0x2cd0e // stroke-opacity Stroke_Width Hash = 0x2db0c // stroke-width Style Hash = 0x15105 // style Svg Hash = 0x2e703 // svg Switch Hash = 0x2ea06 // switch Symbol Hash = 0x2f006 // 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 = 0x2f60c // unicode-bidi Use Hash = 0x30903 // use Vector_Effect Hash = 0x30c0d // vector-effect Version Hash = 0x31907 // version ViewBox Hash = 0x32007 // viewBox Viewport_Fill Hash = 0x3280d // viewport-fill Viewport_Fill_Opacity Hash = 0x32815 // viewport-fill-opacity Visibility Hash = 0x33d0a // visibility White_Space Hash = 0x2690b // white-space Width Hash = 0x2e205 // width Word_Spacing Hash = 0x3470c // word-spacing Writing_Mode Hash = 0x3530c // writing-mode X Hash = 0x4701 // x X1 Hash = 0x5002 // x1 X2 Hash = 0x32602 // x2 Xml_Space Hash = 0x36d09 // xml:space Xmlns Hash = 0x37605 // xmlns 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 { KeepComments bool Precision int // number of significant digits Inline bool // 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
}
PathData represents a path data string.
func NewPathData ¶
NewPathData returns a new PathData.
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
}
PathDataState is the state of the current path.
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(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.
Source Files ¶
buffer.go hash.go pathdata.go svg.go table.go
- Version
- v2.21.3 (latest)
- Published
- Jan 14, 2025
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 4 days ago –
Tools for package owners.