DebugVisitor

Struct DebugVisitor 

Source
pub struct DebugVisitor;
Expand description

A debug implementation of CharStringVisitor that just prints the operators and their operands.

§Example

use allsorts::binary::read::ReadScope;
use allsorts::cff::charstring::{ArgumentsStack, CharStringVisitorContext, DebugVisitor};
use allsorts::cff::CFFError;
use allsorts::cff::{self, CFFFont, CFFVariant, CFF};
use allsorts::font::MatchingPresentation;
use allsorts::font_data::FontData;
use allsorts::tables::{OpenTypeData, OpenTypeFont};
use allsorts::{tag, Font};

fn main() -> Result<(), CFFError> {
    // Read the font
    let buffer = std::fs::read("tests/fonts/opentype/Klei.otf").unwrap();
    let otf = ReadScope::new(&buffer).read::<OpenTypeFont<'_>>()?;
    let offset_table = match otf.data {
        OpenTypeData::Single(ttf) => ttf,
        OpenTypeData::Collection(_) => unreachable!(),
    };

    let cff_table_data = offset_table
        .read_table(&otf.scope, tag::CFF)?
        .expect("missing CFF table");
    let cff = cff_table_data.read::<CFF<'_>>()?;

    // Glyph to visit
    let glyph_id = 741; // U+2116 NUMERO SIGN

    // Set up CharString visitor
    let font = &cff.fonts[0];
    let local_subrs = match &font.data {
        CFFVariant::CID(_) => None, // Will be resolved on request.
        CFFVariant::Type1(type1) => type1.local_subr_index.as_ref(),
    };

    let mut visitor = DebugVisitor;
    let variable = None;
    let mut ctx = CharStringVisitorContext::new(
        glyph_id,
        &font.char_strings_index,
        local_subrs,
        &cff.global_subr_index,
        variable,
    );
    let mut stack = ArgumentsStack {
        data: &mut [0.0; cff::MAX_OPERANDS],
        len: 0,
        max_len: cff::MAX_OPERANDS,
    };
    ctx.visit(CFFFont::CFF(font), &mut stack, &mut visitor)?;
    Ok(())
}

Trait Implementations§

Source§

impl CharStringVisitor<f32, CFFError> for DebugVisitor

Source§

fn visit( &mut self, op: VisitOp, stack: &ArgumentsStack<'_, f32>, ) -> Result<(), CFFError>

Called for each operator in the CharString, except for callsubr and callgsubr — these are handled by enter/exit_subr.
Source§

fn enter_subr(&mut self, index: SubroutineIndex) -> Result<(), CFFError>

Called prior to entering a subroutine. Read more
Source§

fn exit_subr(&mut self) -> Result<(), E>

Called when returning from a subroutine.
Source§

fn enter_seac(&mut self, _seac: SeacChar, _dx: T, _dy: T) -> Result<(), E>

Called before entering a component of an accented character. Read more
Source§

fn exit_seac(&mut self, _seac: SeacChar) -> Result<(), E>

Called when returning from a component of an accented character. Read more
Source§

fn hint_data(&mut self, _op: VisitOp, _hints: &[u8]) -> Result<(), E>

Called with the hint data that follows the hintmask and cntrmask operators. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.