draw2d

package
v0.0.0-...-90b7190 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2015 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

The package draw2d provide a Graphic Context that can draw vectorial figure on surface.

Index

Constants

View Source
const M = 1<<16 - 1

Variables

View Source
var (
	CurveRecursionLimit        = 32
	CurveCollinearityEpsilon   = 1e-30
	CurveAngleToleranceEpsilon = 0.01
)

Functions

func Circle

func Circle(path Path, cx, cy, radius float64)

func DrawImage

func DrawImage(src image.Image, dest draw.Image, tr MatrixTransform, op draw.Op, filter ImageFilter)

func Ellipse

func Ellipse(path Path, cx, cy, rx, ry float64)

func GetFont

func GetFont(fontData FontData) *truetype.Font

func GetFontFolder

func GetFontFolder() string

func Rect

func Rect(path Path, x1, y1, x2, y2 float64)

func RegisterFont

func RegisterFont(fontData FontData, font *truetype.Font)

func RoundRect

func RoundRect(path Path, x1, y1, x2, y2, arcWidth, arcHeight float64)

func SetFontFolder

func SetFontFolder(folder string)

Types

type Cap

type Cap int
const (
	RoundCap Cap = iota
	ButtCap
	SquareCap
)

func (Cap) Convert

func (c Cap) Convert() raster.Capper

type ContextStack

type ContextStack struct {
	Tr          MatrixTransform
	Path        *PathStorage
	LineWidth   float64
	Dash        []float64
	DashOffset  float64
	StrokeColor color.Color
	FillColor   color.Color
	FillRule    FillRule
	Cap         Cap
	Join        Join
	FontSize    float64
	FontData    FontData
	// contains filtered or unexported fields
}

type DashVertexConverter

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

func NewDashConverter

func NewDashConverter(dash []float64, dashOffset float64, converter VertexConverter) *DashVertexConverter

func (*DashVertexConverter) NextCommand

func (dasher *DashVertexConverter) NextCommand(cmd VertexCommand)

func (*DashVertexConverter) Vertex

func (dasher *DashVertexConverter) Vertex(x, y float64)

type DemuxConverter

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

func NewDemuxConverter

func NewDemuxConverter(converters ...VertexConverter) *DemuxConverter

func (*DemuxConverter) NextCommand

func (dc *DemuxConverter) NextCommand(cmd VertexCommand)

func (*DemuxConverter) Vertex

func (dc *DemuxConverter) Vertex(x, y float64)

type FillRule

type FillRule int
const (
	FillRuleEvenOdd FillRule = iota
	FillRuleWinding
)

func (FillRule) UseNonZeroWinding

func (f FillRule) UseNonZeroWinding() bool

type FontData

type FontData struct {
	Name   string
	Family FontFamily
	Style  FontStyle
}

type FontFamily

type FontFamily byte
const (
	FontFamilySans FontFamily = iota
	FontFamilySerif
	FontFamilyMono
)

type FontStyle

type FontStyle byte
const (
	FontStyleNormal FontStyle = iota
	FontStyleBold
	FontStyleItalic
)

type GraphicContext

type GraphicContext interface {
	Path
	// Create a new path
	BeginPath()
	GetMatrixTransform() MatrixTransform
	SetMatrixTransform(tr MatrixTransform)
	ComposeMatrixTransform(tr MatrixTransform)
	Rotate(angle float64)
	Translate(tx, ty float64)
	Scale(sx, sy float64)
	SetStrokeColor(c color.Color)
	SetFillColor(c color.Color)
	SetFillRule(f FillRule)
	SetLineWidth(lineWidth float64)
	SetLineCap(cap Cap)
	SetLineJoin(join Join)
	SetLineDash(dash []float64, dashOffset float64)
	SetFontSize(fontSize float64)
	GetFontSize() float64
	SetFontData(fontData FontData)
	GetFontData() FontData
	DrawImage(image image.Image)
	Save()
	Restore()
	Clear()
	ClearRect(x1, y1, x2, y2 int)
	SetDPI(dpi int)
	GetDPI() int
	GetStringBounds(s string) (left, top, right, bottom float64)
	CreateStringPath(text string, x, y float64) (cursor float64)
	FillString(text string) (cursor float64)
	FillStringAt(text string, x, y float64) (cursor float64)
	StrokeString(text string) (cursor float64)
	StrokeStringAt(text string, x, y float64) (cursor float64)
	Stroke(paths ...*PathStorage)
	Fill(paths ...*PathStorage)
	FillStroke(paths ...*PathStorage)
}

type ImageFilter

type ImageFilter int
const (
	LinearFilter ImageFilter = iota
	BilinearFilter
	BicubicFilter
)

type ImageGraphicContext

type ImageGraphicContext struct {
	*StackGraphicContext

	DPI int
	// contains filtered or unexported fields
}

func NewGraphicContext

func NewGraphicContext(img draw.Image) *ImageGraphicContext

*

  • Create a new Graphic context from an image

func NewGraphicContextWithPainter

func NewGraphicContextWithPainter(img draw.Image, painter Painter) *ImageGraphicContext

Create a new Graphic context from an image and a Painter (see Freetype-go)

func (*ImageGraphicContext) Clear

func (gc *ImageGraphicContext) Clear()

func (*ImageGraphicContext) ClearRect

func (gc *ImageGraphicContext) ClearRect(x1, y1, x2, y2 int)

func (*ImageGraphicContext) CreateStringPath

func (gc *ImageGraphicContext) CreateStringPath(s string, x, y float64) float64

CreateStringPath creates a path from the string s at x, y, and returns the string width. The text is placed so that the left edge of the em square of the first character of s and the baseline intersect at x, y. 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.

func (*ImageGraphicContext) DrawImage

func (gc *ImageGraphicContext) DrawImage(img image.Image)

func (*ImageGraphicContext) Fill

func (gc *ImageGraphicContext) Fill(paths ...*PathStorage)

*** second method ***

func (*ImageGraphicContext) FillString

func (gc *ImageGraphicContext) FillString(text string) (cursor float64)

func (*ImageGraphicContext) FillStringAt

func (gc *ImageGraphicContext) FillStringAt(text string, x, y float64) (cursor float64)

func (*ImageGraphicContext) FillStroke

func (gc *ImageGraphicContext) FillStroke(paths ...*PathStorage)

second method

func (*ImageGraphicContext) GetDPI

func (gc *ImageGraphicContext) GetDPI() int

func (*ImageGraphicContext) GetStringBounds

func (gc *ImageGraphicContext) GetStringBounds(s string) (left, top, right, bottom float64)

GetStringBounds returns the approximate pixel bounds of the string s at x, y. The the left edge of the em square of the first character of s and the baseline intersect at 0, 0 in the returned coordinates. Therefore the top and left coordinates may well be negative.

func (*ImageGraphicContext) SetDPI

func (gc *ImageGraphicContext) SetDPI(dpi int)

SetDPI sets the screen resolution in dots per inch.

func (*ImageGraphicContext) SetFont

func (gc *ImageGraphicContext) SetFont(font *truetype.Font)

SetFont sets the font used to draw text.

func (*ImageGraphicContext) SetFontSize

func (gc *ImageGraphicContext) SetFontSize(fontSize float64)

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

func (*ImageGraphicContext) Stroke

func (gc *ImageGraphicContext) Stroke(paths ...*PathStorage)

*** second method ***

func (*ImageGraphicContext) StrokeString

func (gc *ImageGraphicContext) StrokeString(text string) (cursor float64)

func (*ImageGraphicContext) StrokeStringAt

func (gc *ImageGraphicContext) StrokeStringAt(text string, x, y float64) (cursor float64)

type Join

type Join int
const (
	BevelJoin Join = iota
	RoundJoin
	MiterJoin
)

func (Join) Convert

func (j Join) Convert() raster.Joiner

type LineStroker

type LineStroker struct {
	Next          VertexConverter
	HalfLineWidth float64
	Cap           Cap
	Join          Join
	// contains filtered or unexported fields
}

func NewLineStroker

func NewLineStroker(c Cap, j Join, converter VertexConverter) *LineStroker

func (*LineStroker) NextCommand

func (l *LineStroker) NextCommand(command VertexCommand)

func (*LineStroker) Vertex

func (l *LineStroker) Vertex(x, y float64)

type MatrixTransform

type MatrixTransform [6]float64

func NewIdentityMatrix

func NewIdentityMatrix() MatrixTransform

* Creates an identity transformation.

func NewMatrixTransform

func NewMatrixTransform(rectangle1, rectangle2 [4]float64) MatrixTransform

*

  • Creates a transformation, combining a scale and a translation, that transform rectangle1 into rectangle2.

func NewRotationMatrix

func NewRotationMatrix(angle float64) MatrixTransform

*

  • Creates a rotation transformation.

func NewScaleMatrix

func NewScaleMatrix(sx, sy float64) MatrixTransform

*

  • Creates a transformation with a sx, sy scale factor

func NewTranslationMatrix

func NewTranslationMatrix(tx, ty float64) MatrixTransform

*

  • Creates a transformation with a translation, that,
  • transform point1 into point2.

func (MatrixTransform) Determinant

func (tr MatrixTransform) Determinant() float64

func (MatrixTransform) Equals

func (tr1 MatrixTransform) Equals(tr2 MatrixTransform) bool

*

  • Tests if a two transformation are equal. A tolerance is applied when
  • comparing matrix elements.

func (MatrixTransform) GetInverseTransformation

func (tr MatrixTransform) GetInverseTransformation() MatrixTransform

*

  • Returns a transformation that is the inverse of the given transformation.

func (MatrixTransform) GetMaxAbsScaling

func (tr MatrixTransform) GetMaxAbsScaling() (s float64)

func (MatrixTransform) GetMinAbsScaling

func (tr MatrixTransform) GetMinAbsScaling() (s float64)

func (MatrixTransform) GetScale

func (tr MatrixTransform) GetScale() float64

func (MatrixTransform) GetScaling

func (tr MatrixTransform) GetScaling() (x, y float64)

func (MatrixTransform) GetTranslation

func (tr MatrixTransform) GetTranslation() (x, y float64)

func (MatrixTransform) InverseTransform

func (tr MatrixTransform) InverseTransform(points ...*float64)

func (MatrixTransform) IsIdentity

func (tr MatrixTransform) IsIdentity() bool

*

  • Tests if a transformation is the identity transformation. A tolerance
  • is applied when comparing matrix elements.

func (MatrixTransform) IsTranslation

func (tr MatrixTransform) IsTranslation() bool

*

  • Tests if a transformation is is a pure translation. A tolerance
  • is applied when comparing matrix elements.

func (MatrixTransform) Multiply

func (*MatrixTransform) Rotate

func (tr *MatrixTransform) Rotate(angle float64) *MatrixTransform

func (*MatrixTransform) Scale

func (tr *MatrixTransform) Scale(sx, sy float64) *MatrixTransform

func (MatrixTransform) Transform

func (tr MatrixTransform) Transform(points ...*float64)

func (MatrixTransform) TransformArray

func (tr MatrixTransform) TransformArray(points []float64)

func (MatrixTransform) TransformRasterPoint

func (tr MatrixTransform) TransformRasterPoint(points ...*raster.Point)

func (MatrixTransform) TransformRectangle

func (tr MatrixTransform) TransformRectangle(x0, y0, x2, y2 *float64)

func (*MatrixTransform) Translate

func (tr *MatrixTransform) Translate(tx, ty float64) *MatrixTransform

func (MatrixTransform) VectorTransform

func (tr MatrixTransform) VectorTransform(points ...*float64)

type MatrixTransformAdder

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

this adder apply a Matrix transformation to points

func NewMatrixTransformAdder

func NewMatrixTransformAdder(tr MatrixTransform, adder raster.Adder) *MatrixTransformAdder

func (MatrixTransformAdder) Add1

func (mta MatrixTransformAdder) Add1(b raster.Point)

Add1 adds a linear segment to the current curve.

func (MatrixTransformAdder) Add2

func (mta MatrixTransformAdder) Add2(b, c raster.Point)

Add2 adds a quadratic segment to the current curve.

func (MatrixTransformAdder) Add3

func (mta MatrixTransformAdder) Add3(b, c, d raster.Point)

Add3 adds a cubic segment to the current curve.

func (MatrixTransformAdder) Start

func (mta MatrixTransformAdder) Start(a raster.Point)

Start starts a new curve at the given point.

type Painter

type Painter interface {
	raster.Painter
	SetColor(color color.Color)
}

type Path

type Path interface {
	// Return the current point of the path
	LastPoint() (x, y float64)
	// Create a new subpath that start at the specified point
	MoveTo(x, y float64)
	// Create a new subpath that start at the specified point
	// relative to the current point
	RMoveTo(dx, dy float64)
	// Add a line to the current subpath
	LineTo(x, y float64)
	// Add a line to the current subpath
	// relative to the current point
	RLineTo(dx, dy float64)

	QuadCurveTo(cx, cy, x, y float64)
	RQuadCurveTo(dcx, dcy, dx, dy float64)
	CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)
	RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64)
	ArcTo(cx, cy, rx, ry, startAngle, angle float64)
	RArcTo(dcx, dcy, rx, ry, startAngle, angle float64)
	Close()
}

type PathAdder

type PathAdder struct {
	ApproximationScale float64
	// contains filtered or unexported fields
}

func NewPathAdder

func NewPathAdder(adder raster.Adder) *PathAdder

func (*PathAdder) Convert

func (pathAdder *PathAdder) Convert(paths ...*PathStorage)

type PathCmd

type PathCmd int
const (
	MoveTo PathCmd = iota
	LineTo
	QuadCurveTo
	CubicCurveTo
	ArcTo
	Close
)

type PathConverter

type PathConverter struct {
	ApproximationScale, AngleTolerance, CuspLimit float64
	// contains filtered or unexported fields
}

func NewPathConverter

func NewPathConverter(converter VertexConverter) *PathConverter

func (*PathConverter) ArcTo

func (c *PathConverter) ArcTo(cx, cy, rx, ry, startAngle, angle float64) *PathConverter

func (*PathConverter) Close

func (c *PathConverter) Close() *PathConverter

func (*PathConverter) Convert

func (c *PathConverter) Convert(paths ...*PathStorage)

func (*PathConverter) ConvertCommand

func (c *PathConverter) ConvertCommand(cmd PathCmd, vertices ...float64) int

func (*PathConverter) CubicCurveTo

func (c *PathConverter) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) *PathConverter

func (*PathConverter) LineTo

func (c *PathConverter) LineTo(x, y float64) *PathConverter

func (*PathConverter) MoveTo

func (c *PathConverter) MoveTo(x, y float64) *PathConverter

func (*PathConverter) QuadCurveTo

func (c *PathConverter) QuadCurveTo(cx, cy, x, y float64) *PathConverter

func (*PathConverter) RArcTo

func (c *PathConverter) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) *PathConverter

func (*PathConverter) RCubicCurveTo

func (c *PathConverter) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) *PathConverter

func (*PathConverter) RLineTo

func (c *PathConverter) RLineTo(dx, dy float64) *PathConverter

func (*PathConverter) RMoveTo

func (c *PathConverter) RMoveTo(dx, dy float64) *PathConverter

func (*PathConverter) RQuadCurveTo

func (c *PathConverter) RQuadCurveTo(dcx, dcy, dx, dy float64) *PathConverter

type PathStorage

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

func NewPathStorage

func NewPathStorage() (p *PathStorage)

func (*PathStorage) ArcTo

func (p *PathStorage) ArcTo(cx, cy, rx, ry, startAngle, angle float64) *PathStorage

func (*PathStorage) Clear

func (p *PathStorage) Clear()

func (*PathStorage) Close

func (p *PathStorage) Close() *PathStorage

func (*PathStorage) Copy

func (src *PathStorage) Copy() (dest *PathStorage)

func (*PathStorage) CubicCurveTo

func (p *PathStorage) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) *PathStorage

func (*PathStorage) IsEmpty

func (p *PathStorage) IsEmpty() bool

func (*PathStorage) LastPoint

func (p *PathStorage) LastPoint() (x, y float64)

func (*PathStorage) LineTo

func (p *PathStorage) LineTo(x, y float64) *PathStorage

func (*PathStorage) MoveTo

func (p *PathStorage) MoveTo(x, y float64) *PathStorage

func (*PathStorage) QuadCurveTo

func (p *PathStorage) QuadCurveTo(cx, cy, x, y float64) *PathStorage

func (*PathStorage) RArcTo

func (p *PathStorage) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64) *PathStorage

func (*PathStorage) RCubicCurveTo

func (p *PathStorage) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64) *PathStorage

func (*PathStorage) RLineTo

func (p *PathStorage) RLineTo(dx, dy float64) *PathStorage

func (*PathStorage) RMoveTo

func (p *PathStorage) RMoveTo(dx, dy float64) *PathStorage

func (*PathStorage) RQuadCurveTo

func (p *PathStorage) RQuadCurveTo(dcx, dcy, dx, dy float64) *PathStorage

func (*PathStorage) String

func (p *PathStorage) String() string

type StackGraphicContext

type StackGraphicContext struct {
	Current *ContextStack
}

func NewStackGraphicContext

func NewStackGraphicContext() *StackGraphicContext

*

  • Create a new Graphic context from an image

func (*StackGraphicContext) ArcTo

func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, angle float64)

func (*StackGraphicContext) BeginPath

func (gc *StackGraphicContext) BeginPath()

func (*StackGraphicContext) Close

func (gc *StackGraphicContext) Close()

func (*StackGraphicContext) ComposeMatrixTransform

func (gc *StackGraphicContext) ComposeMatrixTransform(Tr MatrixTransform)

func (*StackGraphicContext) CubicCurveTo

func (gc *StackGraphicContext) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)

func (*StackGraphicContext) GetFontData

func (gc *StackGraphicContext) GetFontData() FontData

func (*StackGraphicContext) GetFontSize

func (gc *StackGraphicContext) GetFontSize() float64

func (*StackGraphicContext) GetMatrixTransform

func (gc *StackGraphicContext) GetMatrixTransform() MatrixTransform

func (*StackGraphicContext) IsEmpty

func (gc *StackGraphicContext) IsEmpty() bool

func (*StackGraphicContext) LastPoint

func (gc *StackGraphicContext) LastPoint() (float64, float64)

func (*StackGraphicContext) LineTo

func (gc *StackGraphicContext) LineTo(x, y float64)

func (*StackGraphicContext) MoveTo

func (gc *StackGraphicContext) MoveTo(x, y float64)

func (*StackGraphicContext) QuadCurveTo

func (gc *StackGraphicContext) QuadCurveTo(cx, cy, x, y float64)

func (*StackGraphicContext) RArcTo

func (gc *StackGraphicContext) RArcTo(dcx, dcy, rx, ry, startAngle, angle float64)

func (*StackGraphicContext) RCubicCurveTo

func (gc *StackGraphicContext) RCubicCurveTo(dcx1, dcy1, dcx2, dcy2, dx, dy float64)

func (*StackGraphicContext) RLineTo

func (gc *StackGraphicContext) RLineTo(dx, dy float64)

func (*StackGraphicContext) RMoveTo

func (gc *StackGraphicContext) RMoveTo(dx, dy float64)

func (*StackGraphicContext) RQuadCurveTo

func (gc *StackGraphicContext) RQuadCurveTo(dcx, dcy, dx, dy float64)

func (*StackGraphicContext) Restore

func (gc *StackGraphicContext) Restore()

func (*StackGraphicContext) Rotate

func (gc *StackGraphicContext) Rotate(angle float64)

func (*StackGraphicContext) Save

func (gc *StackGraphicContext) Save()

func (*StackGraphicContext) Scale

func (gc *StackGraphicContext) Scale(sx, sy float64)

func (*StackGraphicContext) SetFillColor

func (gc *StackGraphicContext) SetFillColor(c color.Color)

func (*StackGraphicContext) SetFillRule

func (gc *StackGraphicContext) SetFillRule(f FillRule)

func (*StackGraphicContext) SetFontData

func (gc *StackGraphicContext) SetFontData(FontData FontData)

func (*StackGraphicContext) SetFontSize

func (gc *StackGraphicContext) SetFontSize(FontSize float64)

func (*StackGraphicContext) SetLineCap

func (gc *StackGraphicContext) SetLineCap(Cap Cap)

func (*StackGraphicContext) SetLineDash

func (gc *StackGraphicContext) SetLineDash(Dash []float64, DashOffset float64)

func (*StackGraphicContext) SetLineJoin

func (gc *StackGraphicContext) SetLineJoin(Join Join)

func (*StackGraphicContext) SetLineWidth

func (gc *StackGraphicContext) SetLineWidth(LineWidth float64)

func (*StackGraphicContext) SetMatrixTransform

func (gc *StackGraphicContext) SetMatrixTransform(Tr MatrixTransform)

func (*StackGraphicContext) SetStrokeColor

func (gc *StackGraphicContext) SetStrokeColor(c color.Color)

func (*StackGraphicContext) Translate

func (gc *StackGraphicContext) Translate(tx, ty float64)

type VertexAdder

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

func NewVertexAdder

func NewVertexAdder(adder raster.Adder) *VertexAdder

func (*VertexAdder) NextCommand

func (vertexAdder *VertexAdder) NextCommand(cmd VertexCommand)

func (*VertexAdder) Vertex

func (vertexAdder *VertexAdder) Vertex(x, y float64)

type VertexCommand

type VertexCommand byte
const (
	VertexNoCommand VertexCommand = iota
	VertexStartCommand
	VertexJoinCommand
	VertexCloseCommand
	VertexStopCommand
)

type VertexConverter

type VertexConverter interface {
	NextCommand(cmd VertexCommand)
	Vertex(x, y float64)
}

type VertexMatrixTransform

type VertexMatrixTransform struct {
	Next VertexConverter
	// contains filtered or unexported fields
}

this VertexConverter apply the Matrix transformation tr

func NewVertexMatrixTransform

func NewVertexMatrixTransform(tr MatrixTransform, converter VertexConverter) *VertexMatrixTransform

func (*VertexMatrixTransform) NextCommand

func (vmt *VertexMatrixTransform) NextCommand(command VertexCommand)

Vertex Matrix Transform

func (*VertexMatrixTransform) Vertex

func (vmt *VertexMatrixTransform) Vertex(x, y float64)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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