move freetype dependency to draw2dimg
This commit is contained in:
parent
3b19ab855e
commit
1e0467b8fc
4 changed files with 34 additions and 33 deletions
|
@ -4,33 +4,11 @@
|
||||||
package draw2dbase
|
package draw2dbase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/freetype-go/freetype/raster"
|
|
||||||
"github.com/llgcode/draw2d"
|
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"github.com/llgcode/draw2d"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toFtCap(c draw2d.LineCap) raster.Capper {
|
|
||||||
switch c {
|
|
||||||
case draw2d.RoundCap:
|
|
||||||
return raster.RoundCapper
|
|
||||||
case draw2d.ButtCap:
|
|
||||||
return raster.ButtCapper
|
|
||||||
case draw2d.SquareCap:
|
|
||||||
return raster.SquareCapper
|
|
||||||
}
|
|
||||||
return raster.RoundCapper
|
|
||||||
}
|
|
||||||
|
|
||||||
func toFtJoin(j draw2d.LineJoin) raster.Joiner {
|
|
||||||
switch j {
|
|
||||||
case draw2d.RoundJoin:
|
|
||||||
return raster.RoundJoiner
|
|
||||||
case draw2d.BevelJoin:
|
|
||||||
return raster.BevelJoiner
|
|
||||||
}
|
|
||||||
return raster.RoundJoiner
|
|
||||||
}
|
|
||||||
|
|
||||||
type LineStroker struct {
|
type LineStroker struct {
|
||||||
Flattener Flattener
|
Flattener Flattener
|
||||||
HalfLineWidth float64
|
HalfLineWidth float64
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/go-gl/gl/v2.1/gl"
|
"github.com/go-gl/gl/v2.1/gl"
|
||||||
"github.com/llgcode/draw2d"
|
"github.com/llgcode/draw2d"
|
||||||
"github.com/llgcode/draw2d/draw2dbase"
|
"github.com/llgcode/draw2d/draw2dbase"
|
||||||
|
"github.com/llgcode/draw2d/draw2dimg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -188,7 +189,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) {
|
||||||
paths = append(paths, gc.Current.Path)
|
paths = append(paths, gc.Current.Path)
|
||||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||||
|
|
||||||
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{gc.Current.Tr, draw2dbase.FtLineBuilder{gc.strokeRasterizer}})
|
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dimg.FtLineBuilder{Adder: gc.strokeRasterizer}})
|
||||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||||
|
|
||||||
var liner draw2dbase.Flattener
|
var liner draw2dbase.Flattener
|
||||||
|
@ -209,7 +210,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.Path) {
|
||||||
gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule)
|
gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule)
|
||||||
|
|
||||||
/**** first method ****/
|
/**** first method ****/
|
||||||
flattener := draw2dbase.Transformer{gc.Current.Tr, draw2dbase.FtLineBuilder{gc.fillRasterizer}}
|
flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dimg.FtLineBuilder{Adder: gc.fillRasterizer}}
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
draw2dbase.Flatten(p, flattener, gc.Current.Tr.GetScale())
|
draw2dbase.Flatten(p, flattener, gc.Current.Tr.GetScale())
|
||||||
}
|
}
|
||||||
|
@ -222,9 +223,9 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) {
|
||||||
gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule)
|
gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule)
|
||||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||||
|
|
||||||
flattener := draw2dbase.Transformer{gc.Current.Tr, draw2dbase.FtLineBuilder{gc.fillRasterizer}}
|
flattener := draw2dbase.Transformer{gc.Current.Tr, draw2dimg.FtLineBuilder{gc.fillRasterizer}}
|
||||||
|
|
||||||
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{gc.Current.Tr, draw2dbase.FtLineBuilder{gc.strokeRasterizer}})
|
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{gc.Current.Tr, draw2dimg.FtLineBuilder{gc.strokeRasterizer}})
|
||||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||||
|
|
||||||
var liner draw2dbase.Flattener
|
var liner draw2dbase.Flattener
|
||||||
|
|
|
@ -244,7 +244,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) {
|
||||||
paths = append(paths, gc.Current.Path)
|
paths = append(paths, gc.Current.Path)
|
||||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||||
|
|
||||||
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dbase.FtLineBuilder{Adder: gc.strokeRasterizer}})
|
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: FtLineBuilder{Adder: gc.strokeRasterizer}})
|
||||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||||
|
|
||||||
var liner draw2dbase.Flattener
|
var liner draw2dbase.Flattener
|
||||||
|
@ -266,7 +266,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.Path) {
|
||||||
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule == draw2d.FillRuleWinding
|
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule == draw2d.FillRuleWinding
|
||||||
|
|
||||||
/**** first method ****/
|
/**** first method ****/
|
||||||
flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dbase.FtLineBuilder{Adder: gc.fillRasterizer}}
|
flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: FtLineBuilder{Adder: gc.fillRasterizer}}
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
draw2dbase.Flatten(p, flattener, gc.Current.Tr.GetScale())
|
draw2dbase.Flatten(p, flattener, gc.Current.Tr.GetScale())
|
||||||
}
|
}
|
||||||
|
@ -280,9 +280,9 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) {
|
||||||
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule == draw2d.FillRuleWinding
|
gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule == draw2d.FillRuleWinding
|
||||||
gc.strokeRasterizer.UseNonZeroWinding = true
|
gc.strokeRasterizer.UseNonZeroWinding = true
|
||||||
|
|
||||||
flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dbase.FtLineBuilder{Adder: gc.fillRasterizer}}
|
flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: FtLineBuilder{Adder: gc.fillRasterizer}}
|
||||||
|
|
||||||
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dbase.FtLineBuilder{Adder: gc.strokeRasterizer}})
|
stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: FtLineBuilder{Adder: gc.strokeRasterizer}})
|
||||||
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
stroker.HalfLineWidth = gc.Current.LineWidth / 2
|
||||||
|
|
||||||
var liner draw2dbase.Flattener
|
var liner draw2dbase.Flattener
|
||||||
|
@ -302,3 +302,25 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) {
|
||||||
// Stroke
|
// Stroke
|
||||||
gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor)
|
gc.paint(gc.strokeRasterizer, gc.Current.StrokeColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toFtCap(c draw2d.LineCap) raster.Capper {
|
||||||
|
switch c {
|
||||||
|
case draw2d.RoundCap:
|
||||||
|
return raster.RoundCapper
|
||||||
|
case draw2d.ButtCap:
|
||||||
|
return raster.ButtCapper
|
||||||
|
case draw2d.SquareCap:
|
||||||
|
return raster.SquareCapper
|
||||||
|
}
|
||||||
|
return raster.RoundCapper
|
||||||
|
}
|
||||||
|
|
||||||
|
func toFtJoin(j draw2d.LineJoin) raster.Joiner {
|
||||||
|
switch j {
|
||||||
|
case draw2d.RoundJoin:
|
||||||
|
return raster.RoundJoiner
|
||||||
|
case draw2d.BevelJoin:
|
||||||
|
return raster.BevelJoiner
|
||||||
|
}
|
||||||
|
return raster.RoundJoiner
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||||
// created: 13/12/2010 by Laurent Le Goff
|
// created: 13/12/2010 by Laurent Le Goff
|
||||||
|
|
||||||
package draw2dbase
|
package draw2dimg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/freetype-go/freetype/raster"
|
"code.google.com/p/freetype-go/freetype/raster"
|
Loading…
Reference in a new issue