canvas2d

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for js/wasm

Overview

Package canvas2d plays NSGo's drawings into a canvas's 2D context over syscall/js: a browser's <canvas> on the web, and a WeChat mini program's offscreen canvas, which has the same context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadTexture

func ReadTexture(canvas, img js.Value, density float64) (tex canvasmesh.Texture)

ReadTexture snapshots a native image's premultiplied pixels. Canvas security rules may prevent reading an image loaded from another origin.

func WritePixels

func WritePixels(canvas js.Value, pix *image.RGBA) bool

WritePixels replaces canvas with pix, converting premultiplied RGBA to the straight alpha of ImageData. It reports false for a context without ImageData, as some mini program runtimes' are.

Types

type Player

type Player struct {
	Ctx     js.Value
	Drawing *driver.Drawing
	// Ratio is the canvas's pixels per point, and Size its diagonal in
	// points, which repeating gradients cover.
	Ratio, Size float64
	// OriginX and OriginY shift the drawing space when the <canvas> holds only a visible sub-rectangle of a larger canvas.
	OriginX, OriginY float64
	// Font is the context's font shorthand of a font.
	Font func(driver.Font) string
	// Image returns the loaded image an op draws and its pixels per
	// point; false while it loads, when the op draws nothing.
	Image func(driver.ImageSource, bool) (img js.Value, density float64, ok bool)
	// NewCanvas creates a scratch canvas for tinting.
	NewCanvas func(width, height int) js.Value
	// Texture supplies a mesh's loaded pixels. MeshCanvas supplies a
	// scratch canvas for native 2D composition.
	Texture    func(driver.ImageSource) canvasmesh.Texture
	MeshCanvas func() js.Value
	// Shade draws an op that shades with a program, a DrawShader or an
	// image op under SetShader, reporting whether it did; nil, or a false
	// report, leaves a DrawShader out and draws an image op plain.
	Shade func(op *driver.DrawOp) bool
	// contains filtered or unexported fields
}

Player plays a drawing into a 2D context, which draws as NSGo's: the context already does what the ops say, so most map one to one.

func NewPlayer

func NewPlayer(ctx js.Value, ratio, size float64) *Player

NewPlayer returns a player into ctx, whose canvas has ratio pixels per point and a diagonal of size points.

func (*Player) Depth

func (p *Player) Depth() int

Depth is how many saves the ops played so far left unrestored.

func (*Player) Play

func (p *Player) Play(op *driver.DrawOp)

Play plays op.

Jump to

Keyboard shortcuts

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