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
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand Down Expand Up @@ -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.
///
Expand Down
4 changes: 2 additions & 2 deletions src/tables/gvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ enum VariationTuples<'a> {
},
#[cfg(feature = "gvar-alloc")]
Heap {
vec: std::vec::Vec<VariationTuple<'a>>,
vec: alloc::vec::Vec<VariationTuple<'a>>,
},
}

Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/tables/name.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String> {
if self.is_unicode() {
Expand All @@ -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<String> {
let mut name: Vec<u16> = Vec::new();
Expand All @@ -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();
Expand All @@ -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")
Expand Down