improve documentation for godoc
This commit is contained in:
parent
8c807d1289
commit
67213e40fc
5 changed files with 109 additions and 43 deletions
13
README.md
13
README.md
|
@ -1,19 +1,20 @@
|
|||
draw2d
|
||||
======
|
||||
|
||||
This package (written in [go](http://golang.org)) provides an API to draw 2d vector forms on [images](http://golang.org/pkg/image).
|
||||
Package draw2d is a pure [go](http://golang.org) 2D vector graphics library with support for multiple output devices such as [images](http://golang.org/pkg/image) (draw2d), pdf documents (draw2dpdf) and opengl (draw2dopengl), which can also be used on the google app engine.
|
||||
This library is inspired by [postscript](http://www.tailrecursive.org/postscript) and [HTML5 canvas](http://www.w3.org/TR/2dcontext/).
|
||||
|
||||
See the [documentation](http://godoc.org/github.com/llgcode/draw2d) for more details.
|
||||
|
||||
The package depends on [freetype-go](http://code.google.com/p/freetype-go) package for its rasterization algorithm.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Using
|
||||
-----
|
||||
|
||||
Install [golang](http://golang.org/doc/install) and get `draw2d`
|
||||
Install [golang](http://golang.org/doc/install). To install or update the package draw2d on your system, run:
|
||||
|
||||
```
|
||||
go get github.com/llgcode/draw2d
|
||||
go get -u github.com/llgcode/draw2d
|
||||
```
|
||||
|
||||
and start coding using one of the [Samples](https://github.com/llgcode/draw2d.samples).
|
||||
|
|
65
draw2d.go
65
draw2d.go
|
@ -1,5 +1,68 @@
|
|||
// Copyright 2010 The draw2d Authors. All rights reserved.
|
||||
// created: 13/12/2010 by Laurent Le Goff
|
||||
|
||||
// Package draw2d provides a Graphic Context that can draw vector form on canvas.
|
||||
// Package draw2d is a pure go 2D vector graphics library with support
|
||||
// for multiple output devices such as images (draw2d), pdf documents
|
||||
// (draw2dpdf) and opengl (draw2dopengl), which can also be used on the
|
||||
// google app engine.
|
||||
//
|
||||
// Features
|
||||
//
|
||||
// Operations in draw2d include stroking and filling polygons, arcs,
|
||||
// Bézier curves, drawing images and text rendering with truetype fonts.
|
||||
// All drawing operations can be transformed by affine transformations
|
||||
// (scale, rotation, translation).
|
||||
//
|
||||
// Installation
|
||||
//
|
||||
// To install or update the package on your system, run:
|
||||
// go get -u github.com/llgcode/draw2d
|
||||
//
|
||||
// Quick Start
|
||||
//
|
||||
// Package draw2d itself provides a graphic context that can draw vector
|
||||
// graphics and text on an image canvas. The following Go code
|
||||
// generates a simple drawing and saves it to an image file:
|
||||
// // Initialize the graphic context on an RGBA image
|
||||
// dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
|
||||
// gc := draw2d.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
|
||||
// draw2d.SaveToPngFile(fn, dest)
|
||||
//
|
||||
// There are more examples here:
|
||||
// https://github.com/llgcode/draw2d.samples
|
||||
//
|
||||
// Drawing on pdf documents is provided by the draw2dpdf package.
|
||||
// Drawing on opengl is provided by the draw2dgl package.
|
||||
// See subdirectories at the bottom of this page.
|
||||
//
|
||||
// Acknowledgments
|
||||
//
|
||||
// Laurent Le Goff wrote this library, inspired by postscript and
|
||||
// HTML5 canvas. He implemented the image and opengl backend. Also
|
||||
// he created a pure go Postscripter interpreter which can draw to a
|
||||
// draw2d graphic context (https://github.com/llgcode/ps). Stani
|
||||
// Michiels implemented the pdf backend.
|
||||
//
|
||||
// The package depends on freetype-go package for its rasterization
|
||||
// algorithm.
|
||||
//
|
||||
// Packages using draw2d
|
||||
//
|
||||
// - https://github.com/llgcode/ps
|
||||
//
|
||||
// - https://github.com/gonum/plot
|
||||
package draw2d
|
||||
|
|
3
draw2dgl/doc.go
Normal file
3
draw2dgl/doc.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Package draw2dgl provides a graphic context that can draw vector
|
||||
// graphics and text on OpenGL.
|
||||
package draw2dgl
|
|
@ -1,5 +1,39 @@
|
|||
// 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 form on pdf file.
|
||||
// Package draw2dpdf provides a graphic context that can draw vector
|
||||
// graphics and text on pdf file.
|
||||
//
|
||||
// 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 := draw2d.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(fn, dest)
|
||||
//
|
||||
// There are more examples here:
|
||||
// https://github.com/llgcode/draw2d.samples
|
||||
//
|
||||
// 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
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package draw2dpdf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
|
||||
"github.com/llgcode/draw2d"
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
)
|
||||
|
||||
func ExampleGraphicContext() {
|
||||
// Initialize the graphic context on a pdf document
|
||||
pdf := gofpdf.New("P", "mm", "A4", "../font")
|
||||
pdf.AddPage()
|
||||
gc := NewGraphicContext(pdf)
|
||||
|
||||
// some properties
|
||||
gc.SetFillColor(color.RGBA{0x44, 0xff, 0x44, 0xff})
|
||||
gc.SetStrokeColor(color.RGBA{0x44, 0x44, 0x44, 0xff})
|
||||
gc.SetLineCap(draw2d.RoundCap)
|
||||
gc.SetLineWidth(5)
|
||||
|
||||
// draw something
|
||||
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()
|
||||
fmt.Println(gc.LastPoint())
|
||||
|
||||
// draw2dpdf.SaveToPdfFile("example.pdf", pdf)
|
||||
|
||||
// Output:
|
||||
// 10 10
|
||||
}
|
Loading…
Reference in a new issue