Skip to main content

Outline

Struct Outline 

Source
pub struct Outline<S: Scale> {
    points: Vec<Point<S::Coord>>,
    flags: Vec<PointFlags>,
    contours: Vec<u16>,
    phantom: [Point<S::Coord>; 4],
    unscaled: Vec<Point<i32>>,
    deltas: Vec<Point<S::Delta>>,
    iup: Vec<Point<S::Delta>>,
    composite_deltas: Vec<Point<S::Delta>>,
    point_count: u32,
    contour_count: u32,
}
Expand description

An outline and the buffers that hold it.

OutlinePlan::load requires the caller to size and supply seven buffers. This owns them, grows them as needed and reuses them across glyphs, so loading stops allocating after the first few.

Loading returns an OutlineRef borrowing those buffers. The same data is reachable through points and its neighbours once that borrow ends.

use read_fonts::{
    tables::glyf::outline::{Outline, OutlineTables, Scale26Dot6},
    types::GlyphId,
    FontRef,
};

let font = FontRef::new(font_test_data::COLRV0V1_VARIABLE)?;
let tables = OutlineTables::new(&font)?;
let mut outline = Outline::<Scale26Dot6>::new();

// Borrows `outline`'s buffers for as long as it is held.
let loaded = outline.load(&tables, GlyphId::new(1), Some(16.0))?;
for (point, flags) in loaded.points().iter().zip(loaded.flags()) {
    let _ = (point, flags.is_off_curve_quad());
}

// Once it is dropped, the outline can be read through its accessors.
assert_eq!(outline.points().len(), outline.flags().len());

Fields§

§points: Vec<Point<S::Coord>>§flags: Vec<PointFlags>§contours: Vec<u16>§phantom: [Point<S::Coord>; 4]§unscaled: Vec<Point<i32>>§deltas: Vec<Point<S::Delta>>§iup: Vec<Point<S::Delta>>§composite_deltas: Vec<Point<S::Delta>>§point_count: u32§contour_count: u32

Implementations§

Source§

impl<S: Scale> Outline<S>

Source

pub fn new() -> Self

Creates an empty outline. The buffers are allocated on first use.

Source

pub fn points(&self) -> &[Point<S::Coord>]

The loaded points, excluding phantom points.

Source

pub fn flags(&self) -> &[PointFlags]

The flag for each point in Self::points.

Source

pub fn contours(&self) -> &[u16]

The index of the last point of each contour.

Source

pub fn phantom_points(&self) -> &[Point<S::Coord>; 4]

The four phantom points, after scaling, variation and hinting.

Source

pub fn adjusted_lsb(&self) -> S::Coord

The left side bearing after scaling, variation and hinting.

Source

pub fn adjusted_advance_width(&self) -> S::Coord

The advance width after scaling, variation and hinting.

Source

pub fn to_path(&self, start: PathContourStart, sink: &mut impl PathSink) -> bool

Converts the outline to path commands, calling sink for each.

See OutlineRef::to_path for what start decides and when this returns false.

Source

pub fn load_with<'a>( &mut self, context: &'a dyn OutlineContext<'a>, glyph: GlyphId, scale: &S, hinter: Option<&mut dyn Hinter<S::Coord>>, ) -> Result<OutlineRef<'_, S::Coord>, Error>

Loads glyph at scale, replacing any previous contents.

The per-scale load methods build the scale. Use this to supply a hinter, or to drive a scale generically.

Source§

impl Outline<Scale26Dot6>

Source

pub fn load<'a>( &mut self, context: &'a dyn OutlineContext<'a>, glyph: GlyphId, ppem: Option<f32>, ) -> Result<OutlineRef<'_, F26Dot6>, Error>

Loads glyph at ppem, in 26.6 pixel coordinates.

A ppem of None leaves the result in font units, shifted left by six. The location comes from context.

Source

pub fn load_hinted<'a>( &mut self, context: &'a dyn OutlineContext<'a>, glyph: GlyphId, ppem: Option<f32>, hinter: &mut dyn Hinter<F26Dot6>, ) -> Result<OutlineRef<'_, F26Dot6>, Error>

Loads glyph at ppem, running the glyph’s TrueType instructions through hinter.

Source§

impl Outline<ScaleF32>

Source

pub fn load<'a>( &mut self, context: &'a dyn OutlineContext<'a>, glyph: GlyphId, ppem: Option<f32>, ) -> Result<OutlineRef<'_, f32>, Error>

Loads glyph at ppem, in floating point pixel coordinates.

A ppem of None leaves the result in font units. The location comes from context.

Source§

impl Outline<Unscaled>

Source

pub fn load<'a>( &mut self, context: &'a dyn OutlineContext<'a>, glyph: GlyphId, ) -> Result<OutlineRef<'_, i32>, Error>

Loads glyph in font units.

There is no size to pass: variations apply and components are placed, but nothing is scaled. The location comes from context.

Trait Implementations§

Source§

impl<S: Scale> Default for Outline<S>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S> Freeze for Outline<S>
where <S as Scale>::Coord: Freeze,

§

impl<S> RefUnwindSafe for Outline<S>
where <S as Scale>::Coord: RefUnwindSafe, <S as Scale>::Delta: RefUnwindSafe,

§

impl<S> Send for Outline<S>
where <S as Scale>::Coord: Send, <S as Scale>::Delta: Send,

§

impl<S> Sync for Outline<S>
where <S as Scale>::Coord: Sync, <S as Scale>::Delta: Sync,

§

impl<S> Unpin for Outline<S>
where <S as Scale>::Coord: Unpin, <S as Scale>::Delta: Unpin,

§

impl<S> UnsafeUnpin for Outline<S>
where <S as Scale>::Coord: UnsafeUnpin,

§

impl<S> UnwindSafe for Outline<S>
where <S as Scale>::Coord: UnwindSafe, <S as Scale>::Delta: UnwindSafe,

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> 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, 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.