Skip to main content

OutlinePlan

Struct OutlinePlan 

Source
pub struct OutlinePlan<'a> {
    pub glyph: GlyphId,
    pub glyph_data: Option<Glyph<'a>>,
    pub num_points: u32,
    pub num_contours: u32,
    pub max_simple_points: u32,
    pub max_hinted_composite_points: u32,
    pub max_component_delta_stack: u32,
    pub has_hinting: bool,
    pub has_overlaps: bool,
    pub applies_variations: bool,
}
Expand description

What an outline is made of, and how much scratch space building it needs.

Produced by walking the composite tree without reading point data, which is cheap enough to do per draw. Self::buffer_lengths sizes the buffers and Self::load fills them.

Fields§

§glyph: GlyphId

The glyph this describes.

§glyph_data: Option<Glyph<'a>>

The root glyph’s glyf data, or None for an empty glyph such as a space.

A missing or unreadable glyph is an error from OutlinePlan::new, not None here.

§num_points: u32

Total points in the outline, summed over every simple glyph in the tree, plus the phantom points.

§num_contours: u32

Total contours, summed over every simple glyph in the tree.

§max_simple_points: u32

Largest point count, including phantom points, of any one simple glyph in the tree.

§max_hinted_composite_points: u32

Largest point count, including phantom points, contributed by any one composite glyph in the tree that carries instructions.

Zero when no composite is instructed. Only a hinted composite keeps its loaded points in font units, so this is tracked separately from Self::max_simple_points.

§max_component_delta_stack: u32

Deepest the per-component delta stack gets while loading nested composites.

§has_hinting: bool

True if any glyph in the tree carries TrueType instructions.

§has_overlaps: bool

True if any glyph in the tree is flagged as having overlapping contours or components.

§applies_variations: bool

True when gvar deltas will be applied: the font has a gvar table and the context names a location in it.

A variable font read at its default instance needs no delta buffers. This is the one field taken from the context rather than the walk.

Implementations§

Source§

impl<'a> OutlinePlan<'a>

Source

pub fn new( context: &dyn OutlineContext<'a>, glyph: GlyphId, ) -> Result<Self, Error>

Walks the glyph, and the tree below a composite, collecting what building its outline requires.

Source

pub fn buffer_lengths<S: Scale>(&self) -> BufferLengths

Returns how long each scratch buffer has to be to load at S.

Source

pub fn load<'s, 'buf, S: Scale>( &'s self, context: &'a dyn OutlineContext<'a>, scale: &'s S, buffers: Buffers<'buf, S>, hinter: Option<&mut dyn Hinter<S::Coord>>, ) -> Result<OutlineRef<'buf, S::Coord>, Error>

Builds the outline this plan describes.

The buffers must be at least as long as buffer_lengths says. The location comes from context. The result borrows buffers and nothing else.

use read_fonts::{
    tables::glyf::outline::{Buffers, OutlinePlan, OutlineTables, Scale26Dot6},
    types::{GlyphId, Point},
    FontRef,
};

let font = FontRef::new(font_test_data::COLRV0V1_VARIABLE)?;
let tables = OutlineTables::new(&font)?;
let plan = OutlinePlan::new(&tables, GlyphId::new(1))?;

// A static draw, and 26.6 keeps a font unit copy of the points.
let lengths = plan.buffer_lengths::<Scale26Dot6>();
let mut points = vec![Point::default(); lengths.points as usize];
let mut flags = vec![Default::default(); lengths.points as usize];
let mut contours = vec![0; lengths.contours as usize];
let mut unscaled = vec![Point::default(); lengths.unscaled as usize];
let buffers = Buffers {
    points: &mut points,
    flags: &mut flags,
    contours: &mut contours,
    unscaled: &mut unscaled,
    // Only needed when varying.
    deltas: &mut [],
    iup: &mut [],
    composite_deltas: &mut [],
};

let scale = Scale26Dot6::new(Some(16.0), tables.units_per_em);
let outline = plan.load(&tables, &scale, buffers, None)?;
assert_eq!(outline.points().len(), outline.flags().len());
Source

fn walk( &mut self, context: &dyn OutlineContext<'a>, glyph: &Glyph<'a>, component_depth: u32, recurse_depth: usize, components: &mut usize, ) -> Result<(), Error>

Trait Implementations§

Source§

impl<'a> Clone for OutlinePlan<'a>

Source§

fn clone(&self) -> OutlinePlan<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OutlinePlan<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for OutlinePlan<'a>

Source§

fn default() -> OutlinePlan<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for OutlinePlan<'a>

§

impl<'a> RefUnwindSafe for OutlinePlan<'a>

§

impl<'a> Send for OutlinePlan<'a>

§

impl<'a> Sync for OutlinePlan<'a>

§

impl<'a> Unpin for OutlinePlan<'a>

§

impl<'a> UnsafeUnpin for OutlinePlan<'a>

§

impl<'a> UnwindSafe for OutlinePlan<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.