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.
- Canvas
Decoder - Represents a (stateful) canvas decoder
- Canvas
Font Face - Representation of a font face
- Canvas
Graphics Context - Graphics context for a Canvas
- Coord2
- Represents a 2D point
- Draw
Stream - A draw stream relays
Draw
instructions from a source such as aCanvas
or aDrawContext
as a stream - Drawing
Target - A drawing target sends drawing instructions to a
DrawStream
- FontId
- Identifier for a font
- Font
Line Position - Describes where to position a line relative to some text
- Font
Metrics - Metrics for a font
- Font
Properties - The properties to use when selecting a font face
- GlyphId
- ID for a glyph within a font
- Glyph
Position - Describes how a glyph is positioned on the canvas
- Gradient
Id - Identifies a gradient
- LayerId
- Identifier of a canvas layer
- Sprite
Id - Identifier of a canvas ‘sprite’
- Text
Layout Metrics - The layout metrics for a piece of text
- Texture
Id - Identifier for a texture
- Transform2D
- Represents a 2D affine transformation matrix
Enums§
- Blend
Mode - Blend mode to use when drawing
- Color
- Representation of a colour
- Color
Format - Possible formats of a colour value
- Decoder
Error - Possible error from the decoder
- Draw
- Instructions for drawing to a canvas
- FontOp
- Operations that can be performed on a font
- Font
Style - The possible styles of a font
- Gradient
Op - Operations that can be applied to a gradient
- LineCap
- How to cap lines
- Line
Join - Possible way to join lines
- Path
Attribute - Attributes used to render a bezier path
- PathOp
- Operations that define paths
- Sprite
Transform - Transformation to apply to a canvas ‘sprite’
- Stream
Decoder Error - Error from either a decoder or the stream that’s feeding it
- Text
Alignment - Determines how text is drawn relative to its alignment’s origin point
- Texture
Format - Format of a rendering texture
- Texture
Op - Operations that can be performed on a texture
- Winding
Rule - How a path should determine if it’s an outer edge or not
Traits§
- Canvas
Encoding - Trait implemented by objects that can be encoded into a canvas
- Coordinate2D
- Represents a coordinate with a 2D position
- Graphics
Context - A graphics context provides the basic set of graphics actions that can be performed
- Graphics
Primitives - 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