diff --git a/Cargo.toml b/Cargo.toml index 16b9d9a..1294368 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,11 +22,13 @@ exclude = ["benches/", "tests/", "testing-tools/", "examples/", "meson.build"] core_maths = { version = "0.1.0", optional = true } # only for no_std builds [features] -default = ["std", "opentype-layout", "apple-layout", "variable-fonts", "glyph-names"] +default = ["std", "alloc", "opentype-layout", "apple-layout", "variable-fonts", "glyph-names"] # Enables the use of the standard library. # When disabled, the `no-std-float` feature must be enabled instead. -std = [] +std = ["alloc"] no-std-float = ["core_maths"] +# Enables the use of the allocator without using std +alloc = [] # Enables variable fonts support. Increases binary size almost twice. # Includes avar, CFF2, fvar, gvar, HVAR, MVAR and VVAR tables. variable-fonts = [] @@ -45,7 +47,7 @@ glyph-names = [] # while the spec allows up to 4095. Most variable fonts use 10-20 tuples, # so our limit is suitable for most of the cases. But if you need full support, you have to # enable this feature. -gvar-alloc = ["std"] +gvar-alloc = ["alloc"] [dev-dependencies] base64 = "0.22" diff --git a/src/lib.rs b/src/lib.rs index 506de41..f739a9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,9 @@ Font parsing starts with a [`Face`]. #[macro_use] extern crate std; +#[cfg(feature = "alloc")] +extern crate alloc; + #[cfg(not(any(feature = "std", feature = "no-std-float")))] compile_error!("You have to activate either the `std` or the `no-std-float` feature."); @@ -795,8 +798,7 @@ impl core::fmt::Display for FaceParsingError { } } -#[cfg(feature = "std")] -impl std::error::Error for FaceParsingError {} +impl core::error::Error for FaceParsingError {} /// A raw font face. /// diff --git a/src/tables/gvar.rs b/src/tables/gvar.rs index d0a17f5..67cb9ea 100644 --- a/src/tables/gvar.rs +++ b/src/tables/gvar.rs @@ -66,7 +66,7 @@ enum VariationTuples<'a> { }, #[cfg(feature = "gvar-alloc")] Heap { - vec: std::vec::Vec>, + vec: alloc::vec::Vec>, }, } @@ -87,7 +87,7 @@ impl<'a> VariationTuples<'a> { if capacity > MAX_STACK_TUPLES_LEN { // ... and we're currently on the stack, move to the heap. if let Self::Stack { headers, len } = self { - let mut vec = std::vec::Vec::with_capacity(capacity as usize); + let mut vec = alloc::vec::Vec::with_capacity(capacity as usize); for header in headers.iter_mut().take(*len as usize) { let header = core::mem::take(header); vec.push(header); diff --git a/src/tables/name.rs b/src/tables/name.rs index 6726043..daba68e 100644 --- a/src/tables/name.rs +++ b/src/tables/name.rs @@ -1,10 +1,10 @@ //! A [Naming Table]( //! https://docs.microsoft.com/en-us/typography/opentype/spec/name) implementation. -#[cfg(feature = "std")] -use std::string::String; -#[cfg(feature = "std")] -use std::vec::Vec; +#[cfg(feature = "alloc")] +use alloc::string::String; +#[cfg(feature = "alloc")] +use alloc::vec::Vec; use crate::parser::{FromData, LazyArray16, Offset, Offset16, Stream}; use crate::Language; @@ -140,7 +140,7 @@ impl<'a> Name<'a> { /// - Unicode Platform ID /// - Windows Platform ID + Symbol /// - Windows Platform ID + Unicode BMP - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[inline(never)] pub fn to_string(&self) -> Option { if self.is_unicode() { @@ -156,7 +156,7 @@ impl<'a> Name<'a> { is_unicode_encoding(self.platform_id, self.encoding_id) } - #[cfg(feature = "std")] + #[cfg(feature = "alloc")] #[inline(never)] fn name_from_utf16_be(&self) -> Option { let mut name: Vec = Vec::new(); @@ -182,7 +182,7 @@ impl<'a> Name<'a> { } } -#[cfg(feature = "std")] +#[cfg(feature = "alloc")] impl<'a> core::fmt::Debug for Name<'a> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { let name = self.to_string(); @@ -197,7 +197,7 @@ impl<'a> core::fmt::Debug for Name<'a> { } } -#[cfg(not(feature = "std"))] +#[cfg(not(feature = "alloc"))] impl<'a> core::fmt::Debug for Name<'a> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("Name")