Skip to content

Commit

Permalink
Remove 'druid' feature
Browse files Browse the repository at this point in the history
This is no longer relevant, and removing it is a nice simplification.
  • Loading branch information
cmyr committed Oct 27, 2023
1 parent 7fb8abb commit d320501
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 137 deletions.
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
46 changes: 0 additions & 46 deletions src/glyph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -800,26 +777,3 @@ impl From<kurbo::Affine> for AffineTransform {
}
}
}

#[cfg(feature = "druid")]
impl From<druid::piet::Color> 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<Color> 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)
}
}
8 changes: 0 additions & 8 deletions src/glyph/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
78 changes: 6 additions & 72 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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<Name, Arc<Glyph>>,
#[cfg(not(feature = "druid"))]
pub(crate) glyphs: BTreeMap<Name, Glyph>,
pub(crate) name: Name,
pub(crate) path: PathBuf,
Expand Down Expand Up @@ -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)
})
})
Expand Down Expand Up @@ -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<Name, Glyph> {
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<Glyph>> {
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)
}

Expand All @@ -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<Arc<Glyph>>,
#[cfg(not(feature = "druid"))] glyph: impl Into<Glyph>,
) {
pub fn insert_glyph(&mut self, glyph: impl Into<Glyph>) {
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);
Expand All @@ -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<Glyph> {
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<Arc<Glyph>> {
if let Some(path) = self.contents.remove(name) {
self.path_set.remove(&path.to_string_lossy().to_lowercase());
}
Expand All @@ -580,49 +537,27 @@ 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<Item = &Glyph> + '_ {
#[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<Item = &Arc<Glyph>> + '_ {
self.glyphs.values()
}

/// Returns an iterator over the glyphs in this layer, mutably.
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Glyph> {
#[cfg(feature = "druid")]
return self.glyphs.values_mut().map(Arc::make_mut);
#[cfg(not(feature = "druid"))]
self.glyphs.values_mut()
}

/// Retains only the elements specified by the predicate.
///
/// 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);
}
Expand Down Expand Up @@ -979,22 +914,21 @@ 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![
Layer::default(),
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()
},
Expand Down
1 change: 0 additions & 1 deletion src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>);

impl Name {
Expand Down
4 changes: 0 additions & 4 deletions src/shared_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,7 +13,6 @@ pub type Plist = plist::Dictionary;
///
/// See <https://unifiedfontobject.org/versions/ufo3/conventions/#colors>.
#[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,
Expand Down

0 comments on commit d320501

Please sign in to comment.