[librsvg/librsvg-2.46] librsvg_crate: Make all the examples runnable as tests
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/librsvg-2.46] librsvg_crate: Make all the examples runnable as tests
- Date: Thu, 21 Nov 2019 17:00:55 +0000 (UTC)
commit 0b425b78ec83518e92387ced00cb6087d6552325
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Oct 31 09:40:19 2019 -0600
librsvg_crate: Make all the examples runnable as tests
... and fix obsolete APIs / incorrect ones :facepalm:
Makefile.am | 3 ++-
librsvg_crate/Cargo.toml | 2 +-
librsvg_crate/src/lib.rs | 67 ++++++++++++++++++++++++++++--------------------
3 files changed, 42 insertions(+), 30 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e90e5b16..b31c8a1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -104,9 +104,10 @@ LIBRSVG_INTERNALS_SRC = \
rsvg_internals/src/xml2_load.rs \
$(NULL)
-LIBRSVG_CRATE_SRC = \
+LIBRSVG_CRATE_SRC = \
librsvg_crate/Cargo.toml \
librsvg_crate/build.rs \
+ librsvg_crate/example.svg \
librsvg_crate/examples/proportional.rs \
librsvg_crate/src/lib.rs \
librsvg_crate/tests/api.rs \
diff --git a/librsvg_crate/Cargo.toml b/librsvg_crate/Cargo.toml
index 4cc4c242..5f6d752e 100644
--- a/librsvg_crate/Cargo.toml
+++ b/librsvg_crate/Cargo.toml
@@ -17,7 +17,7 @@ rsvg_internals = { path = "../rsvg_internals" }
url = "2"
[dev-dependencies]
-cairo-rs = { version = "0.7.0", features = ["png", "svg"] }
+cairo-rs = { version = "0.7.0", features = ["png", "pdf", "svg"] }
rsvg_internals = { path = "../rsvg_internals" }
[build-dependencies]
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index c12915e2..f3b8664d 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -85,7 +85,7 @@
//! entities. For example, say you have an SVG in <filename>/foo/bar/foo.svg</filename>
//! and that it has an image element like this:
//!
-//! ```ignore
+//! ```xml
//! <image href="resources/foo.png" .../>
//! ```
//!
@@ -195,12 +195,10 @@ impl Loader {
///
/// # Example:
///
- /// ```ignore
+ /// ```
/// use librsvg;
///
- /// use librsvg::Loader;
- ///
- /// let svg_handle = Loader::new()
+ /// let svg_handle = librsvg::Loader::new()
/// .read_path("example.svg")
/// .unwrap();
/// ```
@@ -221,14 +219,12 @@ impl Loader {
/// Set this to `true` only if loading a trusted SVG fails due to size limits.
///
/// # Example:
- /// ```ignore
+ /// ```
/// use librsvg;
///
- /// use librsvg::Loader;
- ///
- /// let svg_handle = Loader::new()
+ /// let svg_handle = librsvg::Loader::new()
/// .with_unlimited_size()
- /// .read_path("trusted-huge-file.svg")
+ /// .read_path("example.svg") // presumably a trusted huge file
/// .unwrap();
/// ```
pub fn with_unlimited_size(mut self) -> Self {
@@ -249,22 +245,24 @@ impl Loader {
/// of context which allows embedding compressed images.
///
/// # Example:
- /// ```ignore
+ ///
+ /// ```
/// use cairo;
/// use librsvg;
///
- /// use librsvg::Loader;
- ///
- /// let svg_handle = Loader::new()
+ /// let svg_handle = librsvg::Loader::new()
/// .keep_image_data()
- /// .read_path("svg-with-embedded-images.svg")
+ /// .read_path("example.svg")
/// .unwrap();
///
- /// let surface = cairo::pdf::File::new(..., "hello.pdf");
+ /// let surface = cairo::PdfSurface::new(640.0, 480.0, "output.pdf");
/// let cr = cairo::Context::new(&surface);
///
- /// let renderer = CairoRenderer::new(&svg_handle);
- /// renderer.render(&cr).unwrap();
+ /// let renderer = librsvg::CairoRenderer::new(&svg_handle);
+ /// renderer.render_document(
+ /// &cr,
+ /// &cairo::Rectangle { x: 0.0, y: 0.0, width: 640.0, height: 480.0 },
+ /// ).unwrap();
/// ```
pub fn keep_image_data(mut self) -> Self {
self.keep_image_data = true;
@@ -274,13 +272,12 @@ impl Loader {
/// Reads an SVG file from `path`.
///
/// # Example:
- /// ```ignore
- /// use librsvg;
///
- /// use librsvg::Loader;
+ /// ```
+ /// use librsvg;
///
- /// let svg_handle = Loader::new()
- /// .read_path("hello.svg")
+ /// let svg_handle = librsvg::Loader::new()
+ /// .read_path("example.svg")
/// .unwrap();
/// ```
pub fn read_path<P: AsRef<Path>>(self, path: P) -> Result<SvgHandle, LoadingError> {
@@ -293,14 +290,12 @@ impl Loader {
/// The `cancellable` can be used to cancel loading from another thread.
///
/// # Example:
- /// ```ignore
+ /// ```
/// use gio;
/// use librsvg;
///
- /// use librsvg::Loader;
- ///
- /// let svg_handle = Loader::new()
- /// .read_file(&gio::File::new_for_path("hello.svg"), None::<&gio::Cancellable>)
+ /// let svg_handle = librsvg::Loader::new()
+ /// .read_file(&gio::File::new_for_path("example.svg"), None::<&gio::Cancellable>)
/// .unwrap();
/// ```
pub fn read_file<F: IsA<gio::File>, P: IsA<Cancellable>>(
@@ -324,6 +319,22 @@ impl Loader {
/// URL where this SVG got loaded from.
///
/// The `cancellable` can be used to cancel loading from another thread.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use gio::prelude::*;
+ /// use gio;
+ /// use librsvg;
+ ///
+ /// let file = gio::File::new_for_path("example.svg");
+ ///
+ /// let stream = file.read(None::<&gio::Cancellable>).unwrap();
+ ///
+ /// let svg_handle = librsvg::Loader::new()
+ /// .read_stream(&stream, Some(&file), None::<&gio::Cancellable>)
+ /// .unwrap();
+ /// ```
pub fn read_stream<S: IsA<gio::InputStream>, F: IsA<gio::File>, P: IsA<Cancellable>>(
self,
stream: &S,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]