[librsvg: 3/5] Extract function to munge a MIME type for gdk-pixbuf
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 3/5] Extract function to munge a MIME type for gdk-pixbuf
- Date: Wed, 17 Mar 2021 19:21:48 +0000 (UTC)
commit f9e489d71ef2b126a00e842d2f9843fa744e56e7
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Mar 17 12:59:58 2021 -0600
Extract function to munge a MIME type for gdk-pixbuf
src/document.rs | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/src/document.rs b/src/document.rs
index 47e71ad6..b6612e87 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -257,18 +257,7 @@ fn load_image(
return Err(LoadingError::Other(String::from("no image data")));
}
- // See issue #548 - data: URLs without a MIME-type automatically
- // fall back to "text/plain;charset=US-ASCII". Some (old?) versions of
- // Adobe Illustrator generate data: URLs without MIME-type for image
- // data. We'll catch this and fall back to sniffing by unsetting the
- // content_type.
- let unspecified_mime_type = Mime::from_str("text/plain;charset=US-ASCII").unwrap();
-
- let content_type = if mime_type == unspecified_mime_type {
- None
- } else {
- Some(format!("{}/{}", mime_type.type_, mime_type.subtype))
- };
+ let content_type = content_type_for_gdk_pixbuf(&mime_type);
let loader = if let Some(ref content_type) = content_type {
PixbufLoader::new_with_mime_type(content_type)?
@@ -295,6 +284,21 @@ fn load_image(
Ok(surface)
}
+fn content_type_for_gdk_pixbuf(mime_type: &Mime) -> Option<String> {
+ // See issue #548 - data: URLs without a MIME-type automatically
+ // fall back to "text/plain;charset=US-ASCII". Some (old?) versions of
+ // Adobe Illustrator generate data: URLs without MIME-type for image
+ // data. We'll catch this and fall back to sniffing by unsetting the
+ // content_type.
+ let unspecified_mime_type = Mime::from_str("text/plain;charset=US-ASCII").unwrap();
+
+ if *mime_type == unspecified_mime_type {
+ None
+ } else {
+ Some(format!("{}/{}", mime_type.type_, mime_type.subtype))
+ }
+}
+
fn human_readable_url(aurl: &AllowedUrl) -> &str {
if aurl.scheme() == "data" {
// avoid printing a huge data: URL for image data
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]