Crate flo_canvas

Source
Expand description

§flo_canvas

flo_canvas provides an abstraction of a 2D vector canvas, and supporting methods to stream updates to implementations.

The main features that this library supports are the set of primitives in the Draw enum, the Canvas type for streaming drawing instructions elsewhere, and the encoding and decoding functions that can be used to send canvas instructions over a byte stream. Encoding uses MIME64 characters, so it’s easy to embed encoded canvases in other protocols.

By itself, flo_canvas is an excellent way to describe how a 2D scene should be rendered without needing to depend on a system-specific library.

FlowBetween comes with several implementations of the canvas for generating the final rendered results. Most notably, flo_render_canvas will convert between a stream of Draw instructions and a stream of instructions suitable for rendering with most graphics APIs. The accompanying flo_render can render these instructions to OpenGL or Metal and flo_render_gl_offscreen is available to generate bitmap images on a variety of systems.

canvas.js provides a Javascript implementation that can render the instructions to a HTML canvas, and there are also Quartz and Cairo implementations of the canvas provided in FlowBetween’s user interface layers.

§Features

Some features of flo_canvas are optional due to the extra dependencies they can bring in. They can be enabled if the extra functionality is required or left out to get a more compact library.

  • outline-fonts - provides a function that will convert a stream of Draw instructions into another stream of Draw instructions, except all the font commands will be removed and replaced with an outline rendering of the font (useful for rendering back-ends that don’t have native font support or for generating vector files that don’t require particular fonts to be installed)

Re-exports§

pub use flo_curves as curves;

Structs§

Canvas
A canvas is an abstract interface for drawing graphics. It doesn’t actually provide a means to render anything, but rather a way to describe how things should be drawn and pass those on to a renderer elsewhere.
CanvasDecoder
Represents a (stateful) canvas decoder
CanvasFontFace
Representation of a font face
CanvasGraphicsContext
Graphics context for a Canvas
Coord2
Represents a 2D point
DrawStream
A draw stream relays Draw instructions from a source such as a Canvas or a DrawContext as a stream
DrawingTarget
A drawing target sends drawing instructions to a DrawStream
FontId
Identifier for a font
FontLinePosition
Describes where to position a line relative to some text
FontMetrics
Metrics for a font
FontProperties
The properties to use when selecting a font face
GlyphId
ID for a glyph within a font
GlyphPosition
Describes how a glyph is positioned on the canvas
GradientId
Identifies a gradient
LayerId
Identifier of a canvas layer
SpriteId
Identifier of a canvas ‘sprite’
TextLayoutMetrics
The layout metrics for a piece of text
TextureId
Identifier for a texture
Transform2D
Represents a 2D affine transformation matrix

Enums§

BlendMode
Blend mode to use when drawing
Color
Representation of a colour
ColorFormat
Possible formats of a colour value
DecoderError
Possible error from the decoder
Draw
Instructions for drawing to a canvas
FontOp
Operations that can be performed on a font
FontStyle
The possible styles of a font
GradientOp
Operations that can be applied to a gradient
LineCap
How to cap lines
LineJoin
Possible way to join lines
PathAttribute
Attributes used to render a bezier path
PathOp
Operations that define paths
SpriteTransform
Transformation to apply to a canvas ‘sprite’
StreamDecoderError
Error from either a decoder or the stream that’s feeding it
TextAlignment
Determines how text is drawn relative to its alignment’s origin point
TextureFormat
Format of a rendering texture
TextureOp
Operations that can be performed on a texture
WindingRule
How a path should determine if it’s an outer edge or not

Traits§

CanvasEncoding
Trait implemented by objects that can be encoded into a canvas
Coordinate2D
Represents a coordinate with a 2D position
GraphicsContext
A graphics context provides the basic set of graphics actions that can be performed
GraphicsPrimitives
GraphicsPrimitives adds new primitives that can be built directly from a graphics context

Functions§

decode_drawing
Decodes a canvas drawing represented as an iterator of characters. If there’s an error in the stream, it will be the last item decoded.
decode_drawing_stream
Decodes a canvas drawing represented as a stream of characters.
draw_circle
Returns the drawing commands for a circle
draw_rect
Returns the drawing commands for a rectangle
drawing_to_attributed_paths
Converts a stream of drawing instructions into a stream of bezier paths with attributes that specify how they’re rendered.
drawing_to_paths
Converts a stream of drawing instructions into a stream of bezier paths (stripping any other attributes from the stream)
drawing_without_dashed_lines
Converts dashed line stroke operations into separate lines
gradient_scale
Creates a gradient scale, as 8-bit RGBA quads from a set of gradient operations
path_to_dashed_lines
Converts a bezier path to a set of paths by a dash patter