Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ default = ["object-libs"]
object-libs = ["uuid"]
kurbo = ["dep:kurbo"]
rayon = ["dep:rayon"]
ufoz = ["zip"]

[target.'cfg(not(target_family = "wasm"))'.dependencies]
uuid = { version = "1.2", features = ["v4"], optional = true }
Expand All @@ -43,6 +44,7 @@ base64 = "0.22"
close_already = "0.3"
log = "0.4"
smol_str = { version = "0.3", features = ["serde"] }
zip = { version = "2", default-features = false, features = ["deflate"], optional = true }

[dev-dependencies]
failure = "0.1.6"
Expand Down
7 changes: 1 addition & 6 deletions examples/load_save.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! A small program that times the loading and saving of a UFO file.

use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;
use std::time::{Duration, Instant};

Expand Down Expand Up @@ -58,11 +57,7 @@ struct Args {
impl Args {
fn get_from_env_or_exit() -> Self {
let mut args = env::args().skip(1);
let path = match args.next().map(PathBuf::from) {
Some(ref p) if p.exists() && p.extension() == Some(OsStr::new("ufo")) => p.to_owned(),
Some(ref p) => exit_err!("path {:?} is not an existing .ufo file, exiting", p),
None => exit_err!("Please supply a path to a .ufo file"),
};
let path = args.next().map(PathBuf::from).expect("missing path argument");

let outpath = args.next().map(PathBuf::from);
if outpath.as_ref().map(|p| p.exists()).unwrap_or(false) {
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ pub enum FontLoadError {
/// The underlying error.
source: PlistError,
},
/// The file is not a valid zip archive.
#[cfg(feature = "ufoz")]
#[error("failed to open UFO as zip archive")]
InvalidZipFile(#[source] zip::result::ZipError),
/// Norad can currently only open UFO (directory) packages.
#[error("only UFO (directory) packages are supported")]
UfoNotADir,
Expand Down
12 changes: 9 additions & 3 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,17 @@ impl Font {

fn load_impl(path: &Path, request: DataRequest) -> Result<Font, FontLoadError> {
let metadata = path.metadata().map_err(FontLoadError::AccessUfoDir)?;
if !metadata.is_dir() {
return Err(FontLoadError::UfoNotADir);
if metadata.is_dir() {
return Self::load_from_source(&request, &path);
}

Self::load_from_source(&request, &path)
#[cfg(feature = "ufoz")]
if metadata.is_file() {
Comment on lines +224 to +225
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we only checking it's a file, not looking at the extension?

If we were ever to add JSON UFO loading, we're going to clash with this

let source = crate::zip_source::ZipSource::open(path)?;
return Self::load_from_source(&request, &source);
}

Err(FontLoadError::UfoNotADir)
}

/// Returns a [`Font`] loaded from the given [`FontSource`].
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ mod shared_types;
mod upconversion;
pub(crate) mod util;
mod write;
#[cfg(feature = "ufoz")]
mod zip_source;

pub use data_request::DataRequest;
pub use font::{Font, FormatVersion, MetaInfo};
Expand Down
Loading
Loading