pub mod cff;
pub mod glyf;
mod glyphs;
mod path;
pub mod type1;
mod unscaled;
pub mod varc;
#[doc(inline)]
pub use crate::tables::glyf::outline::PathContourStart;
#[doc(inline)]
pub use glyphs::{OutlineGlyph, OutlineGlyphs};
#[doc(inline)]
pub use path::{ControlBoundsSink, NullSink, PathElement, PathSink, SvgSink, TransformSink};
pub(crate) use unscaled::PointsFromPath;
#[doc(inline)]
pub use unscaled::UnscaledOutlineSink;
use super::GlyphSource;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum OutlineSource {
Varc,
Glyf,
Cff2,
Cff,
Type1,
}
impl From<OutlineSource> for GlyphSource {
fn from(source: OutlineSource) -> Self {
match source {
OutlineSource::Varc => Self::Varc,
OutlineSource::Glyf => Self::Glyf,
OutlineSource::Cff2 => Self::Cff2,
OutlineSource::Cff => Self::Cff,
OutlineSource::Type1 => Self::Type1,
}
}
}
impl TryFrom<GlyphSource> for OutlineSource {
type Error = GlyphSource;
fn try_from(source: GlyphSource) -> Result<Self, GlyphSource> {
Ok(match source {
GlyphSource::Varc => Self::Varc,
GlyphSource::Glyf => Self::Glyf,
GlyphSource::Cff2 => Self::Cff2,
GlyphSource::Cff => Self::Cff,
GlyphSource::Type1 => Self::Type1,
_ => return Err(source),
})
}
}
#[derive(Copy, Clone, Default, PartialEq, Debug)]
pub struct DrawOptions {
pub ppem: Option<f32>,
pub contour_start: PathContourStart,
}
impl DrawOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_ppem(self, ppem: Option<f32>) -> Self {
Self { ppem, ..self }
}
pub fn with_contour_start(self, contour_start: PathContourStart) -> Self {
Self {
contour_start,
..self
}
}
}
#[derive(Debug, Default)]
pub enum DrawMemory<'a> {
#[default]
Scratch,
Buffer(&'a mut [u8]),
}
impl<'a> DrawMemory<'a> {
pub(crate) fn into_buffer(self) -> Option<&'a mut [u8]> {
match self {
Self::Scratch => None,
Self::Buffer(buffer) => Some(buffer),
}
}
}
impl<'a> From<&'a mut [u8]> for DrawMemory<'a> {
fn from(buffer: &'a mut [u8]) -> Self {
Self::Buffer(buffer)
}
}
#[non_exhaustive]
#[derive(Copy, Clone, Default, PartialEq, Debug)]
pub struct DrawnMetrics {
pub h_advance: Option<f32>,
pub x_bearing: Option<f32>,
pub has_overlaps: bool,
pub dropout_control: DropoutControl,
}
#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
pub enum DropoutControl {
Ignore,
#[default]
Simple,
SimpleWithStubs,
Smart,
SmartWithStubs,
}
impl DropoutControl {
pub fn is_enabled(self) -> bool {
self != Self::Ignore
}
pub fn is_smart(self) -> bool {
matches!(self, Self::Smart | Self::SmartWithStubs)
}
pub fn includes_stubs(self) -> bool {
matches!(self, Self::SimpleWithStubs | Self::SmartWithStubs)
}
}
#[cfg(test)]
mod tests {
use super::DropoutControl;
#[test]
fn dropout_predicates() {
assert!(!DropoutControl::Ignore.is_enabled());
assert!(DropoutControl::Simple.is_enabled());
assert!(!DropoutControl::Simple.is_smart());
assert!(DropoutControl::SmartWithStubs.is_smart());
assert!(DropoutControl::SmartWithStubs.includes_stubs());
assert!(!DropoutControl::Smart.includes_stubs());
assert_eq!(DropoutControl::default(), DropoutControl::Simple);
}
}