gg: github.com/fogleman/gg Index | Files | Directories

package gg

import "github.com/fogleman/gg"

Package gg provides a simple API for rendering 2D graphics in pure Go.

Index

Package Files

bezier.go context.go gradient.go matrix.go path.go pattern.go point.go util.go wrap.go

func Degrees Uses

func Degrees(radians float64) float64

func LoadFontFace Uses

func LoadFontFace(path string, points float64) (font.Face, error)

LoadFontFace is a helper function to load the specified font file with the specified point size. Note that the returned `font.Face` objects are not thread safe and cannot be used in parallel across goroutines. You can usually just use the Context.LoadFontFace function instead of this package-level function.

func LoadImage Uses

func LoadImage(path string) (image.Image, error)

func LoadPNG Uses

func LoadPNG(path string) (image.Image, error)

func Radians Uses

func Radians(degrees float64) float64

func SavePNG Uses

func SavePNG(path string, im image.Image) error

type Align Uses

type Align int
const (
    AlignLeft Align = iota
    AlignCenter
    AlignRight
)

type Context Uses

type Context struct {
    // contains filtered or unexported fields
}

func NewContext Uses

func NewContext(width, height int) *Context

NewContext creates a new image.RGBA with the specified width and height and prepares a context for rendering onto that image.

func NewContextForImage Uses

func NewContextForImage(im image.Image) *Context

NewContextForImage copies the specified image into a new image.RGBA and prepares a context for rendering onto that image.

func NewContextForRGBA Uses

func NewContextForRGBA(im *image.RGBA) *Context

NewContextForRGBA prepares a context for rendering onto the specified image. No copy is made.

func (*Context) AsMask Uses

func (dc *Context) AsMask() *image.Alpha

AsMask returns an *image.Alpha representing the alpha channel of this context. This can be useful for advanced clipping operations where you first render the mask geometry and then use it as a mask.

func (*Context) Clear Uses

func (dc *Context) Clear()

Clear fills the entire image with the current color.

func (*Context) ClearPath Uses

func (dc *Context) ClearPath()

ClearPath clears the current path. There is no current point after this operation.

func (*Context) Clip Uses

func (dc *Context) Clip()

Clip updates the clipping region by intersecting the current clipping region with the current path as it would be filled by dc.Fill(). The path is cleared after this operation.

func (*Context) ClipPreserve Uses

func (dc *Context) ClipPreserve()

ClipPreserve updates the clipping region by intersecting the current clipping region with the current path as it would be filled by dc.Fill(). The path is preserved after this operation.

func (*Context) ClosePath Uses

func (dc *Context) ClosePath()

ClosePath adds a line segment from the current point to the beginning of the current subpath. If there is no current point, this is a no-op.

func (*Context) CubicTo Uses

func (dc *Context) CubicTo(x1, y1, x2, y2, x3, y3 float64)

CubicTo adds a cubic bezier curve to the current path starting at the current point. If there is no current point, it first performs MoveTo(x1, y1). Because freetype/raster does not support cubic beziers, this is emulated with many small line segments.

func (*Context) DrawArc Uses

func (dc *Context) DrawArc(x, y, r, angle1, angle2 float64)

func (*Context) DrawCircle Uses

func (dc *Context) DrawCircle(x, y, r float64)

func (*Context) DrawEllipse Uses

func (dc *Context) DrawEllipse(x, y, rx, ry float64)

func (*Context) DrawEllipticalArc Uses

func (dc *Context) DrawEllipticalArc(x, y, rx, ry, angle1, angle2 float64)

func (*Context) DrawImage Uses

func (dc *Context) DrawImage(im image.Image, x, y int)

DrawImage draws the specified image at the specified point.

func (*Context) DrawImageAnchored Uses

func (dc *Context) DrawImageAnchored(im image.Image, x, y int, ax, ay float64)

DrawImageAnchored draws the specified image at the specified anchor point. The anchor point is x - w * ax, y - h * ay, where w, h is the size of the image. Use ax=0.5, ay=0.5 to center the image at the specified point.

func (*Context) DrawLine Uses

func (dc *Context) DrawLine(x1, y1, x2, y2 float64)

func (*Context) DrawPoint Uses

func (dc *Context) DrawPoint(x, y, r float64)

DrawPoint is like DrawCircle but ensures that a circle of the specified size is drawn regardless of the current transformation matrix. The position is still transformed, but not the shape of the point.

func (*Context) DrawRectangle Uses

func (dc *Context) DrawRectangle(x, y, w, h float64)

func (*Context) DrawRegularPolygon Uses

func (dc *Context) DrawRegularPolygon(n int, x, y, r, rotation float64)

func (*Context) DrawRoundedRectangle Uses

func (dc *Context) DrawRoundedRectangle(x, y, w, h, r float64)

func (*Context) DrawString Uses

func (dc *Context) DrawString(s string, x, y float64)

DrawString draws the specified text at the specified point.

func (*Context) DrawStringAnchored Uses

func (dc *Context) DrawStringAnchored(s string, x, y, ax, ay float64)

DrawStringAnchored draws the specified text at the specified anchor point. The anchor point is x - w * ax, y - h * ay, where w, h is the size of the text. Use ax=0.5, ay=0.5 to center the text at the specified point.

func (*Context) DrawStringWrapped Uses

func (dc *Context) DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Align)

DrawStringWrapped word-wraps the specified string to the given max width and then draws it at the specified anchor point using the given line spacing and text alignment.

func (*Context) EncodePNG Uses

func (dc *Context) EncodePNG(w io.Writer) error

EncodePNG encodes the image as a PNG and writes it to the provided io.Writer.

func (*Context) Fill Uses

func (dc *Context) Fill()

Fill fills the current path with the current color. Open subpaths are implicity closed. The path is cleared after this operation.

func (*Context) FillPreserve Uses

func (dc *Context) FillPreserve()

FillPreserve fills the current path with the current color. Open subpaths are implicity closed. The path is preserved after this operation.

func (*Context) FontHeight Uses

func (dc *Context) FontHeight() float64

func (*Context) Height Uses

func (dc *Context) Height() int

Height returns the height of the image in pixels.

func (*Context) Identity Uses

func (dc *Context) Identity()

Identity resets the current transformation matrix to the identity matrix. This results in no translating, scaling, rotating, or shearing.

func (*Context) Image Uses

func (dc *Context) Image() image.Image

Image returns the image that has been drawn by this context.

func (*Context) InvertY Uses

func (dc *Context) InvertY()

InvertY flips the Y axis so that Y grows from bottom to top and Y=0 is at the bottom of the image.

func (*Context) LineTo Uses

func (dc *Context) LineTo(x, y float64)

LineTo adds a line segment to the current path starting at the current point. If there is no current point, it is equivalent to MoveTo(x, y)

func (*Context) LoadFontFace Uses

func (dc *Context) LoadFontFace(path string, points float64) error

func (*Context) MeasureString Uses

func (dc *Context) MeasureString(s string) (w, h float64)

MeasureString returns the rendered width and height of the specified text given the current font face.

func (*Context) MoveTo Uses

func (dc *Context) MoveTo(x, y float64)

MoveTo starts a new subpath within the current path starting at the specified point.

func (*Context) NewSubPath Uses

func (dc *Context) NewSubPath()

NewSubPath starts a new subpath within the current path. There is no current point after this operation.

func (*Context) Pop Uses

func (dc *Context) Pop()

Pop restores the last saved context state from the stack.

func (*Context) Push Uses

func (dc *Context) Push()

Push saves the current state of the context for later retrieval. These can be nested.

func (*Context) QuadraticTo Uses

func (dc *Context) QuadraticTo(x1, y1, x2, y2 float64)

QuadraticTo adds a quadratic bezier curve to the current path starting at the current point. If there is no current point, it first performs MoveTo(x1, y1)

func (*Context) ResetClip Uses

func (dc *Context) ResetClip()

ResetClip clears the clipping region.

func (*Context) Rotate Uses

func (dc *Context) Rotate(angle float64)

Rotate updates the current matrix with a clockwise rotation. Rotation occurs about the origin. Angle is specified in radians.

func (*Context) RotateAbout Uses

func (dc *Context) RotateAbout(angle, x, y float64)

RotateAbout updates the current matrix with a clockwise rotation. Rotation occurs about the specified point. Angle is specified in radians.

func (*Context) SavePNG Uses

func (dc *Context) SavePNG(path string) error

SavePNG encodes the image as a PNG and writes it to disk.

func (*Context) Scale Uses

func (dc *Context) Scale(x, y float64)

Scale updates the current matrix with a scaling factor. Scaling occurs about the origin.

func (*Context) ScaleAbout Uses

func (dc *Context) ScaleAbout(sx, sy, x, y float64)

ScaleAbout updates the current matrix with a scaling factor. Scaling occurs about the specified point.

func (*Context) SetColor Uses

func (dc *Context) SetColor(c color.Color)

SetColor sets the current color(for both fill and stroke).

func (*Context) SetDash Uses

func (dc *Context) SetDash(dashes ...float64)

SetDash sets the current dash pattern to use. Call with zero arguments to disable dashes. The values specify the lengths of each dash, with alternating on and off lengths.

func (*Context) SetFillRule Uses

func (dc *Context) SetFillRule(fillRule FillRule)

func (*Context) SetFillRuleEvenOdd Uses

func (dc *Context) SetFillRuleEvenOdd()

func (*Context) SetFillRuleWinding Uses

func (dc *Context) SetFillRuleWinding()

func (*Context) SetFillStyle Uses

func (dc *Context) SetFillStyle(pattern Pattern)

SetFillStyle sets current fill style

func (*Context) SetFontFace Uses

func (dc *Context) SetFontFace(fontFace font.Face)

func (*Context) SetHexColor Uses

func (dc *Context) SetHexColor(x string)

SetHexColor sets the current color using a hex string. The leading pound sign (#) is optional. Both 3- and 6-digit variations are supported. 8 digits may be provided to set the alpha value as well.

func (*Context) SetLineCap Uses

func (dc *Context) SetLineCap(lineCap LineCap)

func (*Context) SetLineCapButt Uses

func (dc *Context) SetLineCapButt()

func (*Context) SetLineCapRound Uses

func (dc *Context) SetLineCapRound()

func (*Context) SetLineCapSquare Uses

func (dc *Context) SetLineCapSquare()

func (*Context) SetLineJoin Uses

func (dc *Context) SetLineJoin(lineJoin LineJoin)

func (*Context) SetLineJoinBevel Uses

func (dc *Context) SetLineJoinBevel()

func (*Context) SetLineJoinRound Uses

func (dc *Context) SetLineJoinRound()

func (*Context) SetLineWidth Uses

func (dc *Context) SetLineWidth(lineWidth float64)

func (*Context) SetMask Uses

func (dc *Context) SetMask(mask *image.Alpha) error

SetMask allows you to directly set the *image.Alpha to be used as a clipping mask. It must be the same size as the context, else an error is returned and the mask is unchanged.

func (*Context) SetPixel Uses

func (dc *Context) SetPixel(x, y int)

SetPixel sets the color of the specified pixel using the current color.

func (*Context) SetRGB Uses

func (dc *Context) SetRGB(r, g, b float64)

SetRGB sets the current color. r, g, b values should be between 0 and 1, inclusive. Alpha will be set to 1 (fully opaque).

func (*Context) SetRGB255 Uses

func (dc *Context) SetRGB255(r, g, b int)

SetRGB255 sets the current color. r, g, b values should be between 0 and 255, inclusive. Alpha will be set to 255 (fully opaque).

func (*Context) SetRGBA Uses

func (dc *Context) SetRGBA(r, g, b, a float64)

SetRGBA sets the current color. r, g, b, a values should be between 0 and 1, inclusive.

func (*Context) SetRGBA255 Uses

func (dc *Context) SetRGBA255(r, g, b, a int)

SetRGBA255 sets the current color. r, g, b, a values should be between 0 and 255, inclusive.

func (*Context) SetStrokeStyle Uses

func (dc *Context) SetStrokeStyle(pattern Pattern)

SetStrokeStyle sets current stroke style

func (*Context) Shear Uses

func (dc *Context) Shear(x, y float64)

Shear updates the current matrix with a shearing angle. Shearing occurs about the origin.

func (*Context) ShearAbout Uses

func (dc *Context) ShearAbout(sx, sy, x, y float64)

ShearAbout updates the current matrix with a shearing angle. Shearing occurs about the specified point.

func (*Context) Stroke Uses

func (dc *Context) Stroke()

Stroke strokes the current path with the current color, line width, line cap, line join and dash settings. The path is cleared after this operation.

func (*Context) StrokePreserve Uses

func (dc *Context) StrokePreserve()

StrokePreserve strokes the current path with the current color, line width, line cap, line join and dash settings. The path is preserved after this operation.

func (*Context) TransformPoint Uses

func (dc *Context) TransformPoint(x, y float64) (tx, ty float64)

TransformPoint multiplies the specified point by the current matrix, returning a transformed position.

func (*Context) Translate Uses

func (dc *Context) Translate(x, y float64)

Translate updates the current matrix with a translation.

func (*Context) Width Uses

func (dc *Context) Width() int

Width returns the width of the image in pixels.

func (*Context) WordWrap Uses

func (dc *Context) WordWrap(s string, w float64) []string

WordWrap wraps the specified string to the given max width and current font face.

type FillRule Uses

type FillRule int
const (
    FillRuleWinding FillRule = iota
    FillRuleEvenOdd
)

type Gradient Uses

type Gradient interface {
    Pattern
    AddColorStop(offset float64, color color.Color)
}

func NewLinearGradient Uses

func NewLinearGradient(x0, y0, x1, y1 float64) Gradient

func NewRadialGradient Uses

func NewRadialGradient(x0, y0, r0, x1, y1, r1 float64) Gradient

type LineCap Uses

type LineCap int
const (
    LineCapRound LineCap = iota
    LineCapButt
    LineCapSquare
)

type LineJoin Uses

type LineJoin int
const (
    LineJoinRound LineJoin = iota
    LineJoinBevel
)

type Matrix Uses

type Matrix struct {
    XX, YX, XY, YY, X0, Y0 float64
}

func Identity Uses

func Identity() Matrix

func Rotate Uses

func Rotate(angle float64) Matrix

func Scale Uses

func Scale(x, y float64) Matrix

func Shear Uses

func Shear(x, y float64) Matrix

func Translate Uses

func Translate(x, y float64) Matrix

func (Matrix) Multiply Uses

func (a Matrix) Multiply(b Matrix) Matrix

func (Matrix) Rotate Uses

func (a Matrix) Rotate(angle float64) Matrix

func (Matrix) Scale Uses

func (a Matrix) Scale(x, y float64) Matrix

func (Matrix) Shear Uses

func (a Matrix) Shear(x, y float64) Matrix

func (Matrix) TransformPoint Uses

func (a Matrix) TransformPoint(x, y float64) (tx, ty float64)

func (Matrix) TransformVector Uses

func (a Matrix) TransformVector(x, y float64) (tx, ty float64)

func (Matrix) Translate Uses

func (a Matrix) Translate(x, y float64) Matrix

type Pattern Uses

type Pattern interface {
    ColorAt(x, y int) color.Color
}

func NewSolidPattern Uses

func NewSolidPattern(color color.Color) Pattern

func NewSurfacePattern Uses

func NewSurfacePattern(im image.Image, op RepeatOp) Pattern

type Point Uses

type Point struct {
    X, Y float64
}

func CubicBezier Uses

func CubicBezier(x0, y0, x1, y1, x2, y2, x3, y3 float64) []Point

func QuadraticBezier Uses

func QuadraticBezier(x0, y0, x1, y1, x2, y2 float64) []Point

func (Point) Distance Uses

func (a Point) Distance(b Point) float64

func (Point) Fixed Uses

func (a Point) Fixed() fixed.Point26_6

func (Point) Interpolate Uses

func (a Point) Interpolate(b Point, t float64) Point

type RepeatOp Uses

type RepeatOp int
const (
    RepeatBoth RepeatOp = iota
    RepeatX
    RepeatY
    RepeatNone
)

Directories

PathSynopsis
examples

Package gg imports 21 packages (graph) and is imported by 71 packages. Updated 2018-08-23. Refresh now. Tools for package owners.