Skip to content

Commit

Permalink
pff2: Separate Bitmap struct for better indexing
Browse files Browse the repository at this point in the history
The bitmap and its properties have been moved to a separate struct,
so that it can implement iterators for easier rendering of the bitmap
  • Loading branch information
max-ishere committed Feb 7, 2024
1 parent 6d66890 commit 1116234
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 150 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.18", features = ["derive"] }
log = "0.4.20"
nom = "7.1.3"
thiserror = "1.0.56"

[dev-dependencies]
test-case = "3.3.1"
anyhow = "1.0.79"
44 changes: 25 additions & 19 deletions examples/pff2.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
//! A minimal font.pf2 parser impl that prints the parsed Rust struct
//! A minimal font.pf2 parser impl that prints a glyph from a PFF2 font
use std::fs::read;
use std::{fs::read, path::PathBuf};

use args::Args;
use clap::Parser as _;
use theme_parser::parser::pff2::Parser;
use theme_parser::parser::pff2::{Glyph, Parser};

mod args {
use std::path::PathBuf;
#[derive(clap::Parser)]
struct Args {
#[clap(long, short = 'f')]
pub font_file: PathBuf,

use clap::Parser;

#[derive(Parser)]
pub struct Args {
#[clap(long, short = 'f')]
pub font_file: PathBuf,
}
#[clap(long = "char", short)]
pub character: char,
}

const SQUARE_BLOCK: &str = "\u{2588}\u{2588}";

fn main() -> anyhow::Result<()> {
let args = Args::parse();

let data = read(args.font_file)?;
let font = Parser::parse(&data)?.validate();
let font = Parser::parse(&data)?.validate()?;

println!("{}", font.name);

let print = format!("{font:#?}")
.split("\n")
.take(100)
.fold(String::new(), |print, line| print + line + "\n");
let glyph = font.glyph(args.character).unwrap();

println!("{print}");
render_glyph(glyph);

Ok(())
}

fn render_glyph(glyph: &Glyph) {
for row in &glyph.bitmap {
for col in row {
print!("{}", if col { SQUARE_BLOCK } else { " " });
}
println!();
}
}
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ use std::rc::Rc;
#[macro_use]
extern crate test_case;

#[macro_use]
extern crate log;

extern crate thiserror;

pub mod parser {
pub mod pff2;
pub mod theme_txt;
}

pub mod render {
pub mod pff2;
}

pub type OwnedSlice<T> = Rc<T>;

trait Sealed {}
Loading

0 comments on commit 1116234

Please sign in to comment.