[librsvg/wip/rust-api: 4/11] Add a CairoRenderer and an SvgHandle::get_cairo_renderer() method
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/rust-api: 4/11] Add a CairoRenderer and an SvgHandle::get_cairo_renderer() method
- Date: Sat, 16 Feb 2019 01:34:45 +0000 (UTC)
commit 8bb244d276c66e2d73ebcabd6b664935bf6cd319
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Feb 13 16:18:09 2019 -0600
Add a CairoRenderer and an SvgHandle::get_cairo_renderer() method
librsvg_crate/src/lib.rs | 34 +++++++++++++++++++++++++++++++++-
rsvg_internals/src/lib.rs | 2 +-
2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index 35ab5800..f457e221 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -1,4 +1,5 @@
#![warn(unused)]
+extern crate cairo;
extern crate gio;
extern crate glib;
extern crate rsvg_internals;
@@ -9,7 +10,7 @@ use std::path::Path;
use gio::FileExt;
use glib::object::Cast;
-use rsvg_internals::{Handle, LoadFlags};
+use rsvg_internals::{Dpi, Handle, LoadFlags};
use url::Url;
pub use rsvg_internals::{LoadingError, RenderingError};
@@ -86,3 +87,34 @@ impl LoadOptions {
}
pub struct SvgHandle(Handle);
+
+pub struct CairoRenderer<'a> {
+ handle: &'a SvgHandle,
+ dpi: Dpi,
+}
+
+// Note that these are different than the C API's default, which is 90.
+const DEFAULT_DPI_X: f64 = 96.0;
+const DEFAULT_DPI_Y: f64 = 96.0;
+
+impl SvgHandle {
+ pub fn get_cairo_renderer(&self) -> CairoRenderer {
+ CairoRenderer {
+ handle: self,
+ dpi: Dpi::new(DEFAULT_DPI_X, DEFAULT_DPI_Y),
+ }
+ }
+}
+
+impl<'a> CairoRenderer<'a> {
+ pub fn set_dpi(&mut self, dpi_x: f64, dpi_y: f64) {
+ assert!(dpi_x > 0.0);
+ assert!(dpi_y > 0.0);
+
+ self.dpi = Dpi::new(dpi_x, dpi_y);
+ }
+
+ pub fn render(&self, cr: &cairo::Context) -> Result<(), RenderingError> {
+ self.handle.0.render_cairo_sub(cr, None)
+ }
+}
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index ffc1bf33..b6dbac2c 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -42,7 +42,7 @@ pub use c_api::{
pub use color::{rsvg_css_parse_color, ColorKind, ColorSpec};
-pub use dpi::rsvg_rust_set_default_dpi_x_y;
+pub use dpi::{rsvg_rust_set_default_dpi_x_y, Dpi};
pub use error::{LoadingError, RenderingError};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]