ctx2d

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

View Source
const (
	TextAlignLeft   = "left"
	TextAlignRight  = "right"
	TextAlignCenter = "center"
	TextAlignStart  = "start"
	TextAlignEnd    = "end"

	TextBaselineTop         = "top"
	TextBaselineHanging     = "hanging"
	TextBaselineMiddle      = "middle"
	TextBaselineAlphabetic  = "alphabetic"
	TextBaselineIdeographic = "ideographic"
	TextBaselineBottom      = "bottom"

	DirectionInherit = "inherit"
	DirectionLTR     = "ltr"
	DirectionRTL     = "rtl"

	LineCapButt   = "butt"
	LineCapRound  = "round"
	LineCapSquare = "square"
	LineJoinRound = "round"
	LineJoinBevel = "bevel"
	LineJoinMiter = "miter"

	FillRuleNonZero = "nonzero"
	FillRuleEvenOdd = "evenodd"

	ImageSmoothingQualityLow    = "low"
	ImageSmoothingQualityMedium = "medium"
	ImageSmoothingQualityHigh   = "high"
)
View Source
const ErrorNoContextFound = "failed to get 2D context from canvas"

Variables

This section is empty.

Functions

This section is empty.

Types

type CanvasGradient

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

func (*CanvasGradient) AddColorStop

func (g *CanvasGradient) AddColorStop(offset float64, color string) (gradient *CanvasGradient)

type CanvasPattern

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

func (*CanvasPattern) SetTransform

func (p *CanvasPattern) SetTransform(matrix DOMMatrix) (pattern *CanvasPattern)

type ColorSpace

type ColorSpace string
const (
	ColorSpaceSRGB      ColorSpace = "srgb"
	ColorSpaceDisplayP3 ColorSpace = "display-p3"
)

type Context

type Context struct {

	// Settable properties
	FillStyle                any
	StrokeStyle              any
	LineWidth                float64
	GlobalAlpha              float64
	Font                     string
	Direction                string
	Filter                   string
	FontKerning              string
	FontStretch              string
	FontVariantCaps          string
	GlobalCompositeOperation string
	ImageSmoothingEnabled    bool
	ImageSmoothingQuality    string
	LetterSpacing            string
	LineCap                  string
	LineDashOffset           float64
	LineJoin                 string
	MiterLimit               float64
	ShadowBlur               float64
	ShadowColor              string
	ShadowOffsetX            float64
	ShadowOffsetY            float64
	TextAlign                string
	TextBaseline             string
	TextRendering            string
	WordSpacing              string

	// OnFrame is called by requestAnimationFrame. dt is measured in seconds.
	// The command buffer is submitted automatically when it returns.
	OnFrame func(dt, width, height float64)
	// contains filtered or unexported fields
}

func GetContext

func GetContext(canvas *wasmdraw.CanvasElement, opts *Options) (ctx *Context, err error)

func GetOffscreenContext

func GetOffscreenContext(canvas *wasmdraw.OffscreenCanvas, opts *Options) (ctx *Context, err error)

func (*Context) Arc

func (c *Context) Arc(x, y, radius, startAngle, endAngle float64, counterclockwise ...bool) (self *Context)

func (*Context) ArcTo

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

func (*Context) BeginPath

func (c *Context) BeginPath() (self *Context)

func (*Context) BezierCurveTo

func (c *Context) BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y float64) (self *Context)

func (*Context) ClearRect

func (c *Context) ClearRect(x, y, width, height float64) (self *Context)

func (*Context) Clip

func (c *Context) Clip(fillRule ...string) (self *Context)

Clip intersects the current clipping region with the current path.

func (*Context) ClipPath

func (c *Context) ClipPath(path *path2d.Path2D, fillRule ...string) (self *Context)

ClipPath is the Path2D overload of CanvasRenderingContext2D.clip.

func (*Context) ClosePath

func (c *Context) ClosePath() (self *Context)

func (*Context) CreateConicGradient

func (c *Context) CreateConicGradient(startAngle, x, y float64) (gradient *CanvasGradient)

func (*Context) CreateImageData

func (c *Context) CreateImageData(width, height float64) (imgData *ImageData)

func (*Context) CreateImageDataFrom

func (c *Context) CreateImageDataFrom(image *ImageData) (imgData *ImageData)

func (*Context) CreateLinearGradient

func (c *Context) CreateLinearGradient(x0, y0, x1, y1 float64) (gradient *CanvasGradient)

func (*Context) CreatePattern

func (c *Context) CreatePattern(source wasmdraw.CanvasImageSource, repetition string) (pattern *CanvasPattern, err error)

func (*Context) CreateRadialGradient

func (c *Context) CreateRadialGradient(x0, y0, r0, x1, y1, r1 float64) (gradient *CanvasGradient)

func (*Context) Dispose

func (c *Context) Dispose()

func (*Context) DrawImage

func (c *Context) DrawImage(source wasmdraw.CanvasImageSource, args ...float64) (self *Context)

DrawImage mirrors CanvasRenderingContext2D.drawImage. After the source, valid coordinate counts are 2, 4, and 8.

func (*Context) Ellipse

func (c *Context) Ellipse(x, y, rx, ry, rotation, startAngle, endAngle float64, counterclockwise ...bool) (self *Context)

func (*Context) Fill

func (c *Context) Fill(paths ...*path2d.Path2D) (self *Context)

func (*Context) FillPath

func (c *Context) FillPath(path *path2d.Path2D, fillRule ...string) (self *Context)

func (*Context) FillRect

func (c *Context) FillRect(x, y, width, height float64) (self *Context)

func (*Context) FillText

func (c *Context) FillText(text string, x, y float64, maxWidth ...float64) (self *Context)

func (*Context) FillWithRule

func (c *Context) FillWithRule(fillRule string) (self *Context)

func (*Context) GetContextAttributes

func (c *Context) GetContextAttributes() (attributes ContextAttributes)

func (*Context) GetFPS

func (c *Context) GetFPS() (fps int)

func (*Context) GetImageData

func (c *Context) GetImageData(sx, sy, sw, sh float64) (imgData *ImageData)

func (*Context) GetLineDash

func (c *Context) GetLineDash() (dash []float64)

func (*Context) GetMSPerFrame

func (c *Context) GetMSPerFrame() (mean, min, max float64)

func (*Context) GetTransform

func (c *Context) GetTransform() (matrix DOMMatrix)

func (*Context) IsContextLost

func (c *Context) IsContextLost() (isLost bool)

func (*Context) IsPointInPath

func (c *Context) IsPointInPath(x, y float64, fillRule ...string) (inPath bool)

func (*Context) IsPointInPath2D

func (c *Context) IsPointInPath2D(path *path2d.Path2D, x, y float64, fillRule ...string) (inPath bool)

func (*Context) IsPointInStroke

func (c *Context) IsPointInStroke(x, y float64) (inStroke bool)

func (*Context) IsPointInStrokePath

func (c *Context) IsPointInStrokePath(path *path2d.Path2D, x, y float64) (inStroke bool)

func (*Context) LineTo

func (c *Context) LineTo(x, y float64) (self *Context)

func (*Context) MeasureText

func (c *Context) MeasureText(text string) (metrics TextMetrics)

MeasureText is a synchronization point: queued commands are submitted so the browser measures with the exact current canvas state.

func (*Context) MoveTo

func (c *Context) MoveTo(x, y float64) (self *Context)

func (*Context) PutImageData

func (c *Context) PutImageData(image *ImageData, dx, dy float64, dirty ...float64) (ctx *Context)

func (*Context) QuadraticCurveTo

func (c *Context) QuadraticCurveTo(cpx, cpy, x, y float64) (self *Context)

func (*Context) Rect

func (c *Context) Rect(x, y, width, height float64) (self *Context)

func (*Context) Reset

func (c *Context) Reset() (self *Context)

Reset mirrors context.reset and restores drawing state, transforms, paths, and clipping to their defaults.

func (*Context) ResetTransform

func (c *Context) ResetTransform() (self *Context)

func (*Context) Restore

func (c *Context) Restore() (self *Context)

func (*Context) Rotate

func (c *Context) Rotate(angle float64) (self *Context)

func (*Context) RoundRect

func (c *Context) RoundRect(x, y, width, height, radius float64) (self *Context)

func (*Context) Save

func (c *Context) Save() (self *Context)

func (*Context) Scale

func (c *Context) Scale(x, y float64) (self *Context)

func (*Context) SetLineDash

func (c *Context) SetLineDash(segments []float64) (self *Context)

func (*Context) SetTransform

func (c *Context) SetTransform(a, b, cc, d, e, f float64) (self *Context)

func (*Context) Start

func (c *Context) Start() (self *Context)

func (*Context) Stop

func (c *Context) Stop() (self *Context)

func (*Context) Stroke

func (c *Context) Stroke(paths ...*path2d.Path2D) (self *Context)

func (*Context) StrokeRect

func (c *Context) StrokeRect(x, y, width, height float64) (self *Context)

func (*Context) StrokeText

func (c *Context) StrokeText(text string, x, y float64, maxWidth ...float64) (self *Context)

func (*Context) Transform

func (c *Context) Transform(a, b, cc, d, e, f float64) (self *Context)

func (*Context) Translate

func (c *Context) Translate(x, y float64) (self *Context)

type ContextAttributes

type ContextAttributes struct {
	Alpha, Desynchronized, WillReadFrequently bool
	ColorSpace                                string
}

type DOMMatrix

type DOMMatrix struct {
	A, B, C, D, E, F float64
}

type ImageData

type ImageData struct {
	Width, Height int
	// contains filtered or unexported fields
}

func (*ImageData) Close

func (i *ImageData) Close()

Close releases executor references to this browser-owned pixel buffer.

func (*ImageData) Data

func (i *ImageData) Data() (result []byte)

Data explicitly copies the ImageData pixels into Go memory.

func (*ImageData) SetData

func (i *ImageData) SetData(data []byte) (imgData *ImageData)

type Options

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

func DefaultOptions

func DefaultOptions() (o *Options)

func (*Options) WithAlpha

func (o *Options) WithAlpha(alpha bool) (self *Options)

func (*Options) WithColorSpace

func (o *Options) WithColorSpace(colorSpace ColorSpace) (self *Options)

func (*Options) WithCommandCapacity

func (o *Options) WithCommandCapacity(bytes int) (self *Options)

func (*Options) WithDesynchronized

func (o *Options) WithDesynchronized(desynchronized bool) (self *Options)

func (*Options) WithWillReadFrequently

func (o *Options) WithWillReadFrequently(willReadFrequently bool) (self *Options)

type TextMetrics

type TextMetrics struct {
	Width                    float64
	ActualBoundingBoxLeft    float64
	ActualBoundingBoxRight   float64
	ActualBoundingBoxAscent  float64
	ActualBoundingBoxDescent float64
	FontBoundingBoxAscent    float64
	FontBoundingBoxDescent   float64
	EmHeightAscent           float64
	EmHeightDescent          float64
	HangingBaseline          float64
	AlphabeticBaseline       float64
	IdeographicBaseline      float64
}

Directories

Path Synopsis
example
src command
Package path2d provides retained canvas paths with an API mirroring the browser's Path2D object.
Package path2d provides retained canvas paths with an API mirroring the browser's Path2D object.

Jump to

Keyboard shortcuts

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