Documentation ¶
Index ¶
- Constants
- Variables
- func Bresenham(img draw.Image, color color.Color, x0, y0, x1, y1 int)
- func DrawContour(path draw2d.PathBuilder, ps []truetype.Point, dx, dy float64)
- func Flatten(path *draw2d.Path, flattener Flattener, scale float64)
- func PolylineBresenham(img draw.Image, c color.Color, s ...float64)
- func SubdivideCubic(c, c1, c2 []float64)
- func SubdivideQuad(c, c1, c2 []float64)
- func TraceArc(t Liner, x, y, rx, ry, start, angle, scale float64) (lastX, lastY float64)
- func TraceCubic(t Liner, cubic []float64, flatteningThreshold float64)
- func TraceQuad(t Liner, quad []float64, flatteningThreshold float64)
- type ContextStack
- type DashVertexConverter
- type DemuxFlattener
- type Flattener
- type FontExtents
- type Glyph
- type LineStroker
- type Liner
- type SegmentedPath
- type StackGraphicContext
- func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, angle float64)
- func (gc *StackGraphicContext) BeginPath()
- func (gc *StackGraphicContext) Close()
- func (gc *StackGraphicContext) ComposeMatrixTransform(Tr draw2d.Matrix)
- func (gc *StackGraphicContext) CreateStringPath(s string, x, y float64) float64
- func (gc *StackGraphicContext) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)
- func (gc *StackGraphicContext) GetDPI() int
- func (gc *StackGraphicContext) GetFontData() draw2d.FontData
- func (gc *StackGraphicContext) GetFontName() string
- func (gc *StackGraphicContext) GetFontSize() float64
- func (gc *StackGraphicContext) GetMatrixTransform() draw2d.Matrix
- func (gc *StackGraphicContext) GetPath() draw2d.Path
- func (gc *StackGraphicContext) GetStringBounds(s string) (left, top, right, bottom float64)
- func (gc *StackGraphicContext) IsEmpty() bool
- func (gc *StackGraphicContext) LastPoint() (float64, float64)
- func (gc *StackGraphicContext) LineTo(x, y float64)
- func (gc *StackGraphicContext) MoveTo(x, y float64)
- func (gc *StackGraphicContext) QuadCurveTo(cx, cy, x, y float64)
- func (gc *StackGraphicContext) Restore()
- func (gc *StackGraphicContext) Rotate(angle float64)
- func (gc *StackGraphicContext) Save()
- func (gc *StackGraphicContext) Scale(sx, sy float64)
- func (gc *StackGraphicContext) SetDPI(dpi int)
- func (gc *StackGraphicContext) SetFillColor(c color.Color)
- func (gc *StackGraphicContext) SetFillRule(f draw2d.FillRule)
- func (gc *StackGraphicContext) SetFont(font *truetype.Font)
- func (gc *StackGraphicContext) SetFontData(fontData draw2d.FontData)
- func (gc *StackGraphicContext) SetFontSize(fontSize float64)
- func (gc *StackGraphicContext) SetLineCap(cap draw2d.LineCap)
- func (gc *StackGraphicContext) SetLineDash(dash []float64, dashOffset float64)
- func (gc *StackGraphicContext) SetLineJoin(join draw2d.LineJoin)
- func (gc *StackGraphicContext) SetLineWidth(lineWidth float64)
- func (gc *StackGraphicContext) SetMatrixTransform(Tr draw2d.Matrix)
- func (gc *StackGraphicContext) SetStrokeColor(c color.Color)
- func (gc *StackGraphicContext) Translate(tx, ty float64)
- type Transformer
Constants ¶
const (
// CurveRecursionLimit represents the maximum recursion that is really necessary to subsivide a curve into straight lines
CurveRecursionLimit = 32
)
Variables ¶
var DefaultFontData = draw2d.FontData{Name: "luxi", Family: draw2d.FontFamilySans, Style: draw2d.FontStyleNormal}
Functions ¶
func DrawContour ¶
func DrawContour(path draw2d.PathBuilder, ps []truetype.Point, dx, dy float64)
DrawContour draws the given closed contour at the given sub-pixel offset.
func PolylineBresenham ¶
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
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
func TraceCubic ¶
TraceCubic generate lines subdividing the cubic 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 DPI int Previous *ContextStack // contains filtered or unexported fields }
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 FontExtents ¶
type FontExtents struct { // Ascent is the distance that the text // extends above the baseline. Ascent float64 // Descent is the distance that the text // extends below the baseline. The descent // is given as a negative value. Descent float64 // Height is the distance from the lowest // descending point to the highest ascending // point. Height float64 }
FontExtents contains font metric information.
func Extents ¶
func Extents(font *truetype.Font, size float64) FontExtents
Extents returns the FontExtents for a font. TODO needs to read this https://developer.apple.com/fonts/TrueType-Reference-Manual/RM02/Chap2.html#intro
type Glyph ¶
type Glyph struct { // Width of the glyph Width float64 // contains filtered or unexported fields }
Glyph represents a rune which has been converted to a Path and width
func FetchGlyph ¶
func FetchGlyph(gc draw2d.GraphicContext, fontName string, chr rune) *Glyph
FetchGlyph 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 (*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) CreateStringPath ¶
func (gc *StackGraphicContext) 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 (*StackGraphicContext) CubicCurveTo ¶
func (gc *StackGraphicContext) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64)
func (*StackGraphicContext) GetDPI ¶
func (gc *StackGraphicContext) GetDPI() int
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) GetStringBounds ¶
func (gc *StackGraphicContext) 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 (*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) SetDPI ¶
func (gc *StackGraphicContext) SetDPI(dpi int)
func (*StackGraphicContext) SetFillColor ¶
func (gc *StackGraphicContext) SetFillColor(c color.Color)
func (*StackGraphicContext) SetFillRule ¶
func (gc *StackGraphicContext) SetFillRule(f draw2d.FillRule)
func (*StackGraphicContext) SetFont ¶
func (gc *StackGraphicContext) SetFont(font *truetype.Font)
SetFont sets the font used to draw text
func (*StackGraphicContext) SetFontData ¶
func (gc *StackGraphicContext) SetFontData(fontData draw2d.FontData)
func (*StackGraphicContext) SetFontSize ¶
func (gc *StackGraphicContext) SetFontSize(fontSize float64)
SetFontSize sets the font size in points (as in “a 12 point font”).
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 ¶
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)