SVG backend cannot print second part #744
Replies: 1 comment 1 reply
|
The thing tripping you up is that For SVG that is a one-way door: fn present(&mut self) -> Result<(), DrawingErrorKind<Error>> {
if !self.saved {
while self.close_tag() {}
match self.target {
Target::File(ref buf, path) => { /* write buf to path */ }
Target::Buffer(_) => {}
}
self.saved = true;
}
Ok(())
}Every open tag gets closed, the buffer as it stands is written to The difference from // bitmap
fn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind<BitMapBackendError>> {
self.saved = false;
Ok(())
}
// svg
fn ensure_prepared(&mut self) -> Result<(), DrawingErrorKind<Error>> {
Ok(())
}Both backends use the same It also explains the part you found puzzling, that commenting the call out fixes it. The backend saves itself on the way out: impl Drop for SVGBackend<'_> {
fn drop(&mut self) {
if !self.saved {
let _ = self.present();
}
}
}With no explicit call, nothing latches early, and the complete document lands on disk when the backend drops. So the fix is just to present once, after all the drawing is done, on the root area rather than on the pieces — or to leave it out entirely and let the drop handler do it. The same applies to your bitmap block; it works there by accident of that one flag reset rather than because the two-present pattern is right. |

The thing tripping you up is that
present()is not a per-area operation.topandbottomare two views onto the same backend, sotop.present()does not present the top half — it finalises the entire SVG document, before you have drawn the bottom one.For SVG that is a one-way door:
Every open tag gets closed, the buffer as it stands is written to
new.svg, andsavedlatches to true. Your…