Skip to content

Commit

Permalink
is_http_or_https -> is_not_data_url
Browse files Browse the repository at this point in the history
  • Loading branch information
CGQAQ committed Jan 29, 2024
1 parent 64cf7cc commit 46fbb52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl Resvg {

match &img.kind {
ImageKind::HOLE(url) => {
if is_http_or_https(&url) {
if is_not_data_url(&url) {
data.push(url.clone());
}
}
Expand Down Expand Up @@ -507,8 +507,8 @@ impl Resvg {
}
}

fn is_http_or_https(data: &String) -> bool {
return data.starts_with("http://") || data.starts_with("https://");
fn is_not_data_url(data: &str) -> bool {
return !data.starts_with("data:");
}

fn traverse_tree_mut<F>(node: &mut usvg::Node, f: &F)
Expand Down
3 changes: 2 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use resvg::tiny_skia::{Pixmap, Transform};
use resvg::usvg::fontdb::Database;
use resvg::usvg::{self, ImageHrefResolver, ImageKind, Options, TreeParsing};
use serde::{Deserialize, Deserializer};
use crate::is_not_data_url;

/// Image fit options.
/// This provides the deserializer for `usvg::FitTo`.
Expand Down Expand Up @@ -365,7 +366,7 @@ where
pub(crate) fn tweak_usvg_options(opts: &mut usvg::Options) {
opts.image_href_resolver = ImageHrefResolver::default();
opts.image_href_resolver.resolve_string = Box::new(move |data: &str, opts: &Options| {
if data.starts_with("https://") || data.starts_with("http://") {
if is_not_data_url(data) {
Some(ImageKind::HOLE(data.to_string()))
} else {
let resolver = ImageHrefResolver::default().resolve_string;
Expand Down

0 comments on commit 46fbb52

Please sign in to comment.