Start path package
This commit is contained in:
parent
d6812fd8e6
commit
61a6e03fdb
4 changed files with 26 additions and 22 deletions
9
gc.go
9
gc.go
|
@ -4,6 +4,7 @@
|
|||
package draw2d
|
||||
|
||||
import (
|
||||
"github.com/llgcode/draw2d/path"
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
@ -16,7 +17,7 @@ const (
|
|||
)
|
||||
|
||||
type GraphicContext interface {
|
||||
PathBuilder
|
||||
path.PathBuilder
|
||||
// Create a new path
|
||||
BeginPath()
|
||||
GetMatrixTransform() MatrixTransform
|
||||
|
@ -49,7 +50,7 @@ type GraphicContext interface {
|
|||
FillStringAt(text string, x, y float64) (cursor float64)
|
||||
StrokeString(text string) (cursor float64)
|
||||
StrokeStringAt(text string, x, y float64) (cursor float64)
|
||||
Stroke(paths ...*Path)
|
||||
Fill(paths ...*Path)
|
||||
FillStroke(paths ...*Path)
|
||||
Stroke(paths ...*path.Path)
|
||||
Fill(paths ...*path.Path)
|
||||
FillStroke(paths ...*path.Path)
|
||||
}
|
||||
|
|
7
image.go
7
image.go
|
@ -5,6 +5,7 @@ package draw2d
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/llgcode/draw2d/path"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
@ -275,7 +276,7 @@ func (gc *ImageGraphicContext) paint(rasterizer *raster.Rasterizer, color color.
|
|||
}
|
||||
|
||||
/**** second method ****/
|
||||
func (gc *ImageGraphicContext) Stroke(paths ...*Path) {
|
||||
func (gc *ImageGraphicContext) Stroke(paths ...*path.Path) {
|
||||
paths = append(paths, gc.Current.Path)
|
||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||
|
||||
|
@ -295,7 +296,7 @@ func (gc *ImageGraphicContext) Stroke(paths ...*Path) {
|
|||
}
|
||||
|
||||
/**** second method ****/
|
||||
func (gc *ImageGraphicContext) Fill(paths ...*Path) {
|
||||
func (gc *ImageGraphicContext) Fill(paths ...*path.Path) {
|
||||
paths = append(paths, gc.Current.Path)
|
||||
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding()
|
||||
|
||||
|
@ -308,7 +309,7 @@ func (gc *ImageGraphicContext) Fill(paths ...*Path) {
|
|||
}
|
||||
|
||||
/* second method */
|
||||
func (gc *ImageGraphicContext) FillStroke(paths ...*Path) {
|
||||
func (gc *ImageGraphicContext) FillStroke(paths ...*path.Path) {
|
||||
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding()
|
||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ package draw2d
|
|||
|
||||
import (
|
||||
"code.google.com/p/freetype-go/freetype/raster"
|
||||
"github.com/llgcode/draw2d/path"
|
||||
)
|
||||
|
||||
type VertexAdder struct {
|
||||
|
@ -42,29 +43,29 @@ func NewPathAdder(adder raster.Adder) *PathAdder {
|
|||
return &PathAdder{adder, raster.Point{0, 0}, 1}
|
||||
}
|
||||
|
||||
func (pathAdder *PathAdder) Convert(paths ...*Path) {
|
||||
for _, path := range paths {
|
||||
func (pathAdder *PathAdder) Convert(paths ...*path.Path) {
|
||||
for _, apath := range paths {
|
||||
j := 0
|
||||
for _, cmd := range path.commands {
|
||||
for _, cmd := range apath.Components {
|
||||
switch cmd {
|
||||
case MoveTo:
|
||||
pathAdder.firstPoint = raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)}
|
||||
case path.MoveToCmp:
|
||||
pathAdder.firstPoint = raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)}
|
||||
pathAdder.adder.Start(pathAdder.firstPoint)
|
||||
j += 2
|
||||
case LineTo:
|
||||
pathAdder.adder.Add1(raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)})
|
||||
case path.LineToCmp:
|
||||
pathAdder.adder.Add1(raster.Point{raster.Fix32(apath.Points[j] * 256), raster.Fix32(apath.Points[j+1] * 256)})
|
||||
j += 2
|
||||
case QuadCurveTo:
|
||||
pathAdder.adder.Add2(raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.vertices[j+2] * 256), raster.Fix32(path.vertices[j+3] * 256)})
|
||||
case path.QuadCurveToCmp:
|
||||
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)})
|
||||
j += 4
|
||||
case CubicCurveTo:
|
||||
pathAdder.adder.Add3(raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)}, raster.Point{raster.Fix32(path.vertices[j+2] * 256), raster.Fix32(path.vertices[j+3] * 256)}, raster.Point{raster.Fix32(path.vertices[j+4] * 256), raster.Fix32(path.vertices[j+5] * 256)})
|
||||
case path.CubicCurveToCmp:
|
||||
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)})
|
||||
j += 6
|
||||
case ArcTo:
|
||||
lastPoint := arcAdder(pathAdder.adder, path.vertices[j], path.vertices[j+1], path.vertices[j+2], path.vertices[j+3], path.vertices[j+4], path.vertices[j+5], pathAdder.ApproximationScale)
|
||||
case path.ArcToCmp:
|
||||
lastPoint := arcAdder(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)
|
||||
pathAdder.adder.Add1(lastPoint)
|
||||
j += 6
|
||||
case Close:
|
||||
case path.CloseCmp:
|
||||
pathAdder.adder.Add1(pathAdder.firstPoint)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
package draw2d
|
||||
|
||||
import (
|
||||
"github.com/llgcode/draw2d/path"
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
|
@ -16,7 +17,7 @@ type StackGraphicContext struct {
|
|||
|
||||
type ContextStack struct {
|
||||
Tr MatrixTransform
|
||||
Path *Path
|
||||
Path *path.Path
|
||||
LineWidth float64
|
||||
Dash []float64
|
||||
DashOffset float64
|
||||
|
|
Loading…
Reference in a new issue