Trait ab_glyph::ScaleFont

source ·
pub trait ScaleFont<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§

source

fn scale(&self) -> PxScale

Returns the pixel scale associated with this font.

source

fn font(&self) -> &F

Returns a font reference.

source

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

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

Same as Font::codepoint_ids.

Provided Methods§

source

fn h_scale_factor(&self) -> f32

Scale factor for unscaled font horizontal values.

source

fn v_scale_factor(&self) -> f32

Scale factor for unscaled font vertical values.

source

fn scale_factor(&self) -> PxScaleFactor

source

fn ascent(&self) -> f32

Pixel scaled glyph ascent.

source

fn descent(&self) -> f32

Pixel scaled glyph descent.

source

fn height(&self) -> f32

Pixel scaled height ascent - descent.

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

source

fn line_gap(&self) -> f32

Pixel scaled line gap.

source

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

Lookup a GlyphId matching a given char.

source

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));
source

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

Pixel scaled horizontal advance for a given glyph.

source

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

Pixel scaled horizontal side bearing for a given glyph.

source

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

Pixel scaled vertical advance for a given glyph.

source

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

Pixel scaled vertical side bearing for a given glyph.

source

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

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

source

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.

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

source§

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

Implementors§