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
impl CharStringVisitor<f32, CFFError> for DebugVisitor
Source§fn visit(
&mut self,
op: VisitOp,
stack: &ArgumentsStack<'_, f32>,
) -> Result<(), CFFError>
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>
fn enter_subr(&mut self, index: SubroutineIndex) -> Result<(), CFFError>
Called prior to entering a subroutine. Read more
Source§fn enter_seac(&mut self, _seac: SeacChar, _dx: T, _dy: T) -> Result<(), E>
fn enter_seac(&mut self, _seac: SeacChar, _dx: T, _dy: T) -> Result<(), E>
Called before entering a component of an accented character. Read more
Auto Trait Implementations§
impl Freeze for DebugVisitor
impl RefUnwindSafe for DebugVisitor
impl Send for DebugVisitor
impl Sync for DebugVisitor
impl Unpin for DebugVisitor
impl UnwindSafe for DebugVisitor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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