pub trait ScaleFont<F>where
    F: Font,{
Show 20 methods // Required methods fn scale(&self) -> PxScale; fn font(&self) -> &F; fn codepoint_ids(&self) -> CodepointIdIter<'_> ; // Provided methods fn h_scale_factor(&self) -> f32 { ... } fn v_scale_factor(&self) -> f32 { ... } fn scale_factor(&self) -> PxScaleFactor { ... } fn ascent(&self) -> f32 { ... } fn descent(&self) -> f32 { ... } fn height(&self) -> f32 { ... } fn line_gap(&self) -> f32 { ... } fn glyph_id(&self, c: char) -> GlyphId { ... } fn scaled_glyph(&self, c: char) -> Glyph { ... } fn h_advance(&self, id: GlyphId) -> f32 { ... } fn h_side_bearing(&self, id: GlyphId) -> f32 { ... } fn v_advance(&self, id: GlyphId) -> f32 { ... } fn v_side_bearing(&self, id: GlyphId) -> f32 { ... } fn kern(&self, first: GlyphId, second: GlyphId) -> f32 { ... } fn glyph_bounds(&self, glyph: &Glyph) -> Rect { ... } fn glyph_count(&self) -> usize { ... } fn outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph> { ... }
}
Expand description

A Font with an associated pixel scale. This can be used to provide pixel scale values for glyph advances, heights etc.

Example

use ab_glyph::{Font, FontRef, PxScale, ScaleFont};

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

// Associate the font with a scale of 45px
let scaled_font = font.as_scaled(PxScale::from(45.0));

assert_eq!(scaled_font.height(), 45.0);
assert_eq!(scaled_font.h_advance(scaled_font.glyph_id('b')), 21.225);

// Replace associated scale with another
let scaled_font = scaled_font.with_scale(180.0);

assert_eq!(scaled_font.height(), 180.0);
assert_eq!(scaled_font.h_advance(scaled_font.glyph_id('b')), 84.9);

Required Methods§

fn scale(&self) -> PxScale

Returns the pixel scale associated with this font.

fn font(&self) -> &F

Returns a font reference.

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

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

Same as Font::codepoint_ids.

Provided Methods§

fn h_scale_factor(&self) -> f32

Scale factor for unscaled font horizontal values.

fn v_scale_factor(&self) -> f32

Scale factor for unscaled font vertical values.

fn scale_factor(&self) -> PxScaleFactor

fn ascent(&self) -> f32

Pixel scaled glyph ascent.

fn descent(&self) -> f32

Pixel scaled glyph descent.

fn height(&self) -> f32

Pixel scaled height ascent - descent.

By definition of PxScale, this is self.scale().y.

fn line_gap(&self) -> f32

Pixel scaled line gap.

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

Lookup a GlyphId matching a given char.

fn scaled_glyph(&self, c: char) -> Glyph

Construct a Glyph with the font’s pixel scale at position point(0.0, 0.0).

Example
let scaled_font = font.as_scaled(50.0);

let a1 = scaled_font.scaled_glyph('a');
let a2 = font.glyph_id('a').with_scale(50.0); // equivalent

assert_eq!(a1.scale, PxScale::from(50.0));
assert_eq!(a1.position, point(0.0, 0.0));

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

Pixel scaled horizontal advance for a given glyph.

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

Pixel scaled horizontal side bearing for a given glyph.

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

Pixel scaled vertical advance for a given glyph.

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

Pixel scaled vertical side bearing for a given glyph.

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

Returns additional pixel scaled kerning to apply for a particular pair of glyphs.

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

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

Horizontally: Glyph position +/- h_advance/h_side_bearing. Vertically: Glyph position +/- ascent/descent.

Note this method does not make use of the associated scale, as Glyph already includes one of it’s own.

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 outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph>

Compute glyph outline ready for drawing.

Note this method does not make use of the associated scale, as Glyph already includes one of it’s own.

Implementations on Foreign Types§

§

impl<F, SF> ScaleFont<F> for &SFwhere F: Font, SF: ScaleFont<F>,

§

fn scale(&self) -> PxScale

§

fn font(&self) -> &F

§

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

Implementors§

§

impl<F> ScaleFont<F> for PxScaleFont<F>where F: Font,