From 500caaeda74dd9c660279036293f4b2997cf0b03 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 9 Sep 2017 09:42:37 +0200 Subject: Add vendor --- .../github.com/llgcode/draw2d/draw2dpdf/README.md | 42 +++ vendor/github.com/llgcode/draw2d/draw2dpdf/doc.go | 41 +++ .../llgcode/draw2d/draw2dpdf/fileutil.go | 11 + vendor/github.com/llgcode/draw2d/draw2dpdf/gc.go | 379 +++++++++++++++++++++ .../llgcode/draw2d/draw2dpdf/path_converter.go | 44 +++ .../llgcode/draw2d/draw2dpdf/samples_test.go | 65 ++++ .../llgcode/draw2d/draw2dpdf/test_test.go | 39 +++ .../llgcode/draw2d/draw2dpdf/vectorizer.go | 22 ++ 8 files changed, 643 insertions(+) create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/README.md create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/doc.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/fileutil.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/gc.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/path_converter.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/samples_test.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/test_test.go create mode 100644 vendor/github.com/llgcode/draw2d/draw2dpdf/vectorizer.go (limited to 'vendor/github.com/llgcode/draw2d/draw2dpdf') diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/README.md b/vendor/github.com/llgcode/draw2d/draw2dpdf/README.md new file mode 100644 index 0000000..3208c33 --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/README.md @@ -0,0 +1,42 @@ +draw2d pdf +========== + +Package draw2dpdf provides a graphic context that can draw vector graphics and text on pdf file with the [gofpdf](https://github.com/jung-kurt/gofpdf) package. + +Quick Start +----------- + +The following Go code generates a simple drawing and saves it to a pdf document: +```go +// Initialize the graphic context on an RGBA image +dest := draw2dpdf.NewPdf("L", "mm", "A4") +gc := draw2dpdf.NewGraphicContext(dest) + +// Set some properties +gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff}) +gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff}) +gc.SetLineWidth(5) + +// Draw a closed shape +gc.MoveTo(10, 10) // should always be called first for a new path +gc.LineTo(100, 50) +gc.QuadCurveTo(100, 10, 10, 10) +gc.Close() +gc.FillStroke() + +// Save to file +draw2dpdf.SaveToPdfFile("hello.pdf", dest) +``` + +There are more examples here: https://github.com/llgcode/draw2d/tree/master/samples + +Alternative backends +-------------------- + +- Drawing on images is provided by the draw2d package. +- Drawing on opengl is provided by the draw2dgl package. + +Acknowledgments +--------------- + +The pdf backend uses https://github.com/jung-kurt/gofpdf diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/doc.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/doc.go new file mode 100644 index 0000000..2ec7081 --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/doc.go @@ -0,0 +1,41 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + +// Package draw2dpdf provides a graphic context that can draw vector +// graphics and text on pdf file with the gofpdf package. +// +// Quick Start +// +// The following Go code generates a simple drawing and saves it to a +// pdf document: +// // Initialize the graphic context on an RGBA image +// dest := draw2dpdf.NewPdf("L", "mm", "A4") +// gc := draw2dpdf.NewGraphicContext(dest) +// +// // Set some properties +// gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff}) +// gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff}) +// gc.SetLineWidth(5) +// +// // Draw a closed shape +// gc.MoveTo(10, 10) // should always be called first for a new path +// gc.LineTo(100, 50) +// gc.QuadCurveTo(100, 10, 10, 10) +// gc.Close() +// gc.FillStroke() +// +// // Save to file +// draw2dpdf.SaveToPdfFile("hello.pdf", dest) +// +// There are more examples here: +// https://github.com/llgcode/draw2d/tree/master/samples +// +// Alternative backends +// +// Drawing on images is provided by the draw2d package. +// Drawing on opengl is provided by the draw2dgl package. +// +// Acknowledgments +// +// The pdf backend uses https://github.com/jung-kurt/gofpdf +package draw2dpdf diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/fileutil.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/fileutil.go new file mode 100644 index 0000000..349545d --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/fileutil.go @@ -0,0 +1,11 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + +package draw2dpdf + +import "github.com/jung-kurt/gofpdf" + +// SaveToPdfFile creates and saves a pdf document to a file +func SaveToPdfFile(filePath string, pdf *gofpdf.Fpdf) error { + return pdf.OutputFileAndClose(filePath) +} diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/gc.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/gc.go new file mode 100644 index 0000000..c14610a --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/gc.go @@ -0,0 +1,379 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels +// TODO: dashed line + +package draw2dpdf + +import ( + "bytes" + "image" + "image/color" + "image/png" + "log" + "math" + "os" + "strconv" + + "github.com/golang/freetype/truetype" + + "github.com/jung-kurt/gofpdf" + "github.com/llgcode/draw2d" + "github.com/llgcode/draw2d/draw2dbase" + "github.com/llgcode/draw2d/draw2dkit" +) + +const ( + // DPI of a pdf document is fixed at 72. + DPI = 72 + c255 = 255.0 / 65535.0 +) + +var ( + caps = map[draw2d.LineCap]string{ + draw2d.RoundCap: "round", + draw2d.ButtCap: "butt", + draw2d.SquareCap: "square"} + joins = map[draw2d.LineJoin]string{ + draw2d.RoundJoin: "round", + draw2d.BevelJoin: "bevel", + draw2d.MiterJoin: "miter", + } + imageCount uint32 + white color.Color = color.RGBA{255, 255, 255, 255} +) + +// NewPdf creates a new pdf document with the draw2d fontfolder, adds +// a page and set fill color to white. +func NewPdf(orientationStr, unitStr, sizeStr string) *gofpdf.Fpdf { + pdf := gofpdf.New(orientationStr, unitStr, sizeStr, draw2d.GetFontFolder()) + // to be compatible with draw2d + pdf.SetMargins(0, 0, 0) + pdf.SetDrawColor(0, 0, 0) + pdf.SetFillColor(255, 255, 255) + pdf.SetLineCapStyle("round") + pdf.SetLineJoinStyle("round") + pdf.SetLineWidth(1) + pdf.AddPage() + return pdf +} + +// rgb converts a color (used by draw2d) into 3 int (used by gofpdf) +func rgb(c color.Color) (int, int, int) { + r, g, b, _ := c.RGBA() + return int(float64(r) * c255), int(float64(g) * c255), int(float64(b) * c255) +} + +// clearRect draws a white rectangle +func clearRect(gc *GraphicContext, x1, y1, x2, y2 float64) { + // save state + f := gc.Current.FillColor + x, y := gc.pdf.GetXY() + // cover page with white rectangle + gc.SetFillColor(white) + draw2dkit.Rectangle(gc, x1, y1, x2, y2) + gc.Fill() + // restore state + gc.SetFillColor(f) + gc.pdf.MoveTo(x, y) +} + +// GraphicContext implements the draw2d.GraphicContext interface +// It provides draw2d with a pdf backend (based on gofpdf) +type GraphicContext struct { + *draw2dbase.StackGraphicContext + pdf *gofpdf.Fpdf + DPI int +} + +// NewGraphicContext creates a new pdf GraphicContext +func NewGraphicContext(pdf *gofpdf.Fpdf) *GraphicContext { + gc := &GraphicContext{draw2dbase.NewStackGraphicContext(), pdf, DPI} + gc.SetDPI(DPI) + return gc +} + +// DrawImage draws an image as PNG +// TODO: add type (tp) as parameter to argument list? +func (gc *GraphicContext) DrawImage(image image.Image) { + name := strconv.Itoa(int(imageCount)) + imageCount++ + tp := "PNG" // "JPG", "JPEG", "PNG" and "GIF" + b := &bytes.Buffer{} + png.Encode(b, image) + gc.pdf.RegisterImageReader(name, tp, b) + bounds := image.Bounds() + x0, y0 := float64(bounds.Min.X), float64(bounds.Min.Y) + w, h := float64(bounds.Dx()), float64(bounds.Dy()) + gc.pdf.Image(name, x0, y0, w, h, false, tp, 0, "") +} + +// Clear draws a white rectangle over the whole page +func (gc *GraphicContext) Clear() { + width, height := gc.pdf.GetPageSize() + clearRect(gc, 0, 0, width, height) +} + +// ClearRect draws a white rectangle over the specified area. +// Samples: line. +func (gc *GraphicContext) ClearRect(x1, y1, x2, y2 int) { + clearRect(gc, float64(x1), float64(y1), float64(x2), float64(y2)) +} + +// recalc recalculates scale and bounds values from the font size, screen +// resolution and font metrics, and invalidates the glyph cache. +func (gc *GraphicContext) recalc() { + // TODO: resolve properly the font size for pdf and bitmap + gc.Current.Scale = 3 * float64(gc.DPI) / 72 +} + +// SetDPI sets the DPI which influences the font size. +func (gc *GraphicContext) SetDPI(dpi int) { + gc.DPI = dpi + gc.recalc() +} + +// GetDPI returns the DPI which influences the font size. +// (Note that gofpdf uses a fixed dpi of 72: +// https://godoc.org/code.google.com/p/gofpdf#Fpdf.PointConvert) +func (gc *GraphicContext) GetDPI() int { + return gc.DPI +} + +// GetStringBounds returns the approximate pixel bounds of the string s at x, y. +// The left edge of the em square of the first character of s +// and the baseline intersect at 0, 0 in the returned coordinates. +// Therefore the top and left coordinates may well be negative. +func (gc *GraphicContext) GetStringBounds(s string) (left, top, right, bottom float64) { + _, h := gc.pdf.GetFontSize() + d := gc.pdf.GetFontDesc("", "") + if d.Ascent == 0 { + // not defined (standard font?), use average of 81% + top = 0.81 * h + } else { + top = -float64(d.Ascent) * h / float64(d.Ascent-d.Descent) + } + return 0, top, gc.pdf.GetStringWidth(s), top + h +} + +// CreateStringPath creates a path from the string s at x, y, and returns the string width. +func (gc *GraphicContext) CreateStringPath(text string, x, y float64) (cursor float64) { + //fpdf uses the top left corner + left, top, right, bottom := gc.GetStringBounds(text) + w := right - left + h := bottom - top + // gc.pdf.SetXY(x, y-h) do not use this as y-h might be negative + margin := gc.pdf.GetCellMargin() + gc.pdf.MoveTo(x-left-margin, y+top) + gc.pdf.CellFormat(w, h, text, "", 0, "BL", false, 0, "") + return w +} + +// FillString draws a string at 0, 0 +func (gc *GraphicContext) FillString(text string) (cursor float64) { + return gc.FillStringAt(text, 0, 0) +} + +// FillStringAt draws a string at x, y +func (gc *GraphicContext) FillStringAt(text string, x, y float64) (cursor float64) { + return gc.CreateStringPath(text, x, y) +} + +// StrokeString draws a string at 0, 0 (stroking is unsupported, +// string will be filled) +func (gc *GraphicContext) StrokeString(text string) (cursor float64) { + return gc.StrokeStringAt(text, 0, 0) +} + +// StrokeStringAt draws a string at x, y (stroking is unsupported, +// string will be filled) +func (gc *GraphicContext) StrokeStringAt(text string, x, y float64) (cursor float64) { + return gc.CreateStringPath(text, x, y) +} + +// Stroke strokes the paths with the color specified by SetStrokeColor +func (gc *GraphicContext) Stroke(paths ...*draw2d.Path) { + _, _, _, alphaS := gc.Current.StrokeColor.RGBA() + gc.draw("D", alphaS, paths...) + gc.Current.Path.Clear() +} + +// Fill fills the paths with the color specified by SetFillColor +func (gc *GraphicContext) Fill(paths ...*draw2d.Path) { + style := "F" + if gc.Current.FillRule != draw2d.FillRuleWinding { + style += "*" + } + _, _, _, alphaF := gc.Current.FillColor.RGBA() + gc.draw(style, alphaF, paths...) + gc.Current.Path.Clear() +} + +// FillStroke first fills the paths and than strokes them +func (gc *GraphicContext) FillStroke(paths ...*draw2d.Path) { + var rule string + if gc.Current.FillRule != draw2d.FillRuleWinding { + rule = "*" + } + _, _, _, alphaS := gc.Current.StrokeColor.RGBA() + _, _, _, alphaF := gc.Current.FillColor.RGBA() + if alphaS == alphaF { + gc.draw("FD"+rule, alphaF, paths...) + } else { + gc.draw("F"+rule, alphaF, paths...) + gc.draw("S", alphaS, paths...) + } + gc.Current.Path.Clear() +} + +var logger = log.New(os.Stdout, "", log.Lshortfile) + +const alphaMax = float64(0xFFFF) + +// draw fills and/or strokes paths +func (gc *GraphicContext) draw(style string, alpha uint32, paths ...*draw2d.Path) { + paths = append(paths, gc.Current.Path) + for _, p := range paths { + ConvertPath(p, gc.pdf) + } + a := float64(alpha) / alphaMax + current, blendMode := gc.pdf.GetAlpha() + if a != current { + gc.pdf.SetAlpha(a, blendMode) + } + gc.pdf.DrawPath(style) +} + +// overwrite StackGraphicContext methods + +// SetStrokeColor sets the stroke color +func (gc *GraphicContext) SetStrokeColor(c color.Color) { + gc.StackGraphicContext.SetStrokeColor(c) + gc.pdf.SetDrawColor(rgb(c)) +} + +// SetFillColor sets the fill and text color +func (gc *GraphicContext) SetFillColor(c color.Color) { + gc.StackGraphicContext.SetFillColor(c) + gc.pdf.SetFillColor(rgb(c)) + gc.pdf.SetTextColor(rgb(c)) +} + +// SetFont is unsupported by the pdf graphic context, use SetFontData +// instead. +func (gc *GraphicContext) SetFont(font *truetype.Font) { + // TODO: what to do with this api conflict between draw2d and gofpdf?! +} + +// SetFontData sets the current font used to draw text. Always use +// this method, as SetFont is unsupported by the pdf graphic context. +// It is mandatory to call this method at least once before printing +// text or the resulting document will not be valid. +// It is necessary to generate a font definition file first with the +// makefont utility. It is not necessary to call this function for the +// core PDF fonts (courier, helvetica, times, zapfdingbats). +// go get github.com/jung-kurt/gofpdf/makefont +// http://godoc.org/github.com/jung-kurt/gofpdf#Fpdf.AddFont +func (gc *GraphicContext) SetFontData(fontData draw2d.FontData) { + // TODO: call Makefont embed if json file does not exist yet + gc.StackGraphicContext.SetFontData(fontData) + var style string + if fontData.Style&draw2d.FontStyleBold != 0 { + style += "B" + } + if fontData.Style&draw2d.FontStyleItalic != 0 { + style += "I" + } + fn := draw2d.FontFileName(fontData) + fn = fn[:len(fn)-4] + size, _ := gc.pdf.GetFontSize() + gc.pdf.AddFont(fontData.Name, style, fn+".json") + gc.pdf.SetFont(fontData.Name, style, size) +} + +// SetFontSize sets the font size in points (as in ``a 12 point font''). +// TODO: resolve this with ImgGraphicContext (now done with gc.Current.Scale) +func (gc *GraphicContext) SetFontSize(fontSize float64) { + gc.StackGraphicContext.SetFontSize(fontSize) + gc.recalc() + gc.pdf.SetFontSize(fontSize * gc.Current.Scale) +} + +// SetLineDash sets the line dash pattern +func (gc *GraphicContext) SetLineDash(Dash []float64, DashOffset float64) { + gc.StackGraphicContext.SetLineDash(Dash, DashOffset) + gc.pdf.SetDashPattern(Dash, DashOffset) +} + +// SetLineWidth sets the line width +func (gc *GraphicContext) SetLineWidth(LineWidth float64) { + gc.StackGraphicContext.SetLineWidth(LineWidth) + gc.pdf.SetLineWidth(LineWidth) +} + +// SetLineCap sets the line cap (round, but or square) +func (gc *GraphicContext) SetLineCap(Cap draw2d.LineCap) { + gc.StackGraphicContext.SetLineCap(Cap) + gc.pdf.SetLineCapStyle(caps[Cap]) +} + +// SetLineJoin sets the line cap (round, bevel or miter) +func (gc *GraphicContext) SetLineJoin(Join draw2d.LineJoin) { + gc.StackGraphicContext.SetLineJoin(Join) + gc.pdf.SetLineJoinStyle(joins[Join]) +} + +// Transformations + +// Scale generally scales the following text, drawings and images. +// sx and sy are the scaling factors for width and height. +// This must be placed between gc.Save() and gc.Restore(), otherwise +// the pdf is invalid. +func (gc *GraphicContext) Scale(sx, sy float64) { + gc.StackGraphicContext.Scale(sx, sy) + gc.pdf.TransformScale(sx*100, sy*100, 0, 0) +} + +// Rotate rotates the following text, drawings and images. +// Angle is specified in radians and measured clockwise from the +// 3 o'clock position. +// This must be placed between gc.Save() and gc.Restore(), otherwise +// the pdf is invalid. +func (gc *GraphicContext) Rotate(angle float64) { + gc.StackGraphicContext.Rotate(angle) + gc.pdf.TransformRotate(-angle*180/math.Pi, 0, 0) +} + +// Translate moves the following text, drawings and images +// horizontally and vertically by the amounts specified by tx and ty. +// This must be placed between gc.Save() and gc.Restore(), otherwise +// the pdf is invalid. +func (gc *GraphicContext) Translate(tx, ty float64) { + gc.StackGraphicContext.Translate(tx, ty) + gc.pdf.TransformTranslate(tx, ty) +} + +// Save saves the current context stack +// (transformation, font, color,...). +func (gc *GraphicContext) Save() { + gc.StackGraphicContext.Save() + gc.pdf.TransformBegin() +} + +// Restore restores the current context stack +// (transformation, color,...). Restoring the font is not supported. +func (gc *GraphicContext) Restore() { + gc.pdf.TransformEnd() + gc.StackGraphicContext.Restore() + c := gc.Current + gc.SetFontSize(c.FontSize) + // gc.SetFontData(c.FontData) unsupported, causes bug (do not enable) + gc.SetLineWidth(c.LineWidth) + gc.SetStrokeColor(c.StrokeColor) + gc.SetFillColor(c.FillColor) + gc.SetFillRule(c.FillRule) + // gc.SetLineDash(c.Dash, c.DashOffset) // TODO + gc.SetLineCap(c.Cap) + gc.SetLineJoin(c.Join) + // c.Path unsupported + // c.Font unsupported +} diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/path_converter.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/path_converter.go new file mode 100644 index 0000000..49832cf --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/path_converter.go @@ -0,0 +1,44 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + +package draw2dpdf + +import ( + "math" + + "github.com/llgcode/draw2d" +) + +const deg = 180 / math.Pi + +// ConvertPath converts a paths to the pdf api +func ConvertPath(path *draw2d.Path, pdf Vectorizer) { + var startX, startY float64 = 0, 0 + i := 0 + for _, cmp := range path.Components { + switch cmp { + case draw2d.MoveToCmp: + startX, startY = path.Points[i], path.Points[i+1] + pdf.MoveTo(startX, startY) + i += 2 + case draw2d.LineToCmp: + pdf.LineTo(path.Points[i], path.Points[i+1]) + i += 2 + case draw2d.QuadCurveToCmp: + pdf.CurveTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3]) + i += 4 + case draw2d.CubicCurveToCmp: + pdf.CurveBezierCubicTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3], path.Points[i+4], path.Points[i+5]) + i += 6 + case draw2d.ArcToCmp: + pdf.ArcTo(path.Points[i], path.Points[i+1], path.Points[i+2], path.Points[i+3], + 0, // degRotate + path.Points[i+4]*deg, // degStart = startAngle + (path.Points[i+4]-path.Points[i+5])*deg) // degEnd = startAngle-angle + i += 6 + case draw2d.CloseCmp: + pdf.LineTo(startX, startY) + pdf.ClosePath() + } + } +} diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/samples_test.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/samples_test.go new file mode 100644 index 0000000..ca3441f --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/samples_test.go @@ -0,0 +1,65 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels +// See also test_test.go + +package draw2dpdf_test + +import ( + "testing" + + "github.com/llgcode/draw2d" + "github.com/llgcode/draw2d/samples/android" + "github.com/llgcode/draw2d/samples/frameimage" + "github.com/llgcode/draw2d/samples/geometry" + "github.com/llgcode/draw2d/samples/gopher" + "github.com/llgcode/draw2d/samples/gopher2" + "github.com/llgcode/draw2d/samples/helloworld" + "github.com/llgcode/draw2d/samples/line" + "github.com/llgcode/draw2d/samples/linecapjoin" + "github.com/llgcode/draw2d/samples/postscript" +) + +func TestSampleAndroid(t *testing.T) { + test(t, android.Main) +} + +// TODO: FillString: w (width) is incorrect +func TestSampleGeometry(t *testing.T) { + // Set the global folder for searching fonts + // The pdf backend needs for every ttf file its corresponding + // json/.z file which is generated by gofpdf/makefont. + draw2d.SetFontFolder("../resource/font") + test(t, geometry.Main) +} + +func TestSampleGopher(t *testing.T) { + test(t, gopher.Main) +} + +func TestSampleGopher2(t *testing.T) { + test(t, gopher2.Main) +} + +func TestSampleHelloWorld(t *testing.T) { + // Set the global folder for searching fonts + // The pdf backend needs for every ttf file its corresponding + // json/.z file which is generated by gofpdf/makefont. + draw2d.SetFontFolder("../resource/font") + test(t, helloworld.Main) +} + +func TestSampleFrameImage(t *testing.T) { + test(t, frameimage.Main) +} + +func TestSampleLine(t *testing.T) { + test(t, line.Main) +} + +func TestSampleLineCap(t *testing.T) { + test(t, linecapjoin.Main) +} + +func TestSamplePostscript(t *testing.T) { + test(t, postscript.Main) +} diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/test_test.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/test_test.go new file mode 100644 index 0000000..801ff36 --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/test_test.go @@ -0,0 +1,39 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + +// Package draw2dpdf_test gives test coverage with the command: +// go test -cover ./... | grep -v "no test" +// (It should be run from its parent draw2d directory.) +package draw2dpdf_test + +import ( + "testing" + + "github.com/llgcode/draw2d" + "github.com/llgcode/draw2d/draw2dpdf" +) + +type sample func(gc draw2d.GraphicContext, ext string) (string, error) + +func test(t *testing.T, draw sample) { + // Initialize the graphic context on an pdf document + dest := draw2dpdf.NewPdf("L", "mm", "A4") + gc := draw2dpdf.NewGraphicContext(dest) + // Draw sample + output, err := draw(gc, "pdf") + if err != nil { + t.Errorf("Drawing %q failed: %v", output, err) + return + } + /* + // Save to pdf only if it doesn't exist because of git + if _, err = os.Stat(output); err == nil { + t.Skipf("Saving %q skipped, as it exists already. (Git would consider it modified.)", output) + return + } + */ + err = draw2dpdf.SaveToPdfFile(output, dest) + if err != nil { + t.Errorf("Saving %q failed: %v", output, err) + } +} diff --git a/vendor/github.com/llgcode/draw2d/draw2dpdf/vectorizer.go b/vendor/github.com/llgcode/draw2d/draw2dpdf/vectorizer.go new file mode 100644 index 0000000..556c2e0 --- /dev/null +++ b/vendor/github.com/llgcode/draw2d/draw2dpdf/vectorizer.go @@ -0,0 +1,22 @@ +// Copyright 2015 The draw2d Authors. All rights reserved. +// created: 26/06/2015 by Stani Michiels + +package draw2dpdf + +// Vectorizer defines the minimal interface for gofpdf.Fpdf +// to be passed to a PathConvertor. +// It is also implemented by for example VertexMatrixTransform +type Vectorizer interface { + // MoveTo creates a new subpath that start at the specified point + MoveTo(x, y float64) + // LineTo adds a line to the current subpath + LineTo(x, y float64) + // CurveTo adds a quadratic bezier curve to the current subpath + CurveTo(cx, cy, x, y float64) + // CurveTo adds a cubic bezier curve to the current subpath + CurveBezierCubicTo(cx1, cy1, cx2, cy2, x, y float64) + // ArcTo adds an arc to the current subpath + ArcTo(x, y, rx, ry, degRotate, degStart, degEnd float64) + // ClosePath closes the subpath + ClosePath() +} -- cgit v1.2.3