Struct gfx_glyph::ab_glyph::FontRef

pub struct FontRef<'font>(_);
Expand description

Font data handle stored as a &[u8] + parsed data. See Font for more methods.

Also see the owned version FontVec.

Example

use ab_glyph::{Font, FontRef};

let font = FontRef::try_from_slice(include_bytes!("../../dev/fonts/Exo2-Light.otf"))?;

assert_eq!(font.glyph_id('s'), ab_glyph::GlyphId(56));

Implementations§

§

impl<'font> FontRef<'font>

pub fn try_from_slice(data: &'font [u8]) -> Result<FontRef<'font>, InvalidFont>

Creates an FontRef from a byte-slice.

For font collections see FontRef::try_from_slice_and_index.

Example
let font = FontRef::try_from_slice(include_bytes!("../../dev/fonts/Exo2-Light.otf"))?;

pub fn try_from_slice_and_index( data: &'font [u8], index: u32 ) -> Result<FontRef<'font>, InvalidFont>

Creates an FontRef from byte-slice.

You can set index for font collections. For simple fonts use 0 or FontRef::try_from_slice.

Example
let font =
    FontRef::try_from_slice_and_index(include_bytes!("../../dev/fonts/Exo2-Light.otf"), 0)?;

Trait Implementations§

§

impl<'font> Clone for FontRef<'font>

§

fn clone(&self) -> FontRef<'font>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for FontRef<'_>

§

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

Formats the value using the given formatter. Read more
§

impl Font for FontRef<'_>

§

fn units_per_em(&self) -> Option<f32>

Get the size of the font unit Read more
§

fn ascent_unscaled(&self) -> f32

Unscaled glyph ascent. Read more
§

fn descent_unscaled(&self) -> f32

Unscaled glyph descent. Read more
§

fn line_gap_unscaled(&self) -> f32

Unscaled line gap. Read more
§

fn glyph_id(&self, c: char) -> GlyphId

Lookup a GlyphId matching a given char. Read more
§

fn h_advance_unscaled(&self, id: GlyphId) -> f32

Unscaled horizontal advance for a given glyph id. Read more
§

fn h_side_bearing_unscaled(&self, id: GlyphId) -> f32

Unscaled horizontal side bearing for a given glyph id. Read more
§

fn v_advance_unscaled(&self, id: GlyphId) -> f32

Unscaled vertical advance for a given glyph id. Read more
§

fn v_side_bearing_unscaled(&self, id: GlyphId) -> f32

Unscaled vertical side bearing for a given glyph id. Read more
§

fn kern_unscaled(&self, first: GlyphId, second: GlyphId) -> f32

Returns additional unscaled kerning to apply for a particular pair of glyph ids. Read more
§

fn outline(&self, id: GlyphId) -> Option<Outline>

Compute unscaled glyph outline curves & bounding box.
§

fn glyph_count(&self) -> usize

The number of glyphs present in this font. Glyph identifiers for this font will always be in the range 0..self.glyph_count()
§

fn codepoint_ids<'a>(&'a self) -> CodepointIdIter<'a>

Returns an iterator of all distinct (GlyphId, char) pairs. Not ordered. Read more
§

fn glyph_raster_image(&self, id: GlyphId, size: u16) -> Option<GlyphImage<'_>>

Returns a pre-rendered image of the glyph. Read more
§

fn pt_to_px_scale(&self, pt_size: f32) -> Option<PxScale>

Converts pt units into PxScale. Read more
§

fn height_unscaled(&self) -> f32

Unscaled height ascent - descent. Read more
§

fn glyph_bounds(&self, glyph: &Glyph) -> Rectwhere Self: Sized,

Returns the layout bounds of this glyph. These are different to the outline px_bounds(). Read more
§

fn outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph>where Self: Sized,

Compute glyph outline ready for drawing.
§

fn as_scaled<S>(&self, scale: S) -> PxScaleFont<&Self>where S: Into<PxScale>, Self: Sized,

Construct a PxScaleFontRef by associating with the given pixel scale. Read more
§

fn into_scaled<S>(self, scale: S) -> PxScaleFont<Self>where S: Into<PxScale>, Self: Sized,

Move into a PxScaleFont associated with the given pixel scale.
§

impl From<FontRef<'static>> for FontArc

§

fn from(font: FontRef<'static>) -> FontArc

Converts to this type from the input type.
§

impl VariableFont for FontRef<'_>

§

fn set_variation(&mut self, axis: &[u8; 4], value: f32) -> bool

Sets a variation axis coordinate value by it’s tag. Read more
§

fn variations(&self) -> Vec<VariationAxis, Global>

Returns variation axes. Read more

Auto Trait Implementations§

§

impl<'font> RefUnwindSafe for FontRef<'font>

§

impl<'font> Send for FontRef<'font>

§

impl<'font> Sync for FontRef<'font>

§

impl<'font> Unpin for FontRef<'font>

§

impl<'font> UnwindSafe for FontRef<'font>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V