need to be very specific about points vs. pixels.

This commit is contained in:
Will Charczuk 2016-07-09 09:04:30 -07:00
parent 8bc8b1087c
commit 80d6be9849
6 changed files with 60 additions and 25 deletions

View file

@ -25,8 +25,8 @@ type ContextStack struct {
Cap LineCap
Join LineJoin
FontSize float64
Font *truetype.Font
FontSizePoints float64
Font *truetype.Font
Scale float64
@ -45,118 +45,145 @@ func NewStackGraphicContext() *StackGraphicContext {
gc.current.Cap = RoundCap
gc.current.FillRule = FillRuleEvenOdd
gc.current.Join = RoundJoin
gc.current.FontSize = 10
gc.current.FontSizePoints = 10
return gc
}
// GetMatrixTransform returns the matrix transform.
func (gc *StackGraphicContext) GetMatrixTransform() Matrix {
return gc.current.Tr
}
func (gc *StackGraphicContext) SetMatrixTransform(Tr Matrix) {
gc.current.Tr = Tr
// SetMatrixTransform sets the matrix transform.
func (gc *StackGraphicContext) SetMatrixTransform(tr Matrix) {
gc.current.Tr = tr
}
func (gc *StackGraphicContext) ComposeMatrixTransform(Tr Matrix) {
gc.current.Tr.Compose(Tr)
// ComposeMatrixTransform composes a transform into the current transform.
func (gc *StackGraphicContext) ComposeMatrixTransform(tr Matrix) {
gc.current.Tr.Compose(tr)
}
// Rotate rotates the matrix transform by an angle in degrees.
func (gc *StackGraphicContext) Rotate(angle float64) {
gc.current.Tr.Rotate(angle)
}
// Translate translates a transform.
func (gc *StackGraphicContext) Translate(tx, ty float64) {
gc.current.Tr.Translate(tx, ty)
}
// Scale scales a transform.
func (gc *StackGraphicContext) Scale(sx, sy float64) {
gc.current.Tr.Scale(sx, sy)
}
// SetStrokeColor sets the stroke color.
func (gc *StackGraphicContext) SetStrokeColor(c color.Color) {
gc.current.StrokeColor = c
}
// SetFillColor sets the fill color.
func (gc *StackGraphicContext) SetFillColor(c color.Color) {
gc.current.FillColor = c
}
// SetFillRule sets the fill rule.
func (gc *StackGraphicContext) SetFillRule(f FillRule) {
gc.current.FillRule = f
}
// SetLineWidth sets the line width.
func (gc *StackGraphicContext) SetLineWidth(lineWidth float64) {
gc.current.LineWidth = lineWidth
}
// SetLineCap sets the line cap.
func (gc *StackGraphicContext) SetLineCap(cap LineCap) {
gc.current.Cap = cap
}
// SetLineJoin sets the line join.
func (gc *StackGraphicContext) SetLineJoin(join LineJoin) {
gc.current.Join = join
}
// SetLineDash sets the line dash.
func (gc *StackGraphicContext) SetLineDash(dash []float64, dashOffset float64) {
gc.current.Dash = dash
gc.current.DashOffset = dashOffset
}
func (gc *StackGraphicContext) SetFontSize(fontSize float64) {
gc.current.FontSize = fontSize
// SetFontSize sets the font size.
func (gc *StackGraphicContext) SetFontSize(fontSizePoints float64) {
gc.current.FontSizePoints = fontSizePoints
}
// GetFontSize gets the font size.
func (gc *StackGraphicContext) GetFontSize() float64 {
return gc.current.FontSize
return gc.current.FontSizePoints
}
// SetFont sets the current font.
func (gc *StackGraphicContext) SetFont(f *truetype.Font) {
gc.current.Font = f
}
// GetFont returns the font.
func (gc *StackGraphicContext) GetFont() *truetype.Font {
return gc.current.Font
}
// BeginPath starts a new path.
func (gc *StackGraphicContext) BeginPath() {
gc.current.Path.Clear()
}
// IsEmpty returns if the path is empty.
func (gc *StackGraphicContext) IsEmpty() bool {
return gc.current.Path.IsEmpty()
}
func (gc *StackGraphicContext) LastPoint() (float64, float64) {
// LastPoint returns the last point on the path.
func (gc *StackGraphicContext) LastPoint() (x float64, y float64) {
return gc.current.Path.LastPoint()
}
// MoveTo moves the cursor for a path.
func (gc *StackGraphicContext) MoveTo(x, y float64) {
gc.current.Path.MoveTo(x, y)
}
// LineTo draws a line.
func (gc *StackGraphicContext) LineTo(x, y float64) {
gc.current.Path.LineTo(x, y)
}
// QuadCurveTo draws a quad curve.
func (gc *StackGraphicContext) QuadCurveTo(cx, cy, x, y float64) {
gc.current.Path.QuadCurveTo(cx, cy, x, y)
}
// CubicCurveTo draws a cubic curve.
func (gc *StackGraphicContext) CubicCurveTo(cx1, cy1, cx2, cy2, x, y float64) {
gc.current.Path.CubicCurveTo(cx1, cy1, cx2, cy2, x, y)
}
// ArcTo draws an arc.
func (gc *StackGraphicContext) ArcTo(cx, cy, rx, ry, startAngle, angle float64) {
gc.current.Path.ArcTo(cx, cy, rx, ry, startAngle, angle)
}
// Close closes a path.
func (gc *StackGraphicContext) Close() {
gc.current.Path.Close()
}
// Save pushes a context onto the stack.
func (gc *StackGraphicContext) Save() {
context := new(ContextStack)
context.FontSize = gc.current.FontSize
context.FontSizePoints = gc.current.FontSizePoints
context.Font = gc.current.Font
context.LineWidth = gc.current.LineWidth
context.StrokeColor = gc.current.StrokeColor
@ -174,6 +201,7 @@ func (gc *StackGraphicContext) Save() {
gc.current = context
}
// Restore restores the previous context.
func (gc *StackGraphicContext) Restore() {
if gc.current.Previous != nil {
oldContext := gc.current