Struct ab_glyph::FontArc

source ·
pub struct FontArc(/* private fields */);
Expand description

Font implementor that wraps another concrete Font + 'static type storing in an Arc.

Provides convenient type erasure & cheap clones (particularly for FontVec).

§Example

use ab_glyph::{Font, FontArc};

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

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

Implementations§

source§

impl FontArc

source

pub fn new<F: Font + Send + Sync + 'static>(font: F) -> Self

§Example
let font_arc = FontArc::new(font_vec);
source

pub fn try_from_vec(data: Vec<u8>) -> Result<Self, InvalidFont>

Creates an FontArc from owned data.

§Example
let font = FontArc::try_from_vec(owned_font_data)?;
source

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

Creates an FontArc from a byte-slice.

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

Trait Implementations§

source§

impl Clone for FontArc

source§

fn clone(&self) -> FontArc

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
source§

impl Debug for FontArc

source§

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

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

impl Font for FontArc

source§

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

Get the size of the font unit Read more
source§

fn ascent_unscaled(&self) -> f32

Unscaled glyph ascent. Read more
source§

fn descent_unscaled(&self) -> f32

Unscaled glyph descent. Read more
source§

fn line_gap_unscaled(&self) -> f32

Unscaled line gap. Read more
source§

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

Lookup a GlyphId matching a given char. Read more
source§

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

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

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

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

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

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

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

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

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

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

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

Compute unscaled glyph outline curves & bounding box.
source§

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()
source§

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

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

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

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

fn glyph_svg_image(&self, id: GlyphId) -> Option<GlyphSvg<'_>>

Returns raw SVG data of a range of glyphs which includes this one. Read more
source§

fn font_data(&self) -> &[u8]

Extracts a slice containing the data passed into e.g. [FontArc::try_from_slice]. Read more
source§

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

Converts pt units into PxScale. Read more
source§

fn height_unscaled(&self) -> f32

Unscaled height ascent - descent. Read more
source§

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

👎Deprecated since 0.2.22: Deprecated in favor of glyph_raster_image2
Returns a pre-rendered image of the glyph. Read more
source§

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

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

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

Compute glyph outline ready for drawing.
source§

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

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

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

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

impl From<Arc<dyn Font + Send + Sync>> for FontArc

source§

fn from(font: Arc<dyn Font + Send + Sync + 'static>) -> Self

Converts to this type from the input type.
source§

impl From<FontRef<'static>> for FontArc

source§

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

Converts to this type from the input type.
source§

impl From<FontVec> for FontArc

source§

fn from(font: FontVec) -> Self

Converts to this type from the input type.

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

§

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

§

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.