main
Elnu 1 year ago
parent 0ad5b4df3b
commit 7c27f869c9

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

@ -1,6 +1,9 @@
use super::SVGUnit; use super::SVGUnit;
use std::fmt; 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 struct SVGMeasure {
pub measure: f64, pub measure: f64,
@ -49,4 +52,4 @@ impl Div<f64> for SVGMeasure {
fn div(self, scalar: f64) -> SVGMeasure { fn div(self, scalar: f64) -> SVGMeasure {
SVGMeasure::new(self.measure / scalar, self.unit) SVGMeasure::new(self.measure / scalar, self.unit)
} }
} }

@ -2,4 +2,4 @@ mod unit;
pub use unit::SVGUnit; pub use unit::SVGUnit;
mod measure; mod measure;
pub use measure::SVGMeasure; pub use measure::SVGMeasure;

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

Loading…
Cancel
Save