[librsvg/rustify-rsvg-convert: 24/78] rsvg-convert: set background color before rendering
- From: Sven Neumann <sneumann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert: 24/78] rsvg-convert: set background color before rendering
- Date: Wed, 3 Feb 2021 10:18:30 +0000 (UTC)
commit 1aa511bcedabc5a2ea150ac7e5dc3d21c8cdac51
Author: Sven Neumann <sven svenfoo org>
Date: Mon Nov 2 20:41:09 2020 +0100
rsvg-convert: set background color before rendering
src/bin/rsvg-convert/main.rs | 14 +++++++++++++-
src/bin/rsvg-convert/surface.rs | 14 ++++++++------
2 files changed, 21 insertions(+), 7 deletions(-)
---
diff --git a/src/bin/rsvg-convert/main.rs b/src/bin/rsvg-convert/main.rs
index 27997250..cf21a830 100644
--- a/src/bin/rsvg-convert/main.rs
+++ b/src/bin/rsvg-convert/main.rs
@@ -6,6 +6,7 @@ mod input;
mod output;
mod surface;
+use cssparser::Color;
use librsvg::{CairoRenderer, Loader, RenderingError};
use crate::cli::Args;
@@ -66,8 +67,19 @@ fn main() {
}
if let Some(ref surface) = target {
+ let cr = cairo::Context::new(surface);
+
+ if let Some(Color::RGBA(rgba)) = args.background_color {
+ cr.set_source_rgba(
+ rgba.red_f32().into(),
+ rgba.green_f32().into(),
+ rgba.blue_f32().into(),
+ rgba.alpha_f32().into(),
+ );
+ }
+
surface
- .render(&renderer, args.export_id())
+ .render(&renderer, &cr, args.export_id())
.unwrap_or_else(|e| match e {
RenderingError::InvalidId(_) => exit!(
"File {} does not have an object with id \"{}\")",
diff --git a/src/bin/rsvg-convert/surface.rs b/src/bin/rsvg-convert/surface.rs
index e834c349..616fc6ad 100644
--- a/src/bin/rsvg-convert/surface.rs
+++ b/src/bin/rsvg-convert/surface.rs
@@ -88,13 +88,15 @@ impl Surface {
}
}
- pub fn render(&self, renderer: &CairoRenderer, id: Option<&str>) -> Result<(), RenderingError> {
- let cr = cairo::Context::new(self);
- let viewport = self.bounds();
- let show_page = |_| self.show_page(&cr);
-
+ pub fn render(
+ &self,
+ renderer: &CairoRenderer,
+ cr: &cairo::Context,
+ id: Option<&str>,
+ ) -> Result<(), RenderingError> {
+ let show_page = |_| self.show_page(cr);
renderer
- .render_layer(&cr, id, &viewport)
+ .render_layer(cr, id, &self.bounds())
.and_then(show_page)
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]