Documentation ¶
Index ¶
- func Rasterize(outline sfnt.Segments, rasterizer *vector.Rasterizer, originX, originY Fract) (*image.Alpha, error)
- type Fract
- type Shape
- func (self *Shape) CubeTo(cx1, cy1, cx2, cy2, x, y int)
- func (self *Shape) CubeToFract(cx1, cy1, cx2, cy2, x, y Fract)
- func (self *Shape) GetScale() Fract
- func (self *Shape) HasInvertY() bool
- func (self *Shape) InvertY(active bool)
- func (self *Shape) LineTo(x, y int)
- func (self *Shape) LineToFract(x, y Fract)
- func (self *Shape) MoveTo(x, y int)
- func (self *Shape) MoveToFract(x, y Fract)
- func (self *Shape) Paint(drawColor, backColor color.Color) *image.RGBA
- func (self *Shape) QuadTo(ctrlX, ctrlY, x, y int)
- func (self *Shape) QuadToFract(ctrlX, ctrlY, x, y Fract)
- func (self *Shape) Rasterize() (*image.Alpha, error)
- func (self *Shape) RasterizeFract(offsetX, offsetY Fract) (*image.Alpha, error)
- func (self *Shape) Reset()
- func (self *Shape) Segments() sfnt.Segments
- func (self *Shape) SetScale(scale float64)
- func (self *Shape) SetScaleFract(scale Fract)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Shape ¶
type Shape struct {
// contains filtered or unexported fields
}
A helper type to assist the creation of shapes that can later be converted to sfnt.Segments and rasterized with etxt/mask.Rasterize(), or directly converted to an *image.RGBA.
Notice that the rasterization is a CPU process, so working with big shapes (based on their bounding rectangle) can be quite expensive.
Despite what the names of the methods might lead you to believe, shapes are not created by "drawing lines", but rather by defining a set of boundaries that enclose an area. If you get unexpected results using shapes, come back to think about this.
Shapes by themselves do not care about the direction you use to define the segments (clockwise/counter-clockwise), but rasterizers that use the segments most often do. For example, if you define two squares one inside the other, both in the same order (e.g: top-left to top-right, top-right to bottom right...) the rasterized result will be a single square. If you define them following opposite directions, instead, the result will be the difference between the two squares.
func (*Shape) CubeTo ¶
Creates a cubic Bézier curve to (x, y) with (cx1, cy1) and (cx2, cy2) as the control points. See golang.org/x/image/vector.Rasterizer operations and golang.org/x/image/font/sfnt.Segment.
func (*Shape) CubeToFract ¶
Like Shape.CubeTo, but with fractional coordinates.
func (*Shape) HasInvertY ¶
Returns whether Shape.InvertY is active or inactive.
func (*Shape) InvertY ¶
Let's say you want to draw a triangle pointing up, similar to an "A". By default, you would move to (0, 0) and then draw lines to (k, 2*k), (2*k, 0) and back to (0, 0).
If you set InvertY to true, the previous shape will draw a triangle pointing down instead, similar to a "V". This is a convenient flag that makes it easier to work on different contexts (e.g., font glyphs are defined with the ascenders going into the negative y plane).
InvertY can also be used creatively or to switch between clockwise and counter-clockwise directions when drawing symmetrical shapes that have their center at (0, 0).
func (*Shape) LineTo ¶
Creates a straight boundary from the current position to (x, y). See vector.Rasterizer operations and sfnt.Segment.
func (*Shape) LineToFract ¶
Like Shape.LineTo, but with fractional coordinates.
func (*Shape) MoveTo ¶
Moves the current position to (x, y). See vector.Rasterizer operations and sfnt.Segment.
func (*Shape) MoveToFract ¶
Like Shape.MoveTo, but with fractional coordinates.
func (*Shape) Paint ¶
A helper method to rasterize the current shape with the given colors. You could then export the result to a png file, e.g.:
file, _ := os.Create("my_ugly_shape.png") _ = png.Encode(file, shape.Paint(color.White, color.Black)) // ...maybe even checking errors and closing the file ;)
func (*Shape) QuadTo ¶
Creates a quadratic Bézier curve (also known as a conic Bézier curve) to (x, y) with (ctrlX, ctrlY) as the control point. See vector.Rasterizer operations and sfnt.Segment.
func (*Shape) QuadToFract ¶
Like Shape.QuadTo, but with fractional coordinates.
func (*Shape) Rasterize ¶
A helper method to rasterize the current shape into an *image.Alpha.
func (*Shape) RasterizeFract ¶
A helper method to rasterize the current shape displaced by the given fractional offset into an *image.Alpha.
func (*Shape) Reset ¶
func (self *Shape) Reset()
Resets the shape segments. Be careful to not be holding the segments from Shape.Segments() when calling this (they may be overriden soon).
func (*Shape) Segments ¶
Gets the shape information as sfnt.Segments. The underlying data is referenced both by the Shape and the sfnt.Segments, so be careful what you do with it.
func (*Shape) SetScale ¶
Sets a scaling factor to be applied to the coordinates of subsequent Shape.MoveTo(), Shape.LineTo() and similar commands.
func (*Shape) SetScaleFract ¶
Like Shape.SetScale(), but expecting a Fract value instead of a float64.