Skip to main content

vector_text_core/
lib.rs

1#![no_std]
2
3//! `vector-text-core` provides core primitives for the `vector-text` crate.
4
5use alloc::vec::Vec;
6
7extern crate alloc;
8
9/// A point, in compact representation.
10/// Used to store the points which make up an individual glyph.
11#[derive(Debug, Copy, Clone)]
12pub struct PackedPoint {
13    /// X coordinate of this point
14    pub x: i8,
15    /// Y coordinate of this point
16    pub y: i8,
17    /// Should a line be drawn (i.e., "pen down") when moving to this point?
18    pub pen: bool,
19}
20
21/// A single glyph (character) contained within a font.
22#[derive(Debug, Copy, Clone)]
23pub struct Glyph {
24    /// Left coordinate boundary of this glyph
25    pub left: i8,
26    /// Right coordinate boundary of this glyph
27    pub right: i8,
28    /// Series of points which make up this glyph
29    pub strokes: &'static [PackedPoint],
30}
31
32/// Representation of a point with higher range than [PackedPoint].
33/// Used for the output of text rendering.
34pub struct Point {
35    pub x: i16,
36    pub y: i16,
37    pub pen: bool,
38}
39
40impl Default for Point {
41    fn default() -> Self {
42        Self {
43            x: 0,
44            y: 0,
45            pen: false,
46        }
47    }
48}
49
50/// Allows rendering text into vector points.
51///
52/// Implementors may define their own font mapping (enum or other data structure).
53pub trait Renderer<Mapping> {
54    /// Render the given text string to a series of points,
55    /// using the given font mapping.
56    fn render_text(text: &str, mapping: Mapping) -> Vec<Point>;
57}