[librsvg] 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_crate: Make all the examples runnable as tests
- Date: Thu, 31 Oct 2019 15:41:19 +0000 (UTC)
commit 477837fee8fb216e3cf5a9484db5604bda8967b0
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/example.svg | 1 +
librsvg_crate/src/lib.rs | 67 +++++++++++++++++++++++++++--------------------
4 files changed, 43 insertions(+), 30 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 1e27115d..5d8293d2 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 5d369d7b..9a0750ff 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/example.svg b/librsvg_crate/example.svg
new file mode 100644
index 00000000..1a6c762d
--- /dev/null
+++ b/librsvg_crate/example.svg
@@ -0,0 +1 @@
+<svg height="144" width="144" xmlns="http://www.w3.org/2000/svg"><path d="m71.05 23.68c-26.06 0-47.27
21.22-47.27 47.27s21.22 47.27 47.27 47.27 47.27-21.22 47.27-47.27-21.22-47.27-47.27-47.27zm-.07 4.2a3.1 3.11
0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1 3.2-3.11zm7.12 5.12a38.27 38.27 0 0 1 26.2
18.66l-3.67 8.28c-.63 1.43.02 3.11 1.44 3.75l7.06 3.13a38.27 38.27 0 0 1 .08 6.64h-3.93c-.39
0-.55.26-.55.64v1.8c0 4.24-2.39 5.17-4.49 5.4-2 .23-4.21-.84-4.49-2.06-1.18-6.63-3.14-8.04-6.24-10.49
3.85-2.44 7.85-6.05 7.85-10.87 0-5.21-3.57-8.49-6-10.1-3.42-2.25-7.2-2.7-8.22-2.7h-40.6a38.27 38.27 0 0 1
21.41-12.08l4.79 5.02c1.08 1.13 2.87 1.18 4 .09zm-44.2 23.02a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22
0 3.11 3.11 0 0 1 3.2-3.11zm74.15.14a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1
3.2-3.11zm-68.29.5h5.42v24.44h-10.94a38.27 38.27 0 0 1 -1.24-14.61l6.7-2.98c1.43-.64 2.08-2.31
1.44-3.74zm22.62.26h12.91c.67 0 4.71.77 4.71 3.8 0 2.51-3.1 3.41-5.65 3
.41h-11.
98zm0 17.56h9.89c.9 0 4.83.26 6.08 5.28.39 1.54 1.26 6.56 1.85 8.17.59 1.8 2.98 5.4 5.53 5.4h16.14a38.27
38.27 0 0 1 -3.54 4.1l-6.57-1.41c-1.53-.33-3.04.65-3.37 2.18l-1.56 7.28a38.27 38.27 0 0 1
-31.91-.15l-1.56-7.28c-.33-1.53-1.83-2.51-3.36-2.18l-6.43 1.38a38.27 38.27 0 0 1 -3.32-3.92h31.27c.35 0
.59-.06.59-.39v-11.06c0-.32-.24-.39-.59-.39h-9.15zm-14.43 25.33a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1
-6.22 0 3.11 3.11 0 0 1 3.2-3.11zm46.05.14a3.11 3.11 0 0 1 3.02 3.11 3.11 3.11 0 0 1 -6.22 0 3.11 3.11 0 0 1
3.2-3.11z"/><path d="m115.68 70.95a44.63 44.63 0 0 1 -44.63 44.63 44.63 44.63 0 0 1 -44.63-44.63 44.63 44.63
0 0 1 44.63-44.63 44.63 44.63 0 0 1 44.63 44.63zm-.84-4.31 6.96 4.31-6.96 4.31 5.98 5.59-7.66 2.87 4.78
6.65-8.09 1.32 3.4 7.46-8.19-.29 1.88 7.98-7.98-1.88.29 8.19-7.46-3.4-1.32 8.09-6.65-4.78-2.87
7.66-5.59-5.98-4.31 6.96-4.31-6.96-5.59 5.98-2.87-7.66-6.65 4.78-1.32-8.09-7.46 3.4.29-8.19-7.98 1.88
1.88-7.98-8.19.29 3.4-7.46-8.09-1.32 4.78-6.65-7.66-2.87 5.98-5.5
9-6.96-4
.31 6.96-4.31-5.98-5.59 7.66-2.87-4.78-6.65 8.09-1.32-3.4-7.46 8.19.29-1.88-7.98 7.98 1.88-.29-8.19 7.46 3.4
1.32-8.09 6.65 4.78 2.87-7.66 5.59 5.98 4.31-6.96 4.31 6.96 5.59-5.98 2.87 7.66 6.65-4.78 1.32 8.09
7.46-3.4-.29 8.19 7.98-1.88-1.88 7.98 8.19-.29-3.4 7.46 8.09 1.32-4.78 6.65 7.66 2.87z" fill-rule="evenodd"
stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="3"/></svg>
\ No newline at end of file
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index df0d4747..a8eeaa37 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -27,7 +27,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" .../>
//! ```
//!
@@ -136,12 +136,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();
/// ```
@@ -162,14 +160,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 {
@@ -190,22 +186,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;
@@ -215,13 +213,12 @@ impl Loader {
/// Reads an SVG document 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> {
@@ -234,14 +231,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>>(
@@ -265,6 +260,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]