From 1e0467b8fc7b7b5b157b00170b1100675cb0a946 Mon Sep 17 00:00:00 2001 From: Laurent Le Goff Date: Fri, 14 Aug 2015 22:22:01 +0200 Subject: [PATCH] move freetype dependency to draw2dimg --- draw2dbase/stroker.go | 26 ++----------------------- draw2dgl/gc.go | 9 +++++---- draw2dimg/ftgc.go | 30 +++++++++++++++++++++++++---- {draw2dbase => draw2dimg}/ftpath.go | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) rename {draw2dbase => draw2dimg}/ftpath.go (96%) diff --git a/draw2dbase/stroker.go b/draw2dbase/stroker.go index 4d9be86..640b228 100644 --- a/draw2dbase/stroker.go +++ b/draw2dbase/stroker.go @@ -4,33 +4,11 @@ package draw2dbase import ( - "code.google.com/p/freetype-go/freetype/raster" - "github.com/llgcode/draw2d" "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 { Flattener Flattener HalfLineWidth float64 diff --git a/draw2dgl/gc.go b/draw2dgl/gc.go index d9a055c..d47ff0e 100644 --- a/draw2dgl/gc.go +++ b/draw2dgl/gc.go @@ -10,6 +10,7 @@ import ( "github.com/go-gl/gl/v2.1/gl" "github.com/llgcode/draw2d" "github.com/llgcode/draw2d/draw2dbase" + "github.com/llgcode/draw2d/draw2dimg" ) func init() { @@ -188,7 +189,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) { paths = append(paths, gc.Current.Path) 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 var liner draw2dbase.Flattener @@ -209,7 +210,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.Path) { gc.fillRasterizer.UseNonZeroWinding = useNonZeroWinding(gc.Current.FillRule) /**** 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 { 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.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 var liner draw2dbase.Flattener diff --git a/draw2dimg/ftgc.go b/draw2dimg/ftgc.go index 415e3d4..2e8c52d 100644 --- a/draw2dimg/ftgc.go +++ b/draw2dimg/ftgc.go @@ -244,7 +244,7 @@ func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) { paths = append(paths, gc.Current.Path) 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 var liner draw2dbase.Flattener @@ -266,7 +266,7 @@ func (gc *GraphicContext) Fill(paths ...*draw2d.Path) { gc.fillRasterizer.UseNonZeroWinding = gc.Current.FillRule == draw2d.FillRuleWinding /**** 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 { 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.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 var liner draw2dbase.Flattener @@ -302,3 +302,25 @@ func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) { // Stroke 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 +} diff --git a/draw2dbase/ftpath.go b/draw2dimg/ftpath.go similarity index 96% rename from draw2dbase/ftpath.go rename to draw2dimg/ftpath.go index 50aab78..ce6c422 100644 --- a/draw2dbase/ftpath.go +++ b/draw2dimg/ftpath.go @@ -1,7 +1,7 @@ // Copyright 2010 The draw2d Authors. All rights reserved. // created: 13/12/2010 by Laurent Le Goff -package draw2dbase +package draw2dimg import ( "code.google.com/p/freetype-go/freetype/raster"