MCPcopy Create free account
hub / github.com/cogentcore/core / ToSVGPath

Method ToSVGPath

paint/raster/geom.go:61–90  ·  view source on GitHub ↗

ToSVGPath returns a string representation of the path

()

Source from the content-addressed store, hash-verified

59
60// ToSVGPath returns a string representation of the path
61func (p Path) ToSVGPath() string {
62 s := ""
63 for i := 0; i < len(p); {
64 if i != 0 {
65 s += " "
66 }
67 switch PathCommand(p[i]) {
68 case PathMoveTo:
69 s += fmt.Sprintf("M%4.3f,%4.3f", float32(p[i+1])/64, float32(p[i+2])/64)
70 i += 3
71 case PathLineTo:
72 s += fmt.Sprintf("L%4.3f,%4.3f", float32(p[i+1])/64, float32(p[i+2])/64)
73 i += 3
74 case PathQuadTo:
75 s += fmt.Sprintf("Q%4.3f,%4.3f,%4.3f,%4.3f", float32(p[i+1])/64, float32(p[i+2])/64,
76 float32(p[i+3])/64, float32(p[i+4])/64)
77 i += 5
78 case PathCubicTo:
79 s += "C" + fmt.Sprintf("C%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f", float32(p[i+1])/64, float32(p[i+2])/64,
80 float32(p[i+3])/64, float32(p[i+4])/64, float32(p[i+5])/64, float32(p[i+6])/64)
81 i += 7
82 case PathClose:
83 s += "Z"
84 i++
85 default:
86 panic("freetype/rasterx: bad pather")
87 }
88 }
89 return s
90}
91
92// String returns a readable representation of a Path.
93func (p Path) String() string {

Callers 3

StringMethod · 0.95
SVGPathMethod · 0.80
GetTestPathFunction · 0.80

Calls 1

PathCommandTypeAlias · 0.85

Tested by 1

GetTestPathFunction · 0.64