diff --git a/Cargo.toml b/Cargo.toml index 3508e274..b84d95b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,12 +30,6 @@ thiserror = "1.0" indexmap = { version = "2.0.0", features = ["serde"] } base64 = "0.21.2" -[dependencies.druid] -default-features = false -features = ["x11"] -version = "0.8.0" -optional = true - [dev-dependencies] failure = "0.1.6" serde_test = "1.0.102" diff --git a/src/glyph/mod.rs b/src/glyph/mod.rs index a98dcda3..c0cd2566 100644 --- a/src/glyph/mod.rs +++ b/src/glyph/mod.rs @@ -12,9 +12,6 @@ use std::path::{Path, PathBuf}; #[cfg(feature = "kurbo")] use crate::error::ConvertContourError; -#[cfg(feature = "druid")] -use druid::{Data, Lens}; - use crate::error::{ErrorKind, GlifLoadError, GlifWriteError, StoreError}; use crate::name::Name; use crate::names::NameList; @@ -29,10 +26,8 @@ pub use codepoints::Codepoints; /// /// [glif]: http://unifiedfontobject.org/versions/ufo3/glyphs/glif/ #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "druid", derive(Lens))] pub struct Glyph { /// The name of the glyph. - #[cfg_attr(feature = "druid", lens(ignore))] pub(crate) name: Name, /// Glyph height. pub height: f64, @@ -251,23 +246,6 @@ impl Glyph { } } -#[cfg(feature = "druid")] -impl Data for Glyph { - fn same(&self, other: &Glyph) -> bool { - self.name.same(&other.name) - && self.height.same(&other.height) - && self.width.same(&other.width) - && self.codepoints == other.codepoints - && self.note == other.note - && self.guidelines == other.guidelines - && self.anchors == other.anchors - && self.components == other.components - && self.contours == other.contours - && self.image == other.image - && self.lib == other.lib - } -} - /// A reference position in a glyph, such as for attaching accents. /// /// See the [Anchor section] of the UFO spec for more information. @@ -462,7 +440,6 @@ impl std::fmt::Display for PointType { /// A 2D affine transformation. #[derive(Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "druid", derive(Data))] pub struct AffineTransform { /// x-scale value. pub x_scale: f64, @@ -800,26 +777,3 @@ impl From for AffineTransform { } } } - -#[cfg(feature = "druid")] -impl From for Color { - fn from(src: druid::piet::Color) -> Color { - let rgba = src.as_rgba_u32(); - let r = ((rgba >> 24) & 0xff) as f64 / 255.0; - let g = ((rgba >> 16) & 0xff) as f64 / 255.0; - let b = ((rgba >> 8) & 0xff) as f64 / 255.0; - let a = (rgba & 0xff) as f64 / 255.0; - assert!((0.0..=1.0).contains(&b), "b: {}, raw {}", b, (rgba & (0xff << 8))); - - Color::new(r.clamp(0.0, 1.0), g.clamp(0.0, 1.0), b.clamp(0.0, 1.0), a.clamp(0.0, 1.0)) - .unwrap() - } -} - -#[cfg(feature = "druid")] -impl From for druid::piet::Color { - fn from(src: Color) -> druid::piet::Color { - let (red, green, blue, alpha) = src.channels(); - druid::piet::Color::rgba(red, green, blue, alpha) - } -} diff --git a/src/glyph/tests.rs b/src/glyph/tests.rs index 57b0042e..ca36e2e7 100644 --- a/src/glyph/tests.rs +++ b/src/glyph/tests.rs @@ -425,14 +425,6 @@ fn notdef_failure() { let _ = parse_glyph(bytes).unwrap(); } -#[cfg(feature = "druid")] -#[test] -fn druid_from_color() { - let color = druid::piet::Color::rgba(1.0, 0.11, 0.5, 0.23); - let color2: druid::piet::Color = Color::new(1.0, 0.11, 0.5, 0.23).unwrap().into(); - assert_eq!(color2.as_rgba_u32(), color.as_rgba_u32()); -} - //#[test] //fn parse_utf16() { //let bytes = include_bytes!("../../testdata/utf16-glyph.xml"); diff --git a/src/layer.rs b/src/layer.rs index 0b1e59af..a63d54ff 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -2,9 +2,6 @@ use std::collections::{BTreeMap, HashSet}; use std::fs; use std::path::{Path, PathBuf}; -#[cfg(feature = "druid")] -use std::{ops::Deref, sync::Arc}; - #[cfg(feature = "rayon")] use rayon::prelude::*; @@ -263,9 +260,6 @@ impl Default for LayerContents { /// [UFO layer]: http://unifiedfontobject.org/versions/ufo3/glyphs/ #[derive(Debug, Clone, PartialEq)] pub struct Layer { - #[cfg(feature = "druid")] - pub(crate) glyphs: BTreeMap>, - #[cfg(not(feature = "druid"))] pub(crate) glyphs: BTreeMap, pub(crate) name: Name, pub(crate) path: PathBuf, @@ -352,9 +346,6 @@ impl Layer { }) .map(|mut glyph| { glyph.name = name.clone(); - #[cfg(feature = "druid")] - return (name, Arc::new(glyph)); - #[cfg(not(feature = "druid"))] (name, glyph) }) }) @@ -478,30 +469,17 @@ impl Layer { } /// Gets the given key's corresponding entry in the map for in-place manipulation. - #[cfg(not(feature = "druid"))] pub fn entry(&mut self, glyph: Name) -> std::collections::btree_map::Entry { self.glyphs.entry(glyph) } /// Returns a reference to the glyph with the given name, if it exists. pub fn get_glyph(&self, glyph: &str) -> Option<&Glyph> { - #[cfg(feature = "druid")] - return self.glyphs.get(glyph).map(|g| g.deref()); - #[cfg(not(feature = "druid"))] - self.glyphs.get(glyph) - } - - /// Returns a reference to the given glyph, behind an `Arc`, if it exists. - #[cfg(feature = "druid")] - pub fn get_glyph_raw(&self, glyph: &str) -> Option<&Arc> { self.glyphs.get(glyph) } /// Returns a mutable reference to the glyph with the given name, if it exists. pub fn get_glyph_mut(&mut self, glyph: &str) -> Option<&mut Glyph> { - #[cfg(feature = "druid")] - return self.glyphs.get_mut(glyph).map(Arc::make_mut); - #[cfg(not(feature = "druid"))] self.glyphs.get_mut(glyph) } @@ -514,11 +492,7 @@ impl Layer { /// /// If the glyph does not previously exist, the filename is calculated from /// the glyph's name. - pub fn insert_glyph( - &mut self, - #[cfg(feature = "druid")] glyph: impl Into>, - #[cfg(not(feature = "druid"))] glyph: impl Into, - ) { + pub fn insert_glyph(&mut self, glyph: impl Into) { let glyph = glyph.into(); if !self.contents.contains_key(&glyph.name) { let path = crate::util::default_file_name_for_glyph_name(&glyph.name, &self.path_set); @@ -536,24 +510,7 @@ impl Layer { } /// Remove the named glyph from this layer and return it, if it exists. - /// - /// **Note**: If the `druid` feature is enabled, this will not return the - /// removed `Glyph` if there are any other outstanding references to it, - /// although it will still be removed. In this case, consider using the - /// `remove_glyph_raw` method instead. pub fn remove_glyph(&mut self, name: &str) -> Option { - if let Some(path) = self.contents.remove(name) { - self.path_set.remove(&path.to_string_lossy().to_lowercase()); - } - #[cfg(feature = "druid")] - return self.glyphs.remove(name).and_then(|g| Arc::try_unwrap(g).ok()); - #[cfg(not(feature = "druid"))] - self.glyphs.remove(name) - } - - /// Remove the named glyph and return it, including the containing `Arc`. - #[cfg(feature = "druid")] - pub fn remove_glyph_raw(&mut self, name: &str) -> Option> { if let Some(path) = self.contents.remove(name) { self.path_set.remove(&path.to_string_lossy().to_lowercase()); } @@ -580,41 +537,20 @@ impl Layer { Err(NamingError::Missing(old.into())) } else { let name = Name::new(new).map_err(|_| NamingError::Invalid(new.into()))?; - #[cfg(feature = "druid")] - { - let mut g = self.remove_glyph_raw(old).unwrap(); - Arc::make_mut(&mut g).name = name; - self.insert_glyph(g); - } - #[cfg(not(feature = "druid"))] - { - let mut g = self.remove_glyph(old).unwrap(); - g.name = name; - self.insert_glyph(g); - } + let mut g = self.remove_glyph(old).unwrap(); + g.name = name; + self.insert_glyph(g); Ok(()) } } /// Returns an iterator over the glyphs in this layer. pub fn iter(&self) -> impl Iterator + '_ { - #[cfg(feature = "druid")] - return self.glyphs.values().map(|g| g.deref()); - #[cfg(not(feature = "druid"))] - self.glyphs.values() - } - - /// Returns an iterator over the glyphs in this layer. - #[cfg(feature = "druid")] - pub fn iter_raw(&self) -> impl Iterator> + '_ { self.glyphs.values() } /// Returns an iterator over the glyphs in this layer, mutably. pub fn iter_mut(&mut self) -> impl Iterator { - #[cfg(feature = "druid")] - return self.glyphs.values_mut().map(Arc::make_mut); - #[cfg(not(feature = "druid"))] self.glyphs.values_mut() } @@ -622,7 +558,6 @@ impl Layer { /// /// In other words, remove all pairs `(k, v)` for which `f(&k, &mut v)` returns `false`. /// The elements are visited in unsorted (and unspecified) order. - #[cfg(not(feature = "druid"))] pub fn retain(&mut self, f: impl FnMut(&Name, &mut Glyph) -> bool) { self.glyphs.retain(f); } @@ -979,7 +914,6 @@ mod tests { #[test] // Saves test from failing to compile with druid enabled - #[allow(clippy::useless_conversion)] fn test_remove_empty_layers() { let mut layers = LayerContents { layers: vec![ @@ -987,14 +921,14 @@ mod tests { Layer { name: Name::new("fizz").unwrap(), glyphs: maplit::btreemap! { - Name::new("a").unwrap() => Glyph::new("a").into(), + Name::new("a").unwrap() => Glyph::new("a"), }, ..Default::default() }, Layer { name: Name::new("buzz").unwrap(), glyphs: maplit::btreemap! { - Name::new("b").unwrap() => Glyph::new("b").into(), + Name::new("b").unwrap() => Glyph::new("b"), }, ..Default::default() }, diff --git a/src/name.rs b/src/name.rs index 7684ad30..8a114766 100644 --- a/src/name.rs +++ b/src/name.rs @@ -20,7 +20,6 @@ use crate::error::NamingError; /// [`Layer`]: crate::Layer #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] #[serde(transparent)] -#[cfg_attr(feature = "druid", derive(druid::Data))] pub struct Name(Arc); impl Name { diff --git a/src/shared_types.rs b/src/shared_types.rs index 46cf93ba..23646895 100644 --- a/src/shared_types.rs +++ b/src/shared_types.rs @@ -4,9 +4,6 @@ use serde::de::Deserializer; use serde::ser::Serializer; use serde::{Deserialize, Serialize}; -#[cfg(feature = "druid")] -use druid::Data; - pub static PUBLIC_OBJECT_LIBS_KEY: &str = "public.objectLibs"; /// A Plist dictionary. @@ -16,7 +13,6 @@ pub type Plist = plist::Dictionary; /// /// See . #[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "druid", derive(Data))] pub struct Color { /// Red channel value. Must be in the range 0 to 1, inclusive. red: f64,