38 releases

new 0.4.3 Nov 17, 2024
0.4.1 Aug 11, 2024
0.4.0 Apr 1, 2024
0.3.12 Mar 31, 2024
0.1.2 Apr 30, 2021

#26 in Rendering

Download history 4/week @ 2024-08-03 110/week @ 2024-08-10 10/week @ 2024-08-17 6/week @ 2024-08-24 6/week @ 2024-08-31 10/week @ 2024-09-07 38/week @ 2024-09-14 54/week @ 2024-09-21 24/week @ 2024-09-28 10/week @ 2024-10-05 9/week @ 2024-10-12 14/week @ 2024-10-19 162/week @ 2024-10-26 33/week @ 2024-11-02 29/week @ 2024-11-09 113/week @ 2024-11-16

340 downloads per month
Used in surf_n_term

MIT license

285KB
7.5K SLoC

Rasterizer

Build Status MIT License Crate API Docs

This is a fully functional 2D rasterizer and SVG path parser.

Features:

  • parsing SVG path format
  • rendering elliptic arc, lines, cubic/quadratic bezier curves
  • curve offsetting
  • linear and radial gradients

Usage example

There is a very simple binary in examples folder that can be used to render SVG path

$ cargo run --release --example rasterize -- data/squirrel.path -w 512 -o squirrel.bmp

This will produce:

squirrel


lib.rs:

Simple 2D library that support SVG path parsing/generation/manipulation and rasterization.

Main features:

  • SVG path parsing and generation
  • Anti-aliased rendering
  • Path offsetting Path::stroke
  • Linear and Radial gradients with GradLinear and GradRadial
  • Serde integration if serde feature is set (enabled by default)

Overview

Main types are:

  • Path - Represents the same concept as an SVG path, the easiest way to construct it is with Path::builder or it can be parsed from SVG path with str::parse. Path can be stroked with Path::stroke to generated new path that represents an outline.
  • Scene - Represents an image that has not been rendered yet, multiple scenes can be composed to construct more complex scene. This is probably the simplest way to render something useful. See examples/simple.rs for a simple example. It can also be (de)serialized see data/firefox.scene for an example.
  • Paint - Color/Gradient that can be used to fill a path.
  • Image - 2D matrix that can hold and image and used as a target for rendering. Image can also be written into a file with Image::write_bmp or to PNG with Image::write_png if png feature is enabled.

Dependencies

~0.8–2MB
~37K SLoC