Skip to main content

vector_text/
lib.rs

1#![no_std]
2
3//! `vector-text` is a library for drawing text to a vector output
4//! using various vector-based fonts.
5//!
6//! This can be used for drawing text to plotters, with laser displays, on
7//! XY oscilloscopes, or for other purposes!
8//!
9//! The library supports `no_std` environments but requires an allocator.
10//!
11//! Supported fonts include:
12//! - [BGI (Borland)](https://moddingwiki.shikadi.net/wiki/BGI_Stroked_Font) fonts including `LITT.CHR`, via [vector_text_borland]
13//! - [Hershey](https://paulbourke.net/dataformats/hershey/) fonts, via [vector_text_hershey]
14//! - The [NewStroke](https://vovanium.ru/sledy/newstroke/en) font, via [vector_text_newstroke]
15//!
16//! This library provides the render_text function which you can use to render text, e.g.:
17//!
18//! ```
19//! use vector_text::{render_text, VectorFont, HersheyFont};
20//!
21//! let result = render_text("Hello World!", VectorFont::HersheyFont(HersheyFont::Romans));
22//! ```
23
24use alloc::vec::Vec;
25pub use vector_text_borland::BorlandFont;
26pub use vector_text_core::Point;
27use vector_text_core::Renderer;
28pub use vector_text_hershey::HersheyFont;
29
30extern crate alloc;
31
32/// A font using any of the supported vector font formats.
33pub enum VectorFont {
34    HersheyFont(HersheyFont),
35    BorlandFont(BorlandFont),
36    NewstrokeFont(()),
37}
38
39/// Render the given text string to a list of points using the specified font.
40pub fn render_text(text: &str, font: VectorFont) -> Vec<Point> {
41    match font {
42        VectorFont::HersheyFont(font) => {
43            vector_text_hershey::HersheyRenderer::render_text(text, font)
44        }
45        VectorFont::BorlandFont(font) => {
46            vector_text_borland::BorlandRenderer::render_text(text, font)
47        }
48        VectorFont::NewstrokeFont(font) => {
49            vector_text_newstroke::NewstrokeRenderer::render_text(text, font)
50        }
51    }
52}