canvas

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 27 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustImageForColor

func AdjustImageForColor(mask image.Image, width int, height int, col color.Color) image.Image

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func CharPositions

func CharPositions(family string, size float64, bold bool, italic bool, text string) ([]int, error)

func CohenSutherland

func CohenSutherland(x1, y1, x2, y2, left, top, right, bottom int) (int, int, int, int, bool)

func Decode

func Decode(r io.Reader) (image.Image, error)

func DecodeAll

func DecodeAll(r io.Reader) ([]image.Image, error)

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

func Font

func Font(family string, size float64, bold bool, italic bool) (result *truetype.Font, face font.Face, err error)

func MakeFontFace

func MakeFontFace(f *truetype.Font, size float64) font.Face

func MeasureText

func MeasureText(family string, size float64, bold bool, italic bool, text string, multiline bool) (int, int, error)

func MeasureTextFreeType

func MeasureTextFreeType(family string, size float64, bold bool, italic bool, text string, multiline bool) (int, int, error)

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func ParseFont

func ParseFont(b []byte) (*truetype.Font, error)

ParseFont just calls the Parse function from the freetype/truetype package. It is provided here so that code that imports this package doesn't need to also include the freetype/truetype package.

func Pt

func Pt(x, y int) fixed.Point26_6

Pt converts from a co-ordinate pair measured in pixels to a fixed.Point26_6 co-ordinate pair measured in fixed.Int26_6 units.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type CanvasDirect

type CanvasDirect struct {
	stats.Obj
	// contains filtered or unexported fields
}

func NewCanvas

func NewCanvas(width int, height int) *CanvasDirect

func NewCanvasWindow

func NewCanvasWindow(width int, height int) *CanvasDirect

func (*CanvasDirect) ClipIn

func (c *CanvasDirect) ClipIn(x, y, width, height int)

func (*CanvasDirect) ClipInTranslated

func (c *CanvasDirect) ClipInTranslated(x, y, width, height int)

func (*CanvasDirect) ClippedRegion

func (c *CanvasDirect) ClippedRegion() (int, int, int, int)

func (*CanvasDirect) DrawImage

func (c *CanvasDirect) DrawImage(x int, y int, img image.Image)

func (*CanvasDirect) DrawLine

func (c *CanvasDirect) DrawLine(x1 int, y1 int, x2 int, y2 int, width int, color color.Color)

func (*CanvasDirect) DrawPoint

func (c *CanvasDirect) DrawPoint(x int, y int, color color.Color)

func (*CanvasDirect) DrawRect

func (c *CanvasDirect) DrawRect(x int, y int, width int, height int, color color.Color, strokeWidth int)

func (*CanvasDirect) DrawText

func (c *CanvasDirect) DrawText(x int, y int, text string, fontFamily string, fontSize float64, colr color.Color, underline bool)

func (*CanvasDirect) DrawTextMultiline

func (c *CanvasDirect) DrawTextMultiline(x int, y int, width int, height int, hAlign HAlign, vAlign VAlign, text string, colr color.Color, fontFamily string, fontSize float64, underline bool)

func (*CanvasDirect) FillEntire

func (c *CanvasDirect) FillEntire(colr color.Color)

func (*CanvasDirect) FillRect

func (c *CanvasDirect) FillRect(x int, y int, width int, height int, colr color.Color)

func (*CanvasDirect) Image

func (c *CanvasDirect) Image() *image.RGBA

func (*CanvasDirect) Load

func (c *CanvasDirect) Load()

func (*CanvasDirect) MakeScriptLine

func (c *CanvasDirect) MakeScriptLine(x1, y1, x2, y2, width float64) *DrawScript

func (*CanvasDirect) MakeScriptLineBresenham

func (c *CanvasDirect) MakeScriptLineBresenham(x1 float64, y1 float64, x2 float64, y2 float64) *DrawScript

func (*CanvasDirect) MakeScriptLineWu

func (c *CanvasDirect) MakeScriptLineWu(x1, y1, x2, y2 float64) *DrawScript

func (*CanvasDirect) MixPixel

func (c *CanvasDirect) MixPixel(x int, y int, rgba color.Color)

func (*CanvasDirect) Save

func (c *CanvasDirect) Save()

func (*CanvasDirect) State

func (c *CanvasDirect) State() CanvasDirectState

func (*CanvasDirect) Translate

func (c *CanvasDirect) Translate(x, y int)

func (*CanvasDirect) TranslatedX

func (c *CanvasDirect) TranslatedX() int

func (*CanvasDirect) TranslatedY

func (c *CanvasDirect) TranslatedY() int

type CanvasDirectState

type CanvasDirectState struct {
	TranslateX int
	TranslateY int

	ClipX      int
	ClipY      int
	ClipWidth  int
	ClipHeight int
}

func (*CanvasDirectState) String

func (c *CanvasDirectState) String() string

type Context

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

A Context holds the state for drawing text in a given font and size.

func FontContext

func FontContext(family string, size float64, bold bool, italic bool, color color.Color) (*Context, error)

func NewContext

func NewContext() *Context

NewContext creates a new Context.

func (*Context) DrawString

func (c *Context) DrawString(s string, p fixed.Point26_6) (fixed.Point26_6, error)

DrawString draws s at p and returns p advanced by the text extent. The text is placed so that the left edge of the em square of the first character of s and the baseline intersect at p. The majority of the affected pixels will be above and to the right of the point, but some may be below or to the left. For example, drawing a string that starts with a 'J' in an italic font may affect pixels below and left of the point.

p is a fixed.Point26_6 and can therefore represent sub-pixel positions.

func (*Context) PointToFixed

func (c *Context) PointToFixed(x float64) fixed.Int26_6

PointToFixed converts the given number of points (as in "a 12 point font") into a 26.6 fixed point number of pixels.

func (*Context) SetClip

func (c *Context) SetClip(clip image.Rectangle)

SetClip sets the clip rectangle for drawing.

func (*Context) SetDPI

func (c *Context) SetDPI(dpi float64)

SetDPI sets the screen resolution in dots per inch.

func (*Context) SetDst

func (c *Context) SetDst(dst draw.Image)

SetDst sets the destination image for draw operations.

func (*Context) SetFont

func (c *Context) SetFont(f *truetype.Font)

SetFont sets the font used to draw text.

func (*Context) SetFontSize

func (c *Context) SetFontSize(fontSize float64)

SetFontSize sets the font size in points (as in "a 12 point font").

func (*Context) SetHinting

func (c *Context) SetHinting(hinting font.Hinting)

SetHinting sets the hinting policy.

func (*Context) SetSrc

func (c *Context) SetSrc(src image.Image)

SetSrc sets the source image for draw operations. This is typically an image.Uniform.

type DrawScript

type DrawScript struct {
	Bounds image.Rectangle
	// contains filtered or unexported fields
}

func NewDrawScript

func NewDrawScript() *DrawScript

func (*DrawScript) DrawToRGBA

func (c *DrawScript) DrawToRGBA(img *image.RGBA, col color.Color)

func (*DrawScript) MixPixel

func (c *DrawScript) MixPixel(img *image.RGBA, x int, y int, rgba color.Color, intensity uint32)

type DrawScriptHorLine

type DrawScriptHorLine struct {
	X1 int
	X2 int
	Y  int
	C  float64
}

type DrawScriptPoint

type DrawScriptPoint struct {
	X int
	Y int
	C float64
}

type FontInfo

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

type FontMeasureData

type FontMeasureData struct {
	Width  int
	Height int
}

func GetFontMeasureData

func GetFontMeasureData(family string, size float64, bold bool, italic bool, text string, multiline bool) *FontMeasureData

type HAlign

type HAlign int
const HAlignCenter HAlign = 1
const HAlignLeft HAlign = 0
const HAlignRight HAlign = 2

type VAlign

type VAlign int
const VAlignBottom VAlign = 2
const VAlignCenter VAlign = 1
const VAlignTop VAlign = 0

Jump to

Keyboard shortcuts

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