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;
26use vector_text_core::{Point, Renderer};
27pub use vector_text_hershey::HersheyFont;
28
29extern crate alloc;
30
31/// A font using any of the supported vector font formats.
32pub enum VectorFont {
33    HersheyFont(HersheyFont),
34    BorlandFont(BorlandFont),
35    NewstrokeFont(()),
36}
37
38/// Render the given text string to a list of points using the specified font.
39pub fn render_text(text: &str, font: VectorFont) -> Vec<Point> {
40    match font {
41        VectorFont::HersheyFont(font) => {
42            vector_text_hershey::HersheyRenderer::render_text(text, font)
43        }
44        VectorFont::BorlandFont(font) => {
45            vector_text_borland::BorlandRenderer::render_text(text, font)
46        }
47        VectorFont::NewstrokeFont(font) => {
48            vector_text_newstroke::NewstrokeRenderer::render_text(text, font)
49        }
50    }
51}