Documentation
¶
Overview ¶
Package paths provides tools for manipulating 2d paths consisting of line segments.
Index ¶
- func IDsFromSVG(r io.Reader, ids []string) (map[string]*Paths, error)
- type Bounds
- type Font
- type FontConfig
- type FontGlyph
- type FontGlyphConfig
- type Path
- type Paths
- func (ps *Paths) Clip(b Bounds)
- func (ps *Paths) DefaultConfig() *SVGConfig
- func (ps *Paths) Rotate(theta float64)
- func (ps *Paths) SVG(w io.Writer) error
- func (ps *Paths) SVGWithConfig(w io.Writer, cfg *SVGConfig) error
- func (ps *Paths) Simplify(tol float64)
- func (ps *Paths) Sort(cfg *SortConfig)
- func (ps *Paths) TightenBounds()
- func (ps *Paths) Transform(nb Bounds)
- func (ps *Paths) Translate(dx Vec2)
- type PositionedGlyph
- type SVGConfig
- type SortConfig
- type Vec2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Font ¶ added in v0.0.3
Font describes a typeface made up of paths.
type FontConfig ¶ added in v0.0.3
type FontConfig struct { Glyph map[rune]FontGlyphConfig // how to extract glyphs from SVG AdvanceRune rune // if set, multiply the advance by the width of this rune Advance float64 // how much advance to use (which is added to the width of the glyph). SpaceRune rune // if set, multiply the space advance by the width of this rune Space float64 // how much advance to use for a space LineRune rune // if set, multiply the line advance by the height of this rune Line float64 // how much to advance the y coord to start a new line }
FontConfig describes an SVG file that contains glyphs for a font.
type FontGlyph ¶ added in v0.0.3
FontGlyph describes paths of a single letter from a font.
func (*FontGlyph) TransformMatrixCopy ¶ added in v0.0.3
type FontGlyphConfig ¶ added in v0.0.3
type FontGlyphConfig struct { Dot Vec2 // where in the svg the letter is to be found. ID string // the ID of the group/path in the SVG file DeltaAdvance float64 // if set, how much to fiddle the advance for this glyph }
FontGlyphConfig describes how to find a particular glyph in an SVG file.
type Path ¶
type Path struct {
V []Vec2
}
A Path is a contiguous series of line segments, from the first point in the V slice to the last.
type Paths ¶
Paths is a set of paths, along with a view bounds.
func FromSVG ¶
FromSVG parses an SVG file, extracting paths. This provides only limited SVG parsing support, and will fail or produce incorrect results if the SVG file uses features that it doesn't understand.
func GlyphsToPaths ¶ added in v0.0.3
func GlyphsToPaths(offset Vec2, pgs []PositionedGlyph) *Paths
func (*Paths) Clip ¶
Clip removes all line segments outside the given bounds. If a path crosses the bounds, it's broken into multiple paths.
func (*Paths) DefaultConfig ¶ added in v0.0.5
func (*Paths) Rotate ¶ added in v0.0.3
Rotate rotates all paths by the given angle (in radians) about the center of the bounds. The bounds are updated to an axis-aligned bounding box that contains the original (rotated) bounds.
func (*Paths) SVGWithConfig ¶ added in v0.0.5
func (*Paths) Simplify ¶
Simplify removes points from paths, with the guarantee that all removed points are within the given tolerance (distance) from the new path.
func (*Paths) Sort ¶
func (ps *Paths) Sort(cfg *SortConfig)
Sort reorders paths to reduce the amount of movement between the end of one path and the start of the next. This is intended to improve rendering time using a physical xy plotter. The reordering can be configured in a limited way.
func (*Paths) TightenBounds ¶ added in v0.0.3
func (ps *Paths) TightenBounds()
TightenBounds adjusts the bounds to exactly contain the paths. If there are no paths, the bounds are set to zero.
type PositionedGlyph ¶ added in v0.0.3
func LayoutText ¶ added in v0.0.3
type SVGConfig ¶ added in v0.0.5
type SVGConfig struct {
// width and height attributes of the top-level SVG.
Width, Height string
// the four dimensions of the view box.
ViewBox [4]int
// The stroke-width attribute of paths generated.
StrokeWidth string
}
SVGConfig provides configuration for the svg generated.
type SortConfig ¶
type SortConfig struct { Split bool // ok to split continuous paths Reverse bool // ok to draw paths in the reverse direction }
SortConfig provides options for path sorting.