MCPcopy Index your code
hub / github.com/tdewolff/canvas / String

Method String

path.go:2257–2288  ·  view source on GitHub ↗

String returns a string that represents the path similar to the SVG path data format (but not necessarily valid SVG).

()

Source from the content-addressed store, hash-verified

2255
2256// String returns a string that represents the path similar to the SVG path data format (but not necessarily valid SVG).
2257func (p *Path) String() string {
2258 sb := strings.Builder{}
2259 for i := 0; i < len(p.d); {
2260 cmd := p.d[i]
2261 switch cmd {
2262 case MoveToCmd:
2263 fmt.Fprintf(&sb, "M%g %g", p.d[i+1], p.d[i+2])
2264 case LineToCmd:
2265 fmt.Fprintf(&sb, "L%g %g", p.d[i+1], p.d[i+2])
2266 case QuadToCmd:
2267 fmt.Fprintf(&sb, "Q%g %g %g %g", p.d[i+1], p.d[i+2], p.d[i+3], p.d[i+4])
2268 case CubeToCmd:
2269 fmt.Fprintf(&sb, "C%g %g %g %g %g %g", p.d[i+1], p.d[i+2], p.d[i+3], p.d[i+4], p.d[i+5], p.d[i+6])
2270 case ArcToCmd:
2271 rot := p.d[i+3] * 180.0 / math.Pi
2272 large, sweep := toArcFlags(p.d[i+4])
2273 sLarge := "0"
2274 if large {
2275 sLarge = "1"
2276 }
2277 sSweep := "0"
2278 if sweep {
2279 sSweep = "1"
2280 }
2281 fmt.Fprintf(&sb, "A%g %g %g %s %s %g %g", p.d[i+1], p.d[i+2], rot, sLarge, sSweep, p.d[i+5], p.d[i+6])
2282 case CloseCmd:
2283 fmt.Fprintf(&sb, "z")
2284 }
2285 i += cmdLen(cmd)
2286 }
2287 return sb.String()
2288}
2289
2290// ToSVG returns a string that represents the path in the SVG path data format with minification.
2291func (p *Path) ToSVG() string {

Callers 3

ToSVGMethod · 0.45
ToPSMethod · 0.45
ToPDFMethod · 0.45

Calls 2

toArcFlagsFunction · 0.85
cmdLenFunction · 0.85

Tested by

no test coverage detected