|
@@ -3,6 +3,9 @@ use std::fs::{self, OpenOptions};
|
|
|
use std::io::{self, Write};
|
|
|
use std::path::Path;
|
|
|
|
|
|
+mod xml;
|
|
|
+use xml::XMLWriter;
|
|
|
+
|
|
|
const MAX_OUTPUT_FILES: u32 = 500;
|
|
|
|
|
|
/// An SVG document, which has a fixed size (computed in inches) as
|
|
@@ -24,57 +27,6 @@ impl Display for Inches {
|
|
|
|
|
|
fn inches(amt: f64) -> Inches { Inches { amt } }
|
|
|
|
|
|
-pub struct XMLWriter<'a>{
|
|
|
- writer: &'a mut Write,
|
|
|
-}
|
|
|
-
|
|
|
-impl<'a> XMLWriter<'a> {
|
|
|
- pub fn start(buf: &'a mut Write) -> io::Result<XMLWriter<'a>> {
|
|
|
- writeln!(buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>")?;
|
|
|
- Ok(XMLWriter { writer: buf })
|
|
|
- }
|
|
|
-
|
|
|
- /// create an entire closed tag with the given attributes
|
|
|
- pub fn tag(&mut self, name: &str, attrs: &[(&str, &Display)]) -> io::Result<()> {
|
|
|
- write!(self.writer, "<{}", name)?;
|
|
|
- for &(k, v) in attrs {
|
|
|
- write!(self.writer, " {}=\"{}\"", k, v)?;
|
|
|
- }
|
|
|
- writeln!(self.writer, "/>")?;
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- /// create an open tag with the given attributes
|
|
|
- pub fn open(&mut self, name: &str, attrs: &[(&str, &Display)]) -> io::Result<()> {
|
|
|
- write!(self.writer, "<{}", name)?;
|
|
|
- for &(k, v) in attrs {
|
|
|
- write!(self.writer, " {}=\"{}\"", k, v)?;
|
|
|
- }
|
|
|
- writeln!(self.writer, ">")?;
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- /// close a tag with the given attributes
|
|
|
- pub fn close(&mut self, name: &str) -> io::Result<()> {
|
|
|
- write!(self.writer, "</{}>", name)?;
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
- pub fn block<F>(&mut self, name: &str, attrs: &[(&str, &Display)], cb: F) -> io::Result<()>
|
|
|
- where F: FnOnce(&mut XMLWriter<'a>) -> io::Result<()>
|
|
|
- {
|
|
|
- write!(self.writer, "<{}", name)?;
|
|
|
- for &(k, v) in attrs {
|
|
|
- write!(self.writer, " {}=\"{}\"", k, v)?;
|
|
|
- }
|
|
|
- writeln!(self.writer, ">")?;
|
|
|
- cb(self)?;
|
|
|
- write!(self.writer, "</{}>", name)?;
|
|
|
- Ok(())
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
/// Create a new empty SVG document of the specified width and height
|
|
|
pub fn svg(w: f64, h: f64) -> SVG {
|
|
|
SVG {
|
|
@@ -251,7 +203,7 @@ impl AsSVG for Rect {
|
|
|
("width", &w),
|
|
|
("height", &h),
|
|
|
("stroke", &"black"),
|
|
|
- ("fill", &"white"),
|
|
|
+ ("fill", &"none"),
|
|
|
]
|
|
|
)
|
|
|
}
|
|
@@ -281,7 +233,7 @@ impl AsSVG for Circle {
|
|
|
("cy", &y),
|
|
|
("r", &r),
|
|
|
("stroke", &"black"),
|
|
|
- ("fill", &"white"),
|
|
|
+ ("fill", &"none"),
|
|
|
]
|
|
|
)
|
|
|
}
|