img

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2020 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

Context implements the graphic context for drawing on images

func NewContextForRGBA

func NewContextForRGBA(im *image.RGBA) *Context

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

func (*Context) ArcTo

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

ArcTo adds a circular arc to the current sub-path, using the given control points and radius. The arc is automatically connected to the path's latest point with a straight line, if necessary for the specified parameters.

This method is commonly used for making rounded corners. https://github.com/WebKit/webkit/blob/main/Source/WebCore/platform/graphics/cairo/PathCairo.cpp#L204

func (*Context) BeginPath

func (dc *Context) BeginPath()

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

func (*Context) Clear

func (dc *Context) Clear()

Clear fills the entire image with the current fill color.

func (*Context) ClearPath

func (dc *Context) ClearPath()

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

func (*Context) Clip

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

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

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) CurrentPoint

func (dc *Context) CurrentPoint() (float64, float64, bool)

CurrentPoint returns the current point and if there is a current point. The point will have been transformed by the context's transformation matrix.

func (*Context) DrawEllipticalArc

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

DrawEllipticalArc draws an elliptical arc

func (*Context) DrawImageAnchored

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

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

DrawLine draws a line

func (*Context) DrawPoint

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

DrawPoint draws a point

func (*Context) DrawStringAnchored

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) Fill

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) FillAndStroke

func (dc *Context) FillAndStroke()

FillAndStroke first fills the paths and than strokes them

func (*Context) FillPreserve

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) FontSize

func (dc *Context) FontSize() float64

FontSize returns font's size

func (*Context) Height

func (dc *Context) Height() float64

Height returns the height of the image in pixels.

func (*Context) Identity

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

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

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

func (*Context) LineTo

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) MeasureString

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

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

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

func (*Context) Pop

func (dc *Context) Pop()

Pop restores the last saved context state from the stack.

func (*Context) Push

func (dc *Context) Push()

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

func (*Context) QuadraticTo

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

func (dc *Context) ResetClip()

ResetClip clears the clipping region.

func (*Context) Rotate

func (dc *Context) Rotate(angle float64)

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

func (*Context) Scale

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

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

func (*Context) SetFillColor

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

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

func (*Context) SetFillRule

func (dc *Context) SetFillRule(fillRule gg.FillRule)

SetFillRule sets the current fill rule

func (*Context) SetFillStyle

func (dc *Context) SetFillStyle(pattern gg.Pattern)

SetFillStyle sets current fill style

func (*Context) SetFont

func (dc *Context) SetFont(font *truetype.Font)

SetFont sets the current font

func (*Context) SetFontSize

func (dc *Context) SetFontSize(points float64)

SetFontSize sets the current font size

func (*Context) SetLineCap

func (dc *Context) SetLineCap(lineCap gg.LineCap)

SetLineCap sets the current line cap

func (*Context) SetLineDash

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

SetLineDash sets the current dash

func (*Context) SetLineDashOffset

func (dc *Context) SetLineDashOffset(offset float64)

SetLineDashOffset sets the initial offset into the dash pattern

func (*Context) SetLineJoin

func (dc *Context) SetLineJoin(lineJoin gg.LineJoin)

SetLineJoin sets the current line join

func (*Context) SetPixelColor

func (dc *Context) SetPixelColor(c color.Color, x, y int)

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

func (*Context) SetStrokeColor

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

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

func (*Context) SetStrokeStyle

func (dc *Context) SetStrokeStyle(pattern gg.Pattern)

SetStrokeStyle sets current stroke style

func (*Context) SetStrokeWeight

func (dc *Context) SetStrokeWeight(lineWidth float64)

SetStrokeWeight sets the lineWidth.

func (*Context) Stroke

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) StrokeWeight

func (dc *Context) StrokeWeight() float64

StrokeWeight returns the current line width

func (*Context) TransformPoint

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

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

Translate updates the current matrix with a translation.

func (*Context) Width

func (dc *Context) Width() float64

Width returns the width of the image in pixels.

type Point

type Point struct {
	X, Y float64
}

Point holds a coordinates pair

func CubicBezier

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

CubicBezier returns points for a cubic bezier curve

func QuadraticBezier

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

QuadraticBezier returns points for a quadratic bezier curve

func (Point) Distance

func (a Point) Distance(b Point) float64

Distance returns the distance from another point

func (Point) Fixed

func (a Point) Fixed() fixed.Point26_6

Fixed returns a fixed-point coordinate pair

func (Point) Interpolate

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

Interpolate returns a new interpolated point

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL