[librsvg/rustify-rsvg-convert: 69/78] rsvg-convert: Figure out support for Cairo surface backends
- From: Sven Neumann <sneumann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustify-rsvg-convert: 69/78] rsvg-convert: Figure out support for Cairo surface backends
- Date: Wed, 3 Feb 2021 10:18:31 +0000 (UTC)
commit 75219746cfd73a950d870a506c7da1a6b8017b64
Author: Sven Neumann <sven svenfoo org>
Date: Tue Jan 26 23:03:17 2021 +0100
rsvg-convert: Figure out support for Cairo surface backends
Use pkg-config to figure out at compile-time what surface backends
are supported by cairo. Change rsvg-convert to only allow supported
output formats.
build.rs | 27 +++++++++++++++++++++++++--
src/bin/rsvg-convert.rs | 15 ++++++++++++++-
2 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/build.rs b/build.rs
index 3a73d6bd..52081685 100644
--- a/build.rs
+++ b/build.rs
@@ -8,15 +8,20 @@ use std::process;
use pkg_config::{Config, Error};
+const CAIRO_REQUIRED_VERSION: &str = "1.16";
+const PANGO_REQUIRED_VERSION: &str = "1.38";
+const LIBXML_REQUIRED_VERSION: &str = "2.9.0";
+
fn main() {
find_libxml2();
check_for_pangoft2();
+ check_for_cairo_surface_backends();
generate_srgb_tables();
write_version();
}
fn find_libxml2() {
- if let Err(s) = find("libxml-2.0", "2.9.0", &["xml2"]) {
+ if let Err(s) = find("libxml-2.0", LIBXML_REQUIRED_VERSION, &["xml2"]) {
let _ = writeln!(io::stderr(), "{}", s);
process::exit(1);
}
@@ -73,7 +78,7 @@ fn find(package_name: &str, version: &str, shared_libs: &[&str]) -> Result<(), E
fn check_for_pangoft2() {
if pkg_config::Config::new()
- .atleast_version("1.38")
+ .atleast_version(PANGO_REQUIRED_VERSION)
.probe("pangoft2")
.is_ok()
{
@@ -81,6 +86,24 @@ fn check_for_pangoft2() {
}
}
+fn check_for_cairo_surface_backend(backend: &str) {
+ let pkg_name = ["cairo", backend].join("-");
+ if pkg_config::Config::new()
+ .atleast_version(CAIRO_REQUIRED_VERSION)
+ .probe(&pkg_name)
+ .is_ok()
+ {
+ println!("cargo:rustc-cfg=have_cairo_{}", backend);
+ }
+}
+
+fn check_for_cairo_surface_backends() {
+ let backends = ["pdf", "ps", "svg", "xml"];
+ for name in &backends {
+ check_for_cairo_surface_backend(name);
+ }
+}
+
/// Converts an sRGB color value to a linear sRGB color value (undoes the gamma correction).
///
/// The input and the output are supposed to be in the [0, 1] range.
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index a467175a..23202cd6 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -309,6 +309,7 @@ impl std::fmt::Display for Output {
}
arg_enum! {
+ // Keep this enum in sync with supported_formats in parse_args()
#[derive(Clone, Copy, Debug)]
enum Format {
Png,
@@ -459,6 +460,18 @@ impl Converter {
}
fn parse_args() -> Result<Converter, clap::Error> {
+ let supported_formats = vec![
+ "Png",
+ #[cfg(have_cairo_pdf)]
+ "Pdf",
+ #[cfg(have_cairo_ps)]
+ "Ps",
+ #[cfg(have_cairo_ps)]
+ "Eps",
+ #[cfg(have_cairo_svg)]
+ "Svg",
+ ];
+
let app = clap::App::new("rsvg-convert")
.version(concat!("version ", crate_version!()))
.about("Convert SVG files to other image formats")
@@ -534,7 +547,7 @@ fn parse_args() -> Result<Converter, clap::Error> {
.short("f")
.long("format")
.takes_value(true)
- .possible_values(&Format::variants())
+ .possible_values(supported_formats.as_slice())
.case_insensitive(true)
.default_value("png")
.help("Output format"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]