Crates.io | vdtfont |
lib.rs | vdtfont |
version | 0.3.2 |
source | src |
created_at | 2023-04-08 18:52:40.948295 |
updated_at | 2023-04-20 18:34:53.435602 |
description | A library for converting glyphs into triangulations |
homepage | |
repository | https://github.com/alexanderved/vdtfont |
max_upload_size | |
id | 833741 |
size | 204,270 |
A novel library for converting glyphs into triangulations which can be used when rendering text in Game and Application interfaces.
use vdtfont::{*, delaunay::*};
// Create a font
let font_data = include_bytes!("/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf");
let mut font = Font::from_vec(font_data.to_vec())?;
// Obtain a glyph
let glyph = font.glyph('a');
// Outline the glyph
let outlined_glyph = font.outline_glyph(glyph);
// Triangulate th glyph
let triangulated_glyph = font.triangulate_glyph(outlined_glyph)?;
// Use the resulting triangulation
triangulated_glyph
.triangles()
.handle_iter::<DelaunayTriangleHandle>(triangulated_glyph.points())
.for_each(|triangle_handle| {
// ...
})
Full documentaion: https://docs.rs/vdtfont
VDTFont uses OpenCL to build Voronoi diagram and compute Delaunay triangulation with points from the glyph. The triangulation of the glyph can be used for its rendering.
Full algorithm of triangulation is described in the paper "Computing Two-dimensional Delaunay Triangulation Using Graphics Hardware".
The original font_rasterizer wasn't competetive so it was decided to almost fully rewrite it.
A new library VDTFont doesn't use classical method of rasterizing every pixel, but triangulates glyphs using GPU.
On Debian 11:
Run the following Cargo command in your Rust project directory:
$ cargo add vdtfont
Or add the following line to your Cargo.toml:
vdtfont = "0.3.2"
Run the following Cargo command in the project directory:
$ cargo build --release
Run the following command:
# build it
$ cargo build --release --example simple
# run it
$ ./target/release/examples/simple
Enter any symbol (CTRL + C to exit):
r
The image of the symbol was saved in r.png