[librsvg: 2/3] (#676): rsvg-convert - use gio's stdin/stdout streams for win32.
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/3] (#676): rsvg-convert - use gio's stdin/stdout streams for win32.
- Date: Fri, 26 Mar 2021 23:14:39 +0000 (UTC)
commit 075a026c8837f37bbb36584c1cb9b7d92f4cb2a0
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Mar 23 17:03:25 2021 -0600
(#676): rsvg-convert - use gio's stdin/stdout streams for win32.
https://gitlab.gnome.org/GNOME/librsvg/-/issues/676
src/bin/rsvg-convert.rs | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/src/bin/rsvg-convert.rs b/src/bin/rsvg-convert.rs
index 4fcf30c6..a8479fd4 100644
--- a/src/bin/rsvg-convert.rs
+++ b/src/bin/rsvg-convert.rs
@@ -2,10 +2,20 @@
extern crate clap;
use gio::prelude::*;
-use gio::{
- Cancellable, FileCreateFlags, FileExt, InputStream, OutputStream, UnixInputStream,
- UnixOutputStream,
-};
+use gio::{Cancellable, FileCreateFlags, FileExt, InputStream, OutputStream};
+
+#[cfg(unix)]
+use gio::{UnixInputStream, UnixOutputStream};
+
+#[cfg(windows)]
+use std::io;
+
+#[cfg(windows)]
+use std::os::windows::io::AsRawHandle;
+
+#[cfg(windows)]
+use gio_sys;
+
use librsvg::rsvg_convert_only::{LegacySize, PathOrUrl};
use librsvg::{CairoRenderer, Color, Loader, Parse, RenderingError};
use once_cell::unsync::OnceCell;
@@ -326,19 +336,47 @@ mod metadata {
struct Stdin;
impl Stdin {
+ #[cfg(unix)]
pub fn stream() -> InputStream {
let stream = unsafe { UnixInputStream::new(0) };
stream.upcast::<InputStream>()
}
+
+ #[cfg(windows)]
+ pub fn stream() -> InputStream {
+ // https://github.com/gtk-rs/gtk-rs/issues/381 - do this with
+ // Win32InputStream::with_handle when this is fixed
+ let raw_handle = io::stdin().as_raw_handle();
+ unsafe {
+ InputStream::from_glib_full(gio_sys::g_win32_input_stream_new(
+ raw_handle,
+ false.to_glib(),
+ ))
+ }
+ }
}
struct Stdout;
impl Stdout {
+ #[cfg(unix)]
pub fn stream() -> OutputStream {
let stream = unsafe { UnixOutputStream::new(1) };
stream.upcast::<OutputStream>()
}
+
+ #[cfg(windows)]
+ pub fn stream() -> OutputStream {
+ // https://github.com/gtk-rs/gtk-rs/issues/381 - do this with
+ // Win32OutputStream::with_handle when this is fixed
+ let raw_handle = io::stdout().as_raw_handle();
+ unsafe {
+ OutputStream::from_glib_full(gio_sys::g_win32_output_stream_new(
+ raw_handle,
+ false.to_glib(),
+ ))
+ }
+ }
}
#[derive(Clone, Debug)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]