diff --git a/bingus/src/doc.rs b/bingus/src/doc.rs index 632450e..abcf649 100644 --- a/bingus/src/doc.rs +++ b/bingus/src/doc.rs @@ -1,2 +1,2 @@ -pub use printpdf::PdfDocument; +pub use printpdf; mod pdf; diff --git a/bong/Cargo.toml b/bong/Cargo.toml index 59d66eb..4a4018a 100644 --- a/bong/Cargo.toml +++ b/bong/Cargo.toml @@ -11,5 +11,6 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0.97" bingus = { path = "../bingus" } clap = { version = "4.5.32", features = ["derive"] } diff --git a/bong/src/main.rs b/bong/src/main.rs index 85a68a8..fab8ebf 100644 --- a/bong/src/main.rs +++ b/bong/src/main.rs @@ -1,31 +1,27 @@ +use std::fs::File; + +use anyhow::{anyhow, Context, Error}; use bingus::{ - img::{Dimensions, RgbImage}, - snd::RawSamples, - Bendable, DynamicBendable, OpenError, + doc::printpdf::{FontId, Op, PdfDocument, TextItem}, + Bendable, }; use clap::Parser; use cli::Cli; mod cli; -fn main() -> Result<(), OpenError> { +fn main() -> Result<(), Error> { let args = Cli::parse(); - if let DynamicBendable::Image(i) = - bingus::open(args.input_file)?.expect("could not open this file.") - { - let dimensions = Dimensions { - width: i.width(), - height: i.height(), - }; - RawSamples::::bend_from(i, (), bingus::Crop::End) - .unwrap() - .map(|s| s.abs_diff(s.wrapping_neg())) - .bend_into::(dimensions, bingus::Crop::End) - .unwrap() - .save(args.output_file) - .unwrap(); - } else { - println!("Not an image! Sorry!"); - } + File::open(args.input_file) + .context("opening file")? + .bend_into::((), Default::default()) + .map_err(|e| anyhow!("parsing PDF: {e}"))? + .map(|t| Op::WriteText { + items: vec![TextItem::Text(String::from("h"))], + font: FontId::new(), + }) + .bend_into::(Box::new(args.output_file), Default::default()) + .context("saving output file")?; + Ok(()) }