2025-09-18 14:05:44 -06:00
|
|
|
#[allow(non_upper_case_globals)]
|
|
|
|
|
|
|
|
|
|
mod fonts;
|
2025-09-19 10:47:08 -06:00
|
|
|
mod parser;
|
|
|
|
|
mod bitmap;
|
2025-09-18 14:05:44 -06:00
|
|
|
|
2025-09-19 10:47:08 -06:00
|
|
|
use std::{rc::Rc, time::Instant};
|
|
|
|
|
|
|
|
|
|
use fontdue::{layout::{CoordinateSystem, Layout, LayoutSettings}};
|
|
|
|
|
|
|
|
|
|
use crate::{bitmap::Bitmap, parser::{KElement}};
|
2025-09-18 14:05:44 -06:00
|
|
|
|
|
|
|
|
fn main() -> Result<(), std::fmt::Error> {
|
2025-09-19 10:47:08 -06:00
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
|
|
let mut rustex = RusTeX::new(TeXSettings { scale: 100. });
|
|
|
|
|
|
|
|
|
|
let element = KElement::LinearGroup(vec![
|
|
|
|
|
KElement::Fraction(
|
|
|
|
|
Rc::new(KElement::Integer(123)),
|
|
|
|
|
Rc::new(KElement::Integer(12))
|
|
|
|
|
),
|
|
|
|
|
// KElement::Integer(12),
|
|
|
|
|
// KElement::Integer(12),
|
|
|
|
|
KElement::Decimal(12.34),
|
|
|
|
|
KElement::Fraction(
|
|
|
|
|
Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Integer(12)))),
|
|
|
|
|
Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Fraction(Rc::new(KElement::Integer(123)),Rc::new(KElement::Decimal(1234.5678)))))))))))))))),
|
|
|
|
|
),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// rustex.add_text(&TextStyle::new("testi12345ng! e^23", 100.0, 0));
|
|
|
|
|
let bitmap = rustex.rasterize(element);
|
|
|
|
|
|
|
|
|
|
println!("Rasterizing time: {:?}", start.elapsed());
|
|
|
|
|
|
|
|
|
|
bitmap.print();
|
|
|
|
|
|
|
|
|
|
// print_bitmap(&bitmap, width, height);
|
|
|
|
|
|
2025-09-18 14:05:44 -06:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct RusTeX {
|
2025-09-19 10:47:08 -06:00
|
|
|
settings: TeXSettings,
|
|
|
|
|
layout: Layout
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TeXSettings {
|
|
|
|
|
scale: f32,
|
2025-09-18 14:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RusTeX {
|
2025-09-19 10:47:08 -06:00
|
|
|
pub fn new(settings: TeXSettings) -> Self {
|
2025-09-18 14:05:44 -06:00
|
|
|
let mut layout = Layout::new(CoordinateSystem::PositiveYDown);
|
2025-09-19 10:47:08 -06:00
|
|
|
|
2025-09-18 14:05:44 -06:00
|
|
|
layout.reset(&LayoutSettings {
|
|
|
|
|
..LayoutSettings::default()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Self {
|
2025-09-19 10:47:08 -06:00
|
|
|
settings,
|
2025-09-18 14:05:44 -06:00
|
|
|
layout,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 10:47:08 -06:00
|
|
|
// pub fn add_text_style(&mut self, text_style: &TextStyle) {
|
|
|
|
|
// // self.layout.append(&fonts::FONTS, text_style);
|
|
|
|
|
// }
|
2025-09-18 14:05:44 -06:00
|
|
|
|
2025-09-19 10:47:08 -06:00
|
|
|
pub fn rasterize(&mut self, root_element: KElement) -> Bitmap {
|
|
|
|
|
root_element.rasterize(&mut self.layout, self.settings.scale)
|
2025-09-18 14:05:44 -06:00
|
|
|
}
|
|
|
|
|
}
|