draw2d/path/ftpath.go

74 lines
2.4 KiB
Go
Raw Normal View History

2011-04-27 08:06:14 +00:00
// Copyright 2010 The draw2d Authors. All rights reserved.
// created: 13/12/2010 by Laurent Le Goff
2012-04-17 09:03:56 +00:00
package path
2011-04-27 08:06:14 +00:00
import (
2012-01-13 09:14:12 +00:00
"code.google.com/p/freetype-go/freetype/raster"
"github.com/llgcode/draw2d/curve"
2011-04-27 08:06:14 +00:00
)
type FtLineBuilder struct {
adder raster.Adder
2011-04-27 08:06:14 +00:00
}
func NewFtLineBuilder(adder raster.Adder) *FtLineBuilder {
return &FtLineBuilder{adder}
2011-04-27 08:06:14 +00:00
}
func (FtLineBuilder *FtLineBuilder) MoveTo(x, y float64) {
FtLineBuilder.adder.Start(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)})
2011-04-27 08:06:14 +00:00
}
func (FtLineBuilder *FtLineBuilder) LineTo(x, y float64) {
FtLineBuilder.adder.Add1(raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)})
2011-04-27 08:06:14 +00:00
}
func (FtLineBuilder *FtLineBuilder) LineJoin() {
2015-04-23 15:43:26 +00:00
}
func (FtLineBuilder *FtLineBuilder) Close() {
}
func (FtLineBuilder *FtLineBuilder) End() {
2015-04-23 14:18:21 +00:00
}
2011-04-27 08:06:14 +00:00
type PathAdder struct {
adder raster.Adder
2011-05-18 21:23:31 +00:00
firstPoint raster.Point
2011-04-27 08:06:14 +00:00
ApproximationScale float64
}
func NewPathAdder(adder raster.Adder) *PathAdder {
return &PathAdder{adder, raster.Point{0, 0}, 1}
}
func (pathAdder *PathAdder) Convert(paths ...*Path) {
2015-04-27 10:16:18 +00:00
for _, apath := range paths {
2011-04-27 08:06:14 +00:00
j := 0
2015-04-27 10:16:18 +00:00
for _, cmd := range apath.Components {
2011-04-27 08:06:14 +00:00
switch cmd {
case MoveToCmp:
2015-04-27 10:16:18 +00:00
pathAdder.firstPoint = raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)}
2011-04-27 08:06:14 +00:00
pathAdder.adder.Start(pathAdder.firstPoint)
j += 2
case LineToCmp:
2015-04-27 10:16:18 +00:00
pathAdder.adder.Add1(raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)})
2011-04-27 08:06:14 +00:00
j += 2
case QuadCurveToCmp:
2015-04-27 10:16:18 +00:00
pathAdder.adder.Add2(raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)}, raster.Point{raster.Fix32(apath.Points[j+2] * 256), raster.Fix32(apath.Points[j+3] * 256)})
2011-04-27 08:06:14 +00:00
j += 4
case CubicCurveToCmp:
2015-04-27 10:16:18 +00:00
pathAdder.adder.Add3(raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)}, raster.Point{raster.Fix32(apath.Points[j+2] * 256), raster.Fix32(apath.Points[j+3] * 256)}, raster.Point{raster.Fix32(apath.Points[j+4] * 256), raster.Fix32(apath.Points[j+5] * 256)})
2011-04-27 08:06:14 +00:00
j += 6
case ArcToCmp:
lastPoint := curve.TraceArcFt(pathAdder.adder, apath.Points[j], apath.Points[j+1], apath.Points[j+2], apath.Points[j+3], apath.Points[j+4], apath.Points[j+5], pathAdder.ApproximationScale)
2011-04-27 08:06:14 +00:00
pathAdder.adder.Add1(lastPoint)
j += 6
case CloseCmp:
2011-04-27 08:06:14 +00:00
pathAdder.adder.Add1(pathAdder.firstPoint)
}
}
}
}