draw2dbase

package
v0.0.0-...-675e82c Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

README

draw2d/draw2dbase

Coverage GoDoc

Base package implementation that is used by pdf, svg, img, gl implementations.

Documentation

Index

Constants

View Source
const (
	// CurveRecursionLimit represents the maximum recursion that is really necessary to subsivide a curve into straight lines
	CurveRecursionLimit = 32
)

Variables

View Source
var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal}

Functions

func Bresenham

func Bresenham(img draw.Image, color color.Color, x0, y0, x1, y1 int)

Bresenham draws a line between (x0, y0) and (x1, y1)

func Flatten

func Flatten(path *draw2d.Path, flattener Flattener, scale float64)

Flatten convert curves into straight segments keeping join segments info

func PolylineBresenham

func PolylineBresenham(img draw.Image, c color.Color, s ...float64)

PolylineBresenham draws a polyline to an image

func SubdivideCubic

func SubdivideCubic(c, c1, c2 []float64)

SubdivideCubic a Bezier cubic curve in 2 equivalents Bezier cubic curves. c1 and c2 parameters are the resulting curves length of c, c1 and c2 must be 8 otherwise it panics.

func SubdivideQuad

func SubdivideQuad(c, c1, c2 []float64)

SubdivideQuad a Bezier quad curve in 2 equivalents Bezier quad curves. c1 and c2 parameters are the resulting curves length of c, c1 and c2 must be 6 otherwise it panics.

func TraceArc

func TraceArc(t Liner, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64)

TraceArc trace an arc using a Liner

func TraceCubic

func TraceCubic(t Liner, cubic []float64, flatteningThreshold float64) error

TraceCubic generate lines subdividing the cubic curve using a Liner flattening_threshold helps determines the flattening expectation of the curve

func TraceQuad

func TraceQuad(t Liner, quad []float64, flatteningThreshold float64) error

TraceQuad generate lines subdividing the curve using a Liner flattening_threshold helps determines the flattening expectation of the curve

Types

type ContextStack

type ContextStack struct {
	Tr          draw2d.Matrix
	Path        *draw2d.Path
	LineWidth   float64
	Dash        []float64
	DashOffset  float64
	StrokeColor color.Color
	FillColor   color.Color
	FillRule    draw2d.FillRule
	Cap         draw2d.LineCap
	Join        draw2d.LineJoin
	FontSize    float64
	FontData    draw2d.FontData

	Font *truetype.Font
	// fontSize and dpi are used to calculate scale. scale is the number of
	// 26.6 fixed point units in 1 em.
	Scale float64

	Previous *ContextStack
}

func (*ContextStack) GetFontName

func (cs *ContextStack) GetFontName() string

GetFontName gets the current FontData with fontSize as a string

type DashVertexConverter

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

func NewDashConverter

func NewDashConverter(dash []float64, dashOffset float64, flattener Flattener) *DashVertexConverter

func (*DashVertexConverter) Close

func (dasher *DashVertexConverter) Close()

func (*DashVertexConverter) End

func (dasher *DashVertexConverter) End()

func (*DashVertexConverter) LineJoin

func (dasher *DashVertexConverter) LineJoin()

func (*DashVertexConverter) LineTo

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

func (*DashVertexConverter) MoveTo

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

type DemuxFlattener

type DemuxFlattener struct {
	Flatteners []Flattener
}

func (DemuxFlattener) Close

func (dc DemuxFlattener) Close()

func (DemuxFlattener) End

func (dc DemuxFlattener) End()

func (DemuxFlattener) LineJoin

func (dc DemuxFlattener) LineJoin()

func (DemuxFlattener) LineTo

func (dc DemuxFlattener) LineTo(x, y float64)

func (DemuxFlattener) MoveTo

func (dc DemuxFlattener) MoveTo(x, y float64)

type Flattener

type Flattener interface {
	// MoveTo Start a New line from the point (x, y)
	MoveTo(x, y float64)
	// LineTo Draw a line from the current position to the point (x, y)
	LineTo(x, y float64)
	// LineJoin use Round, Bevel or miter to join points
	LineJoin()
	// Close add the most recent starting point to close the path to create a polygon
	Close()
	// End mark the current line as finished so we can draw caps
	End()
}

Flattener receive segment definition

type Glyph

type Glyph struct {
	// path represents a glyph, it is always at (0, 0)
	Path *draw2d.Path
	// Width of the glyph
	Width float64
}

Glyph represents a rune which has been converted to a Path and width

func (*Glyph) Copy

func (g *Glyph) Copy() *Glyph

Copy Returns a copy of a Glyph

func (*Glyph) Fill

func (g *Glyph) Fill(gc draw2d.GraphicContext, x, y float64) float64

Fill copies a glyph from the cache, and fills it

func (*Glyph) Stroke

func (g *Glyph) Stroke(gc draw2d.GraphicContext, x, y float64) float64

Stroke fetches a glyph from the cache, and strokes it

type GlyphCache

type GlyphCache interface {
	// Fetch fetches a glyph from the cache, storing with Render first if it doesn't already exist
	Fetch(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph
}

GlyphCache manage a cache of glyphs

type GlyphCacheImp

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

GlyphCacheImp manage a map of glyphs without sync mecanism, not thread safe

func NewGlyphCache

func NewGlyphCache() *GlyphCacheImp

NewGlyphCache initializes a GlyphCache

func (*GlyphCacheImp) Fetch

func (glyphCache *GlyphCacheImp) Fetch(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph

Fetch fetches a glyph from the cache, calling renderGlyph first if it doesn't already exist

type LineStroker

type LineStroker struct {
	Flattener     Flattener
	HalfLineWidth float64
	Cap           draw2d.LineCap
	Join          draw2d.LineJoin
	// contains filtered or unexported fields
}

func NewLineStroker

func NewLineStroker(c draw2d.LineCap, j draw2d.LineJoin, flattener Flattener) *LineStroker

func (*LineStroker) Close

func (l *LineStroker) Close()

func (*LineStroker) End

func (l *LineStroker) End()

func (*LineStroker) LineJoin

func (l *LineStroker) LineJoin()

func (*LineStroker) LineTo

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

func (*LineStroker) MoveTo

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

type Liner

type Liner interface {
	// LineTo Draw a line from the current position to the point (x, y)
	LineTo(x, y float64)
}

Liner receive segment definition

type SegmentedPath

type SegmentedPath struct {
	Points []float64
}

func (*SegmentedPath) Close

func (p *SegmentedPath) Close()

func (*SegmentedPath) End

func (p *SegmentedPath) End()

func (*SegmentedPath) LineJoin

func (p *SegmentedPath) LineJoin()

func (*SegmentedPath) LineTo

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

func (*SegmentedPath) MoveTo

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

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 draw2d.Matrix)

func (*StackGraphicContext) CubicCurveTo

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

func (*StackGraphicContext) GetFontData

func (gc *StackGraphicContext) GetFontData() draw2d.FontData

func (*StackGraphicContext) GetFontName

func (gc *StackGraphicContext) GetFontName() string

func (*StackGraphicContext) GetFontSize

func (gc *StackGraphicContext) GetFontSize() float64

func (*StackGraphicContext) GetMatrixTransform

func (gc *StackGraphicContext) GetMatrixTransform() draw2d.Matrix

func (*StackGraphicContext) GetPath

func (gc *StackGraphicContext) GetPath() draw2d.Path

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) 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 draw2d.FillRule)

func (*StackGraphicContext) SetFontData

func (gc *StackGraphicContext) SetFontData(fontData draw2d.FontData)

func (*StackGraphicContext) SetFontSize

func (gc *StackGraphicContext) SetFontSize(fontSize float64)

func (*StackGraphicContext) SetLineCap

func (gc *StackGraphicContext) SetLineCap(cap draw2d.LineCap)

func (*StackGraphicContext) SetLineDash

func (gc *StackGraphicContext) SetLineDash(dash []float64, dashOffset float64)

func (*StackGraphicContext) SetLineJoin

func (gc *StackGraphicContext) SetLineJoin(join draw2d.LineJoin)

func (*StackGraphicContext) SetLineWidth

func (gc *StackGraphicContext) SetLineWidth(lineWidth float64)

func (*StackGraphicContext) SetMatrixTransform

func (gc *StackGraphicContext) SetMatrixTransform(Tr draw2d.Matrix)

func (*StackGraphicContext) SetStrokeColor

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

func (*StackGraphicContext) Translate

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

type Transformer

type Transformer struct {
	Tr        draw2d.Matrix
	Flattener Flattener
}

Transformer apply the Matrix transformation tr

func (Transformer) Close

func (t Transformer) Close()

func (Transformer) End

func (t Transformer) End()

func (Transformer) LineJoin

func (t Transformer) LineJoin()

func (Transformer) LineTo

func (t Transformer) LineTo(x, y float64)

func (Transformer) MoveTo

func (t Transformer) MoveTo(x, y float64)

Jump to

Keyboard shortcuts

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