main
Elnu 1 year ago
parent 0ad5b4df3b
commit 7c27f869c9

@ -1,9 +1,9 @@
pub mod svg;
use svg::*;
use std::{fs::OpenOptions, io::Write};
use askama::Template;
use derive_more::From;
use std::{fs::OpenOptions, io::Write};
#[derive(Template)]
#[template(path = "document.xml")]
@ -25,8 +25,8 @@ fn main() -> Result<(), Error> {
.create(true)
.open("output.svg")?;
let document = DocumentTemplate {
width: SVGMeasure::new(8.5, SVGUnit::Inch),
height: SVGMeasure::new(11.0,SVGUnit::Inch),
width: SVGMeasure::new(8.5, SVGUnit::Inch),
height: SVGMeasure::new(11.0, SVGUnit::Inch),
};
write!(file, "{}", document.render()?)?;
Ok(())

@ -1,6 +1,9 @@
use super::SVGUnit;
use std::fmt;
use std::{ops::{Add, Sub, Mul, Div}, fmt::Display};
use std::{
fmt::Display,
ops::{Add, Div, Mul, Sub},
};
pub struct SVGMeasure {
pub measure: f64,

@ -35,21 +35,25 @@ pub enum SVGUnit {
impl Display for SVGUnit {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use SVGUnit::*;
write!(f, "{}", match &self {
Pixel => "px",
Inch => "in",
Centimeter => "cm",
Millimeter => "mm",
Point => "pt",
Pica => "pc",
Em => "em",
Ex => "ex",
Character => "ch",
Rem => "rem",
ViewportWidth => "vw",
ViewportHeight => "vh",
ViewportMinimum => "vmin",
ViewportMaximum => "vmax",
})
write!(
f,
"{}",
match &self {
Pixel => "px",
Inch => "in",
Centimeter => "cm",
Millimeter => "mm",
Point => "pt",
Pica => "pc",
Em => "em",
Ex => "ex",
Character => "ch",
Rem => "rem",
ViewportWidth => "vw",
ViewportHeight => "vh",
ViewportMinimum => "vmin",
ViewportMaximum => "vmax",
}
)
}
}
Loading…
Cancel
Save