-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pff2: Separate Bitmap struct for better indexing
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
1 parent
6d66890
commit 1116234
Showing
6 changed files
with
449 additions
and
150 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.