diff --git a/draw2d.go b/draw2d.go index 25b0d12..d71158a 100644 --- a/draw2d.go +++ b/draw2d.go @@ -150,6 +150,7 @@ type StrokeStyle struct { Dash []float64 } +// FillStyle is an empty interface you may want to use SolidFillStyle type FillStyle interface { } @@ -165,22 +166,29 @@ type SolidFillStyle struct { type Valign int const ( + // ValignTop top align text ValignTop Valign = iota - ValignTopCenter - ValignTopBottom - ValignTopBaseline + // ValignCenter centered text + ValignCenter + // ValignBottom bottom aligned text + ValignBottom + // ValignBaseline align text with the baseline of the font + ValignBaseline ) // Halign Horizontal Alignment of the text type Halign int const ( + // HalignLeft Horizontally align to left HalignLeft = iota + // HalignCenter Horizontally align to center HalignCenter + // HalignRight Horizontally align to right HalignRight ) -// TextStyle +// TextStyle describe text property type TextStyle struct { // Color defines the color of text Color color.Color @@ -194,6 +202,7 @@ type TextStyle struct { Valign Valign } +// ScalingPolicy is a constant to define how to scale an image type ScalingPolicy int const ( diff --git a/draw2dbase/curve_test.go b/draw2dbase/curve_test.go index 750521a..d04b9fb 100644 --- a/draw2dbase/curve_test.go +++ b/draw2dbase/curve_test.go @@ -15,8 +15,8 @@ import ( ) var ( - flattening_threshold float64 = 0.5 - testsCubicFloat64 = []float64{ + flatteningThreshold = 0.5 + testsCubicFloat64 = []float64{ 100, 100, 200, 100, 100, 200, 200, 200, 100, 100, 300, 200, 200, 200, 300, 100, 100, 100, 0, 300, 200, 0, 300, 300, @@ -75,7 +75,7 @@ func TestCubicCurve(t *testing.T) { for i := 0; i < len(testsCubicFloat64); i += 8 { var p SegmentedPath p.MoveTo(testsCubicFloat64[i], testsCubicFloat64[i+1]) - TraceCubic(&p, testsCubicFloat64[i:], flattening_threshold) + TraceCubic(&p, testsCubicFloat64[i:], flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, testsCubicFloat64[i:i+8]...) raster.PolylineBresenham(img, image.Black, p.Points...) @@ -91,7 +91,7 @@ func TestQuadCurve(t *testing.T) { for i := 0; i < len(testsQuadFloat64); i += 6 { var p SegmentedPath p.MoveTo(testsQuadFloat64[i], testsQuadFloat64[i+1]) - TraceQuad(&p, testsQuadFloat64[i:], flattening_threshold) + TraceQuad(&p, testsQuadFloat64[i:], flatteningThreshold) img := image.NewNRGBA(image.Rect(0, 0, 300, 300)) raster.PolylineBresenham(img, color.NRGBA{0xff, 0, 0, 0xff}, testsQuadFloat64[i:i+6]...) raster.PolylineBresenham(img, image.Black, p.Points...) @@ -108,7 +108,7 @@ func BenchmarkCubicCurve(b *testing.B) { for i := 0; i < len(testsCubicFloat64); i += 8 { var p SegmentedPath p.MoveTo(testsCubicFloat64[i], testsCubicFloat64[i+1]) - TraceCubic(&p, testsCubicFloat64[i:], flattening_threshold) + TraceCubic(&p, testsCubicFloat64[i:], flatteningThreshold) } } } diff --git a/draw2dbase/stack_gc.go b/draw2dbase/stack_gc.go index b2a56c7..ff8f4f8 100644 --- a/draw2dbase/stack_gc.go +++ b/draw2dbase/stack_gc.go @@ -12,7 +12,7 @@ import ( "code.google.com/p/freetype-go/freetype/truetype" ) -var DefaultFontData = draw2d.FontData{"luxi", draw2d.FontFamilySans, draw2d.FontStyleNormal} +var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal} type StackGraphicContext struct { Current *ContextStack diff --git a/draw2dgl/gc.go b/draw2dgl/gc.go index d47ff0e..b738a5e 100644 --- a/draw2dgl/gc.go +++ b/draw2dgl/gc.go @@ -223,9 +223,9 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) { gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule) gc.strokeRasterizer.UseNonZeroWinding = true - flattener := draw2dbase.Transformer{gc.Current.Tr, draw2dimg.FtLineBuilder{gc.fillRasterizer}} + flattener := draw2dbase.Transformer{Tr: gc.Current.Tr, Flattener: draw2dimg.FtLineBuilder{Adder: gc.fillRasterizer}} - stroker := draw2dbase.NewLineStroker(gc.Current.Cap, gc.Current.Join, draw2dbase.Transformer{gc.Current.Tr, draw2dimg.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 var liner draw2dbase.Flattener @@ -235,7 +235,7 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) { liner = stroker } - demux := draw2dbase.DemuxFlattener{[]draw2dbase.Flattener{flattener, liner}} + demux := draw2dbase.DemuxFlattener{Flatteners: []draw2dbase.Flattener{flattener, liner}} for _, p := range paths { draw2dbase.Flatten(p, demux, gc.Current.Tr.GetScale()) } diff --git a/samples/helloworld/helloworld.go b/samples/helloworld/helloworld.go index f9bf410..af5b47e 100644 --- a/samples/helloworld/helloworld.go +++ b/samples/helloworld/helloworld.go @@ -31,7 +31,7 @@ func Draw(gc draw2d.GraphicContext, text string) { gc.FillStroke() // Set the font luximbi.ttf - gc.SetFontData(draw2d.FontData{"luxi", draw2d.FontFamilyMono, draw2d.FontStyleBold | draw2d.FontStyleItalic}) + gc.SetFontData(draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilyMono, Style: draw2d.FontStyleBold | draw2d.FontStyleItalic}) // Set the fill text color to black gc.SetFillColor(image.Black) gc.SetFontSize(14)