text2art 1.0.2

Simple library for translate text to ascii art.
Documentation

Status Crates.io downloads Crates.io downloads License



text2art = "1.0.2"

cargo run --example basic_usage

Code

use text2art::BasicFonts;
use text2art::Font;
use text2art::Printer;

fn main() {
    let font = match Font::from_basic(BasicFonts::Big) {
        Ok(font) => font,
        Err(_) => panic!("something wrong with font"),
    };
    let prntr = Printer::with_font(font);
    prntr.print_to_stdio("Welcome to tex2art! :)").ok();

    prntr.print_to_stdio("text for print_to_stdio").ok();
    prntr
        .print_to("text for print_to", &mut std::io::stdout())
        .ok();

    let rendered_text = prntr.render_text("text for render");
    match rendered_text {
        Ok(rendered_text) => println!("{}", rendered_text),
        Err(_) => println!("Something went wrong!"),
    }
}

Output


You can use your font from str or file. You can use these functions

pub fn from_basic(font: basic_fonts::BasicFonts) -> Result<Font, FontError>
pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Font, FontError>

Font rules:

  1. Constant line width. All lines intro one grapheme should be with equal width
  2. Font line must be in format. Font must contain 3 segments: grapheme, shift and data.

For example:

Where:

  1. Use "\n" for line segmentation For example:

Will be implemented as

  1. Use shift if it needed. With shift you can move you grapheme up or down. All graphemes align on the zero line. Examples from big font below.

Grapheme without shift

Grapheme with negative shift

Grapheme with positive shift

All examples in one structure

  1. You can leave comments. Use '#' for comments.

For example: