minor fix

This commit is contained in:
Laurent Le Goff 2011-04-26 13:26:55 +02:00
parent 71188c8fa8
commit 8e1db8dc62
5 changed files with 72 additions and 47 deletions

View file

@ -55,13 +55,13 @@ func arcAdder(adder raster.Adder, x, y, rx, ry, start, angle, scale float64) ras
if (angle < end-da/4) != clockWise {
curX = x + math.Cos(end)*rx
curY = y + math.Sin(end)*ry
return floatToPoint(curX, curY)
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
}
curX = x + math.Cos(angle)*rx
curY = y + math.Sin(angle)*ry
angle += da
adder.Add1(floatToPoint(curX, curY))
adder.Add1(raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)})
}
return floatToPoint(curX, curY)
return raster.Point{raster.Fix32(curX * 256), raster.Fix32(curY * 256)}
}

View file

@ -139,7 +139,7 @@ func (gc *ImageGraphicContext) Stroke2(paths ...*PathStorage) {
pathConverter.Convert(paths...)
mta := NewMatrixTransformAdder(gc.Current.Tr, gc.strokeRasterizer)
raster.Stroke(mta, *rasterPath, raster.Fix32(gc.Current.LineWidth*256), gc.Current.Cap.capper(), gc.Current.Join.joiner())
raster.Stroke(mta, *rasterPath, raster.Fix32(gc.Current.LineWidth*256), gc.Current.Cap.Convert(), gc.Current.Join.Convert())
gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor)
}
@ -204,7 +204,7 @@ func (gc *ImageGraphicContext) FillStroke2(paths ...*PathStorage) {
pathConverter.Convert(paths...)
mta := NewMatrixTransformAdder(gc.Current.Tr, gc.strokeRasterizer)
raster.Stroke(mta, *rasterPath, raster.Fix32(gc.Current.LineWidth*256), gc.Current.Cap.capper(), gc.Current.Join.joiner())
raster.Stroke(mta, *rasterPath, raster.Fix32(gc.Current.LineWidth*256), gc.Current.Cap.Convert(), gc.Current.Join.Convert())
gc.paint(gc.fillRasterizer, gc.Current.FillColor)
gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor)
@ -241,7 +241,7 @@ func (f FillRule) UseNonZeroWinding() bool {
return false
}
func (c Cap) capper() raster.Capper {
func (c Cap) Convert() raster.Capper {
switch c {
case RoundCap:
return raster.RoundCapper
@ -253,7 +253,7 @@ func (c Cap) capper() raster.Capper {
return raster.RoundCapper
}
func (j Join) joiner() raster.Joiner {
func (j Join) Convert() raster.Joiner {
switch j {
case RoundJoin:
return raster.RoundJoiner

View file

@ -13,12 +13,6 @@ type VertexAdder struct {
adder raster.Adder
}
func floatToPoint(x, y float64) raster.Point {
return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)}
}
func NewVertexAdder(adder raster.Adder) *VertexAdder {
return &VertexAdder{VertexNoCommand, adder}
}
@ -40,7 +34,7 @@ func (vertexAdder *VertexAdder) Vertex(x, y float64) {
type PathAdder struct {
adder raster.Adder
lastPoint raster.Point
firstPoint raster.Point
ApproximationScale float64
}
@ -53,37 +47,29 @@ func (pathAdder *PathAdder) Convert(paths ...*PathStorage) {
for _, path := range paths {
j := 0
for _, cmd := range path.commands {
j = j + pathAdder.ConvertCommand(cmd, path.vertices[j:]...)
}
}
}
func (pathAdder *PathAdder) ConvertCommand(cmd PathCmd, vertices ...float64) int {
switch cmd {
case MoveTo:
pathAdder.lastPoint = floatToPoint(vertices[0], vertices[1])
pathAdder.adder.Start(pathAdder.lastPoint)
return 2
pathAdder.firstPoint = raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)}
pathAdder.adder.Start(pathAdder.firstPoint)
j += 2
case LineTo:
pathAdder.lastPoint = floatToPoint(vertices[0], vertices[1])
pathAdder.adder.Add1(pathAdder.lastPoint)
return 2
pathAdder.adder.Add1(raster.Point{raster.Fix32(path.vertices[j] * 256), raster.Fix32(path.vertices[j+1] * 256)})
j += 2
case QuadCurveTo:
pathAdder.lastPoint = floatToPoint(vertices[2], vertices[3])
pathAdder.adder.Add2(floatToPoint(vertices[0], vertices[1]), pathAdder.lastPoint)
return 4
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)})
j += 4
case CubicCurveTo:
pathAdder.lastPoint = floatToPoint(vertices[4], vertices[5])
pathAdder.adder.Add3(floatToPoint(vertices[0], vertices[1]), floatToPoint(vertices[2], vertices[3]), pathAdder.lastPoint)
return 6
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)})
j += 6
case ArcTo:
pathAdder.lastPoint = arcAdder(pathAdder.adder, vertices[0], vertices[1], vertices[2], vertices[3], vertices[4], vertices[5], pathAdder.ApproximationScale)
pathAdder.adder.Add1(pathAdder.lastPoint)
return 6
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)
pathAdder.adder.Add1(lastPoint)
j += 6
case Close:
pathAdder.adder.Add1(pathAdder.lastPoint)
return 0
pathAdder.adder.Add1(pathAdder.firstPoint)
}
return 0
}
}
}

View file

@ -26,6 +26,15 @@ func (tr MatrixTransform) Transform(points ...*float64) {
}
}
func (tr MatrixTransform) TransformArray(points []float64) {
for i, j := 0, 1; j < len(points); i, j = i+2, j+2 {
x := points[i]
y := points[j]
points[i] = x*tr[0] + y*tr[2] + tr[4]
points[j] = x*tr[1] + y*tr[3] + tr[5]
}
}
func (tr MatrixTransform) TransformRectangle(x0, y0, x2, y2 *float64) {
x1 := *x2
y1 := *y0

View file

@ -110,6 +110,7 @@ func NewGLPainter() *GLPainter {
return p
}
type GraphicContext struct {
*draw2d.StackGraphicContext
painter *GLPainter
@ -117,6 +118,23 @@ type GraphicContext struct {
strokeRasterizer *raster.Rasterizer
}
type GLVertex struct {
x, y float64
}
func NewGLVertex() *GLVertex {
return &GLVertex{}
}
func (glVertex *GLVertex) NextCommand(cmd draw2d.VertexCommand) {
}
func (glVertex *GLVertex) Vertex(x, y float64) {
gl.Vertex2d(x, y)
}
/**
* Create a new Graphic context from an image
*/
@ -150,7 +168,6 @@ func (gc *GraphicContext) DrawImage(img image.Image) {
}
func (gc *GraphicContext) FillString(text string) (cursor float64) {
return 0
}
@ -194,6 +211,19 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) {
gc.paint(gc.fillRasterizer, gc.Current.FillColor)
gc.Current.Path.Clear()
}
/*
func (gc *GraphicContext) Fill(paths ...*draw2d.PathStorage) {
paths = append(paths, gc.Current.Path)
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding()
pathConverter := draw2d.NewPathAdder(draw2d.NewMatrixTransformAdder(gc.Current.Tr, gc.fillRasterizer))
pathConverter.ApproximationScale = gc.Current.Tr.GetScale()
pathConverter.Convert(paths...)
gc.paint(gc.fillRasterizer, gc.Current.FillColor)
gc.Current.Path.Clear()
}
*/
func (gc *GraphicContext) FillStroke(paths ...*draw2d.PathStorage) {
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule.UseNonZeroWinding()