2015-06-26 23:13:20 +00:00
|
|
|
// Copyright 2015 The draw2d Authors. All rights reserved.
|
|
|
|
// created: 26/06/2015 by Stani Michiels
|
|
|
|
|
2015-07-06 22:25:24 +00:00
|
|
|
package draw2dpdf
|
2015-06-26 23:13:20 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
|
2015-07-06 22:07:44 +00:00
|
|
|
"github.com/llgcode/draw2d"
|
2015-06-26 23:13:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const deg = 180 / math.Pi
|
|
|
|
|
2015-07-09 16:06:14 +00:00
|
|
|
// ConvertPath converts a paths to the pdf api
|
|
|
|
func ConvertPath(path *draw2d.Path, pdf Vectorizer) {
|
|
|
|
var startX, startY float64 = 0, 0
|
|
|
|
i := 0
|
|
|
|
for _, cmp := range path.Components {
|
|
|
|
switch cmp {
|
|
|
|
case draw2d.MoveToCmp:
|
|
|
|
startX, startY = path.Points[i], path.Points[i+1]
|
|
|
|
pdf.MoveTo(startX, startY)
|
|
|
|
i += 2
|
|
|
|
case draw2d.LineToCmp:
|
|
|
|
pdf.LineTo(path.Points[i], path.Points[i+1])
|
|
|
|
i += 2
|
|
|
|
case draw2d.QuadCurveToCmp:
|
|
|
|
pdf.CurveTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3])
|
|
|
|
i += 4
|
|
|
|
case draw2d.CubicCurveToCmp:
|
|
|
|
pdf.CurveBezierCubicTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3], path.Points[i+4], path.Points[i+5])
|
|
|
|
i += 6
|
|
|
|
case draw2d.ArcToCmp:
|
|
|
|
pdf.ArcTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3],
|
|
|
|
0, // degRotate
|
|
|
|
path.Points[i+4]*deg, // degStart = startAngle
|
|
|
|
(path.Points[i+4]-path.Points[i+5])*deg) // degEnd = startAngle-angle
|
|
|
|
i += 6
|
|
|
|
case draw2d.CloseCmp:
|
|
|
|
pdf.LineTo(startX, startY)
|
|
|
|
pdf.ClosePath()
|
2015-06-26 23:13:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|