svg-filters(codegen): add pretty and ugly printing

This commit is contained in:
Schrottkatze 2024-03-17 00:49:53 +01:00
parent bf60bdd814
commit d87033d320
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc

View file

@ -43,10 +43,25 @@ impl SvgDocument {
self.filters.get_mut(&id.to_string()).unwrap() self.filters.get_mut(&id.to_string()).unwrap()
} }
pub fn generate_svg_pretty(&self) -> String {
let mut result = Vec::new();
let doc_writer = quick_xml::Writer::new_with_indent(&mut result, b' ', 2);
self.generate(doc_writer);
String::from_utf8_lossy(&result).to_string()
}
pub fn generate_svg(&self) -> String { pub fn generate_svg(&self) -> String {
let mut result = Vec::new(); let mut result = Vec::new();
let mut doc_writer = quick_xml::Writer::new_with_indent(&mut result, b' ', 2); let doc_writer = quick_xml::Writer::new(&mut result);
self.generate(doc_writer);
String::from_utf8_lossy(&result).to_string()
}
fn generate(&self, mut doc_writer: quick_xml::Writer<&mut Vec<u8>>) {
doc_writer doc_writer
.create_element("svg") .create_element("svg")
.write_inner_content(|writer| { .write_inner_content(|writer| {
@ -55,8 +70,6 @@ impl SvgDocument {
.try_fold(writer, Self::gen_filter) .try_fold(writer, Self::gen_filter)
.map(|_| {}) .map(|_| {})
}); });
String::from_utf8_lossy(&result).to_string()
} }
fn gen_filter<'w, 'r>( fn gen_filter<'w, 'r>(