nanovgo

package module
v0.0.0-...-d6e8631 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: Zlib Imports: 14 Imported by: 3

README

NanoVGo
=============

Pure golang implementation of `NanoVG <https://github.com/memononen/nanovg>`_. NanoVG is a vector graphics engine inspired by HTML5 Canvas API.

`DEMO <https://shibukawa.github.io/nanovgo/>`_

API Reference
---------------

See `GoDoc <https://godoc.org/github.com/shibukawa/nanovgo>`_

Porting Memo
--------------

* Root folder ``.go`` files

  Ported from NanoVG.

* ``fontstashmini/fontstash_mini.go``

  Ported from `fontstash <https://github.com/memononen/fontstash>`_. It includes only needed functions.

* ``fontstashmini/truetype``

  Copy from ``https://github.com/TheOnly92/fontstash.go`` (Public Domain)

License
----------

zlib license

Original (NanoVG) Author
---------------------------

* `Mikko Mononen <https://github.com/memononen>`_

Author
---------------

* `Yoshiki Shibukawa <https://github.com/shibukawa>`_

Contribution
----------------

* Moriyoshi Koizumi
* @hnakamur2
* @mattn_jp
* @hagat
* @h_doxas
* FSX

Documentation

Index

Constants

View Source
const (
	// Kappa90 is length proportional to radius of a cubic bezier handle for 90deg arcs.)
	Kappa90 float32 = 0.5522847493
	// PI of float32
	PI float32 = 3.14159265358979323846264338327
)

Variables

This section is empty.

Functions

func DegToRad

func DegToRad(deg float32) float32

DegToRad converts degree to radian.

func GetBoundRenderbuffer

func GetBoundRenderbuffer() gl.Renderbuffer

func NvgluBindFramebuffer

func NvgluBindFramebuffer(fb *FrameBuffer)

func NvgluDeleteFramebuffer

func NvgluDeleteFramebuffer(fb *FrameBuffer)

func RadToDeg

func RadToDeg(rad float32) float32

RadToDeg converts radian to degree.

Types

type Align

type Align int

Align is used for text location

const (
	// AlignLeft (default) is used for horizontal align. Align text horizontally to left.
	AlignLeft Align = 1 << 0
	// AlignCenter is used for horizontal align. Align text horizontally to center.
	AlignCenter Align = 1 << 1
	// AlignRight is used for horizontal align. Align text horizontally to right.
	AlignRight Align = 1 << 2
	// AlignTop is used for vertical align. Align text vertically to top.
	AlignTop Align = 1 << 3
	// AlignMiddle is used for vertical align. Align text vertically to middle.
	AlignMiddle Align = 1 << 4
	// AlignBottom is used for vertical align. Align text vertically to bottom.
	AlignBottom Align = 1 << 5
	// AlignBaseline (default) is used for vertical align. Align text vertically to baseline.
	AlignBaseline Align = 1 << 6
)

type Color

type Color struct {
	R, G, B, A float32
}

Color utils

Colors in NanoVGo are stored as unsigned ints in ABGR format.

func HSL

func HSL(h, s, l float32) Color

HSL returns color value specified by hue, saturation and lightness. HSL values are all in range [0..1], alpha will be set to 255.

func HSLA

func HSLA(h, s, l float32, a uint8) Color

HSLA returns color value specified by hue, saturation and lightness and alpha. HSL values are all in range [0..1], alpha in range [0..255]

func LerpRGBA

func LerpRGBA(c0, c1 Color, u float32) Color

LerpRGBA linearly interpolates from color c0 to c1, and returns resulting color value.

func MONO

func MONO(i, alpha uint8) Color

MONO returns color value specified by intensity value.

func MONOf

func MONOf(i, alpha float32) Color

MONOf returns color value specified by intensity value.

func RGB

func RGB(r, g, b uint8) Color

RGB returns a color value from red, green, blue values. Alpha will be set to 255 (1.0f).

func RGBA

func RGBA(r, g, b, a uint8) Color

RGBA returns a color value from red, green, blue and alpha values.

func RGBAf

func RGBAf(r, g, b, a float32) Color

RGBAf returns a color value from red, green, blue and alpha values.

func RGBf

func RGBf(r, g, b float32) Color

RGBf returns a color value from red, green, blue values. Alpha will be set to 1.0f.

func (Color) ContrastingColor

func (c Color) ContrastingColor() Color

Calc constraint color

func (Color) HSLA

func (c Color) HSLA() (h, s, l, a float32)

Convert To HSLA

func (Color) List

func (c Color) List() []float32

List returns color value as array.

func (Color) Luminance

func (c Color) Luminance() float32

Calc luminance value

func (Color) PreMultiply

func (c Color) PreMultiply() Color

PreMultiply preset alpha to each color.

func (Color) TransRGBA

func (c Color) TransRGBA(a uint8) Color

TransRGBA sets transparency of a color value.

func (Color) TransRGBAf

func (c Color) TransRGBAf(a float32) Color

TransRGBAf sets transparency of a color value.

type Context

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

Context is an entry point object to use NanoVGo API and created by NewContext() function.

State Handling

NanoVG contains state which represents how paths will be rendered. The state contains transform, fill and stroke styles, text and font styles, and scissor clipping.

Render styles

Fill and stroke render style can be either a solid color or a paint which is a gradient or a pattern. Solid color is simply defined as a color value, different kinds of paints can be created using LinearGradient(), BoxGradient(), RadialGradient() and ImagePattern().

Current render style can be saved and restored using Save() and Restore().

Transforms

The paths, gradients, patterns and scissor region are transformed by an transformation matrix at the time when they are passed to the API. The current transformation matrix is a affine matrix:

[sx kx tx]
[ky sy ty]
[ 0  0  1]

Where: sx,sy define scaling, kx,ky skewing, and tx,ty translation. The last row is assumed to be 0,0,1 and is not stored.

Apart from ResetTransform(), each transformation function first creates specific transformation matrix and pre-multiplies the current transformation by it.

Current coordinate system (transformation) can be saved and restored using Save() and Restore().

Images

NanoVG allows you to load jpg, png, psd, tga, pic and gif files to be used for rendering. In addition you can upload your own image. The image loading is provided by stb_image. The parameter imageFlags is combination of flags defined in ImageFlags.

Paints

NanoVG supports four types of paints: linear gradient, box gradient, radial gradient and image pattern. These can be used as paints for strokes and fills.

Scissoring

Scissoring allows you to clip the rendering into a rectangle. This is useful for various user interface cases like rendering a text edit or a timeline.

Paths

Drawing a new shape starts with BeginPath(), it clears all the currently defined paths. Then you define one or more paths and sub-paths which describe the shape. The are functions to draw common shapes like rectangles and circles, and lower level step-by-step functions, which allow to define a path curve by curve.

NanoVG uses even-odd fill rule to draw the shapes. Solid shapes should have counter clockwise winding and holes should have counter clockwise order. To specify winding of a path you can call PathWinding(). This is useful especially for the common shapes, which are drawn CCW.

Finally you can fill the path using current fill style by calling Fill(), and stroke it with current stroke style by calling Stroke().

The curve segments and sub-paths are transformed by the current transform.

Text

NanoVG allows you to load .ttf files and use the font to render text.

The appearance of the text can be defined by setting the current text style and by specifying the fill color. Common text and font settings such as font size, letter spacing and text align are supported. Font blur allows you to create simple text effects such as drop shadows.

At render time the font face can be set based on the font handles or name.

Font measure functions return values in local space, the calculations are carried in the same resolution as the final rendering. This is done because the text glyph positions are snapped to the nearest pixels sharp rendering.

The local space means that values are not rotated or scale as per the current transformation. For example if you set font size to 12, which would mean that line height is 16, then regardless of the current scaling and rotation, the returned line height is always 16. Some measures may vary because of the scaling since aforementioned pixel snapping.

While this may sound a little odd, the setup allows you to always render the same way regardless of scaling. I.e. following works regardless of scaling:

vg.TextBounds(x, y, "Text me up.", bounds)
vg.BeginPath()
vg.RoundedRect(bounds[0],bounds[1], bounds[2]-bounds[0], bounds[3]-bounds[1])
vg.Fill()

Note: currently only solid color fill is supported for text.

func NewContext

func NewContext(flags CreateFlags) (*Context, error)

NewContext makes new NanoVGo context that is entry point of this API

func (*Context) Arc

func (c *Context) Arc(cx, cy, r, a0, a1 float32, dir Direction)

Arc creates new circle arc shaped sub-path. The arc center is at cx,cy, the arc radius is r, and the arc is drawn from angle a0 to a1, and swept in direction dir (CounterClockwise, or Clockwise). Angles are specified in radians.

func (*Context) ArcTo

func (c *Context) ArcTo(x1, y1, x2, y2, radius float32)

ArcTo adds an arc segment at the corner defined by the last path point, and two specified points.

func (*Context) BeginFrame

func (c *Context) BeginFrame(windowWidth, windowHeight int, devicePixelRatio float32)

BeginFrame begins drawing a new frame Calls to NanoVGo drawing API should be wrapped in Context.BeginFrame() & Context.EndFrame() Context.BeginFrame() defines the size of the window to render to in relation currently set viewport (i.e. glViewport on GL backends). Device pixel ration allows to control the rendering on Hi-DPI devices. For example, GLFW returns two dimension for an opened window: window size and frame buffer size. In that case you would set windowWidth/Height to the window size devicePixelRatio to: frameBufferWidth / windowWidth.

func (*Context) BeginFrameWithSameStates

func (c *Context) BeginFrameWithSameStates(windowWidth, windowHeight int, devicePixelRatio float32)

Same as normal begin frame but without reset of states stack. Usefull for some tricks with rendering multiple fbo in one common coordinate system

func (*Context) BeginPath

func (c *Context) BeginPath()

BeginPath clears the current path and sub-paths.

func (*Context) BezierTo

func (c *Context) BezierTo(c1x, c1y, c2x, c2y, x, y float32)

BezierTo adds cubic bezier segment from last point in the path via two control points to the specified point.

func (*Context) Block

func (c *Context) Block(block func())

Block makes Save/Restore block.

func (*Context) BoundedCircle

func (c *Context) BoundedCircle(x, y, radius, left, right, top, bottom float32)

Create bounded circle in (x,y) with radius and sides shifts.

func (*Context) CancelFrame

func (c *Context) CancelFrame()

CancelFrame cancels drawing the current frame.

func (*Context) Circle

func (c *Context) Circle(cx, cy, r float32)

Circle creates new circle shaped sub-path.

func (*Context) ClosePath

func (c *Context) ClosePath()

ClosePath closes current sub-path with a line segment.

func (*Context) CreateFont

func (c *Context) CreateFont(name, filePath string) int

CreateFont creates font by loading it from the disk from specified file name. Returns handle to the font.

func (*Context) CreateFontFromMemory

func (c *Context) CreateFontFromMemory(name string, data []byte, freeData uint8) int

CreateFontFromMemory creates image by loading it from the specified memory chunk. Returns handle to the font.

func (*Context) CreateFramebuffer

func (c *Context) CreateFramebuffer(w, h int, imageFlags ImageFlags) *FrameBuffer

func (*Context) CreateImage

func (c *Context) CreateImage(filePath string, flags ImageFlags) int

CreateImage creates image by loading it from the disk from specified file name. Returns handle to the image.

func (*Context) CreateImageFromGoImage

func (c *Context) CreateImageFromGoImage(imageFlag ImageFlags, img image.Image) int

CreateImageFromGoImage creates image by loading it from the specified image.Image object. Returns handle to the image.

func (*Context) CreateImageFromMemory

func (c *Context) CreateImageFromMemory(flags ImageFlags, data []byte) int

CreateImageFromMemory creates image by loading it from the specified chunk of memory. Returns handle to the image.

func (*Context) CreateImageRGBA

func (c *Context) CreateImageRGBA(w, h int, imageFlags ImageFlags, data []byte) int

CreateImageRGBA creates image from specified image data. Returns handle to the image.

func (*Context) CurrentTransform

func (c *Context) CurrentTransform() TransformMatrix

CurrentTransform returns the top part (a-f) of the current transformation matrix.

[a c e]
[b d f]
[0 0 1]

There should be space for 6 floats in the return buffer for the values a-f.

func (*Context) DebugDumpPathCache

func (c *Context) DebugDumpPathCache()

DebugDumpPathCache prints cached path information to console

func (*Context) Delete

func (c *Context) Delete()

Delete is called when tearing down NanoVGo context

func (*Context) DeleteImage

func (c *Context) DeleteImage(img int)

DeleteImage deletes created image.

func (*Context) Ellipse

func (c *Context) Ellipse(cx, cy, rx, ry float32)

Ellipse creates new ellipse shaped sub-path.

func (*Context) EndFrame

func (c *Context) EndFrame()

EndFrame ends drawing flushing remaining render state.

func (*Context) Fill

func (c *Context) Fill()

Fill fills the current path with current fill style.

func (*Context) FindFont

func (c *Context) FindFont(name string) int

FindFont finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.

func (*Context) FontBlur

func (c *Context) FontBlur() float32

FontBlur gets the font blur of current text style.

func (*Context) FontFace

func (c *Context) FontFace() string

FontFace gets the font face name of current text style.

func (*Context) FontFaceID

func (c *Context) FontFaceID() int

FontFaceID gets the font face id of current text style.

func (*Context) FontSize

func (c *Context) FontSize() float32

FontSize gets the font size of current text style.

func (*Context) GlobalAlpha

func (c *Context) GlobalAlpha() float32

GlobalAlpha gets the transparency applied to all rendered shapes.

func (*Context) ImageSize

func (c *Context) ImageSize(img int) (int, int, error)

ImageSize returns the dimensions of a created image.

func (*Context) IntersectScissor

func (c *Context) IntersectScissor(x, y, w, h float32)

IntersectScissor calculates intersects current scissor rectangle with the specified rectangle. The scissor rectangle is transformed by the current transform. Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.

func (*Context) LineCap

func (c *Context) LineCap() LineCap

LineCap gets how the end of the line (cap) is drawn,

func (*Context) LineJoin

func (c *Context) LineJoin() LineCap

LineJoin gets how sharp path corners are drawn.

func (*Context) LineTo

func (c *Context) LineTo(x, y float32)

LineTo adds line segment from the last point in the path to the specified point.

func (*Context) MiterLimit

func (c *Context) MiterLimit() float32

MiterLimit gets the miter limit of the stroke style.

func (*Context) MoveTo

func (c *Context) MoveTo(x, y float32)

MoveTo starts new sub-path with specified point as first point.

func (*Context) PathWinding

func (c *Context) PathWinding(winding Winding)

PathWinding sets the current sub-path winding, see Winding.

func (*Context) Polyline

func (c *Context) Polyline(points []FPoint, isClose bool)

Create polyline using points. If isClose=true polyline will be close.

func (*Context) QuadTo

func (c *Context) QuadTo(cx, cy, x, y float32)

QuadTo adds quadratic bezier segment from last point in the path via a control point to the specified point.

func (*Context) Rect

func (c *Context) Rect(x, y, w, h float32)

Rect creates new rectangle shaped sub-path.

func (*Context) Reset

func (c *Context) Reset()

Reset resets current render state to default values. Does not affect the render state stack.

func (*Context) ResetScissor

func (c *Context) ResetScissor()

ResetScissor resets and disables scissoring.

func (*Context) ResetTransform

func (c *Context) ResetTransform()

ResetTransform resets current transform to a identity matrix.

func (*Context) Restore

func (c *Context) Restore()

Restore pops and restores current render state.

func (*Context) Rotate

func (c *Context) Rotate(angle float32)

Rotate rotates current coordinate system. Angle is specified in radians.

func (*Context) RoundedRect

func (c *Context) RoundedRect(x, y, w, h, r float32)

RoundedRect creates new rounded rectangle shaped sub-path.

func (*Context) Save

func (c *Context) Save()

Save pushes and saves the current render state into a state stack. A matching Restore() must be used to restore the state.

func (*Context) Scale

func (c *Context) Scale(x, y float32)

Scale scales the current coordinate system.

func (*Context) Scissor

func (c *Context) Scissor(x, y, w, h float32)

Scissor sets the current scissor rectangle. The scissor rectangle is transformed by the current transform.

func (*Context) SectorSegment

func (c *Context) SectorSegment(x, y, radiusOuter, radiusInner, startAngle, sweepAngle float32)

SectorSegment create new segment of sector. The arc center is at (x,y), the inner arc radius is radiusInner, and outer radius is radiusOuter. The sector drawing from startAngle to (startAngle + sweepAngle) Angles are specified in radians.

func (*Context) SetFillColor

func (c *Context) SetFillColor(color Color)

SetFillColor sets current fill style to a solid color.

func (*Context) SetFillPaint

func (c *Context) SetFillPaint(paint Paint)

SetFillPaint sets current fill style to a paint, which can be a one of the gradients or a pattern.

func (*Context) SetFontBlur

func (c *Context) SetFontBlur(blur float32)

SetFontBlur sets the font blur of current text style.

func (*Context) SetFontFace

func (c *Context) SetFontFace(font string)

SetFontFace sets the font face based on specified name of current text style.

func (*Context) SetFontFaceID

func (c *Context) SetFontFaceID(font int)

SetFontFaceID sets the font face based on specified id of current text style.

func (*Context) SetFontSize

func (c *Context) SetFontSize(size float32)

SetFontSize sets the font size of current text style.

func (*Context) SetGlobalAlpha

func (c *Context) SetGlobalAlpha(alpha float32)

SetGlobalAlpha sets the transparency applied to all rendered shapes. Already transparent paths will get proportionally more transparent as well.

func (*Context) SetLineCap

func (c *Context) SetLineCap(cap LineCap)

SetLineCap sets how the end of the line (cap) is drawn, Can be one of: Butt (default), Round, Squre.

func (*Context) SetLineJoin

func (c *Context) SetLineJoin(joint LineCap)

SetLineJoin sets how sharp path corners are drawn. Can be one of Miter (default), Round, Bevel.

func (*Context) SetMiterLimit

func (c *Context) SetMiterLimit(limit float32)

SetMiterLimit sets the miter limit of the stroke style. Miter limit controls when a sharp corner is beveled.

func (*Context) SetStrokeColor

func (c *Context) SetStrokeColor(color Color)

SetStrokeColor sets current stroke style to a solid color.

func (*Context) SetStrokePaint

func (c *Context) SetStrokePaint(paint Paint)

SetStrokePaint sets current stroke style to a paint, which can be a one of the gradients or a pattern.

func (*Context) SetStrokeWidth

func (c *Context) SetStrokeWidth(width float32)

SetStrokeWidth sets the stroke width of the stroke style.

func (*Context) SetTextAlign

func (c *Context) SetTextAlign(align Align)

SetTextAlign sets the text align of current text style.

func (*Context) SetTextLetterSpacing

func (c *Context) SetTextLetterSpacing(spacing float32)

SetTextLetterSpacing sets the letter spacing of current text style.

func (*Context) SetTextLineHeight

func (c *Context) SetTextLineHeight(lineHeight float32)

SetTextLineHeight sets the line height of current text style.

func (*Context) SetTransform

func (c *Context) SetTransform(t TransformMatrix)

SetTransform premultiplies current coordinate system by specified matrix.

func (*Context) SetTransformByValue

func (cx *Context) SetTransformByValue(a, b, c, d, e, f float32)

SetTransformByValue premultiplies current coordinate system by specified matrix. The parameters are interpreted as matrix as follows:

[a c e]
[b d f]
[0 0 1]

func (*Context) SkewX

func (c *Context) SkewX(angle float32)

SkewX skews the current coordinate system along X axis. Angle is specified in radians.

func (*Context) SkewY

func (c *Context) SkewY(angle float32)

SkewY skews the current coordinate system along Y axis. Angle is specified in radians.

func (*Context) Stroke

func (c *Context) Stroke()

Stroke draws the current path with current stroke style.

func (*Context) StrokeWidth

func (c *Context) StrokeWidth() float32

StrokeWidth gets the stroke width of the stroke style.

func (*Context) Text

func (c *Context) Text(x, y float32, str string) float32

Text draws text string at specified location. If end is specified only the sub-string up to the end is drawn.

func (*Context) TextAlign

func (c *Context) TextAlign() Align

TextAlign gets the text align of current text style.

func (*Context) TextBounds

func (c *Context) TextBounds(x, y float32, str string) (float32, []float32)

TextBounds measures the specified text string. Parameter bounds should be a pointer to float[4], if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax] Returns the horizontal advance of the measured text (i.e. where the next character should drawn). Measured values are returned in local coordinate space.

func (*Context) TextBox

func (c *Context) TextBox(x, y, breakRowWidth float32, str string)

TextBox draws multi-line text string at specified location wrapped at the specified width. If end is specified only the sub-string up to the end is drawn. White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. Words longer than the max width are slit at nearest character (i.e. no hyphenation). Draws text string at specified location. If end is specified only the sub-string up to the end is drawn.

func (*Context) TextBoxBounds

func (c *Context) TextBoxBounds(x, y, breakRowWidth float32, str string) [4]float32

TextBoxBounds measures the specified multi-text string. Parameter bounds should be a pointer to float[4], if the bounding box of the text should be returned. The bounds value are [xmin,ymin, xmax,ymax] Measured values are returned in local coordinate space.

func (*Context) TextBreakLines

func (c *Context) TextBreakLines(str string, breakRowWidth float32) []TextRow

TextBreakLines breaks the specified text into lines. If end is specified only the sub-string will be used. White space is stripped at the beginning of the rows, the text is split at word boundaries or when new-line characters are encountered. Words longer than the max width are slit at nearest character (i.e. no hyphenation).

func (*Context) TextBreakLinesRune

func (c *Context) TextBreakLinesRune(runes []rune, breakRowWidth float32) []TextRow

TextBreakLinesRune is an alternate version of TextBreakLines that accepts rune slice

func (*Context) TextGlyphPositions

func (c *Context) TextGlyphPositions(x, y float32, str string) []GlyphPosition

TextGlyphPositions calculates the glyph x positions of the specified text. If end is specified only the sub-string will be used. Measured values are returned in local coordinate space.

func (*Context) TextGlyphPositionsRune

func (c *Context) TextGlyphPositionsRune(x, y float32, runes []rune) []GlyphPosition

TextGlyphPositionsRune is an alternate version of TextGlyphPositions that accepts rune slice

func (*Context) TextLetterSpacing

func (c *Context) TextLetterSpacing() float32

TextLetterSpacing gets the letter spacing of current text style.

func (*Context) TextLineHeight

func (c *Context) TextLineHeight() float32

TextLineHeight gets the line height of current text style.

func (*Context) TextMetrics

func (c *Context) TextMetrics() (float32, float32, float32)

TextMetrics returns the vertical metrics based on the current text style. Measured values are returned in local coordinate space.

func (*Context) TextRune

func (c *Context) TextRune(x, y float32, runes []rune) float32

TextRune is an alternate version of Text that accepts rune slice.

func (*Context) Translate

func (c *Context) Translate(x, y float32)

Translate translates current coordinate system.

func (*Context) UpdateImage

func (c *Context) UpdateImage(img int, data []byte) error

UpdateImage updates image data specified by image handle.

type CreateFlags

type CreateFlags int

CreateFlags is used when NewContext() to create NanoVGo context.

const (
	// AntiAlias sets NanoVGo to use AA
	AntiAlias CreateFlags = 1 << 0
	// StencilStrokes sets NanoVGo to use stencil buffer to draw strokes
	StencilStrokes CreateFlags = 1 << 1
	// Debug shows OpenGL errors to console
	Debug CreateFlags = 1 << 2
)

type Direction

type Direction int

Direction is used with Context.Arc

const (
	// CounterClockwise specify Arc curve direction
	CounterClockwise Direction = 1
	// Clockwise specify Arc curve direction
	Clockwise Direction = 2
)

type FPoint

type FPoint struct {
	X float32
	Y float32
}

type Float

type Float float32

type FrameBuffer

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

func (*FrameBuffer) Image

func (fb *FrameBuffer) Image() int

type GLint

type GLint = int32

type GLuint

type GLuint = uint32

type GlyphPosition

type GlyphPosition struct {
	Index      int // Position of the glyph in the input string.
	Runes      []rune
	X          float32 // The x-coordinate of the logical glyph position.
	MinX, MaxX float32 // The bounds of the glyph shape.
}

GlyphPosition keeps glyph location information

type ImageFlags

type ImageFlags int

ImageFlags is used for setting image object

const (
	// ImageGenerateMipmaps generates mipmaps during creation of the image.
	ImageGenerateMipmaps ImageFlags = 1 << 0
	// ImageRepeatX repeats image in X direction.
	ImageRepeatX ImageFlags = 1 << 1
	// ImageRepeatY repeats image in X direction.
	ImageRepeatY ImageFlags = 1 << 2
	// ImageFlippy flips (inverses) image in Y direction when rendered.
	ImageFlippy ImageFlags = 1 << 3
	// ImagePreMultiplied specifies image data has premultiplied alpha.
	ImagePreMultiplied ImageFlags = 1 << 4
)
const (
	// ImageNoDelete don't delete from memory when removing image
	ImageNoDelete ImageFlags = 1 << 16
)

type LineCap

type LineCap int

LineCap is used for line cap and joint

const (
	// Butt is used for line cap (default value)
	Butt LineCap = iota
	// Round is used for line cap and joint
	Round
	// Square is used for line cap
	Square
	// Bevel is used for joint
	Bevel
	// Miter is used for joint (default value)
	Miter
)

type Paint

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

Paint structure represent paint information including gradient and image painting. Context.SetFillPaint() and Context.SetStrokePaint() accept this instance.

func BoxGradient

func BoxGradient(x, y, w, h, r, f float32, iColor, oColor Color) Paint

BoxGradient creates and returns a box gradient. Box gradient is a feathered rounded rectangle, it is useful for rendering drop shadows or highlights for boxes. Parameters (x,y) define the top-left corner of the rectangle, (w,h) define the size of the rectangle, r defines the corner radius, and f feather. Feather defines how blurry the border of the rectangle is. Parameter icol specifies the inner color and ocol the outer color of the gradient. The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().

func ImagePattern

func ImagePattern(cx, cy, w, h, angle float32, img int, alpha float32) Paint

ImagePattern creates and returns an image patter. Parameters (ox,oy) specify the left-top location of the image pattern, (ex,ey) the size of one image, angle rotation around the top-left corner, image is handle to the image to render. The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().

func LinearGradient

func LinearGradient(sx, sy, ex, ey float32, iColor, oColor Color) Paint

LinearGradient creates and returns a linear gradient. Parameters (sx,sy)-(ex,ey) specify the start and end coordinates of the linear gradient, icol specifies the start color and ocol the end color. The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().

func RadialGradient

func RadialGradient(cx, cy, inR, outR float32, iColor, oColor Color) Paint

RadialGradient creates and returns a radial gradient. Parameters (cx,cy) specify the center, inr and outr specify the inner and outer radius of the gradient, icol specifies the start color and ocol the end color. The gradient is transformed by the current transform when it is passed to Context.FillPaint() or Context.StrokePaint().

type TextRow

type TextRow struct {
	Runes      []rune  // The input string.
	StartIndex int     // Index to the input text where the row starts.
	EndIndex   int     // Index to the input text where the row ends (one past the last character).
	NextIndex  int     // Index to the beginning of the next row.
	Width      float32 // Logical width of the row.
	MinX, MaxX float32 // Actual bounds of the row. Logical with and bounds can differ because of kerning and some parts over extending.
}

TextRow keeps row geometry information

type TransformMatrix

type TransformMatrix [6]float32

TransformMatrix is a 2x3 matrix is represented as float[6].

func IdentityMatrix

func IdentityMatrix() TransformMatrix

IdentityMatrix makes the transform to identity matrix.

func RotateMatrix

func RotateMatrix(a float32) TransformMatrix

RotateMatrix makes the transform to rotate matrix. Angle is specified in radians.

func ScaleMatrix

func ScaleMatrix(sx, sy float32) TransformMatrix

ScaleMatrix makes the transform to scale matrix.

func SkewXMatrix

func SkewXMatrix(a float32) TransformMatrix

SkewXMatrix makes the transform to skew-x matrix. Angle is specified in radians.

func SkewYMatrix

func SkewYMatrix(a float32) TransformMatrix

SkewYMatrix makes the transform to skew-y matrix. Angle is specified in radians.

func TranslateMatrix

func TranslateMatrix(tx, ty float32) TransformMatrix

TranslateMatrix makes the transform to translation matrix matrix.

func (TransformMatrix) Inverse

func (t TransformMatrix) Inverse() TransformMatrix

Inverse makes the destination to inverse of specified transform. Returns 1 if the inverse could be calculated, else 0.

func (TransformMatrix) Multiply

Multiply makes the transform to the result of multiplication of two transforms, of A = A*B.

func (TransformMatrix) PreMultiply

PreMultiply makes the transform to the result of multiplication of two transforms, of A = B*A.

func (TransformMatrix) ToMat3x4

func (t TransformMatrix) ToMat3x4() []float32

ToMat3x4 makes 3x4 matrix.

func (TransformMatrix) TransformPoint

func (t TransformMatrix) TransformPoint(sx, sy float32) (dx, dy float32)

TransformPoint transforms a point by given TransformMatrix.

type Winding

type Winding int

Winding is used for changing filling strategy

const (
	// Solid fills internal hole
	Solid Winding = 1
	// Hole keeps internal hole
	Hole Winding = 2
)

Directories

Path Synopsis
truetype
This library processes TrueType files: - parse files - extract glyph metrics - extract glyph shapes - render glyphs to one-channel bitmaps with antialiasing (box filter)
This library processes TrueType files: - parse files - extract glyph metrics - extract glyph shapes - render glyphs to one-channel bitmaps with antialiasing (box filter)

Jump to

Keyboard shortcuts

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