[][src]Trait ab_glyph::ScaleFont

pub trait ScaleFont<F: Font> {
    pub fn scale(&self) -> PxScale;
pub fn font(&self) -> &F;
pub fn codepoint_ids(&self) -> CodepointIdIter<'_>

Notable traits for CodepointIdIter<'a>

impl<'a> Iterator for CodepointIdIter<'a> type Item = (GlyphId, char);
; pub fn h_scale_factor(&self) -> f32 { ... }
pub fn v_scale_factor(&self) -> f32 { ... }
pub fn scale_factor(&self) -> PxScaleFactor { ... }
pub fn ascent(&self) -> f32 { ... }
pub fn descent(&self) -> f32 { ... }
pub fn height(&self) -> f32 { ... }
pub fn line_gap(&self) -> f32 { ... }
pub fn glyph_id(&self, c: char) -> GlyphId { ... }
pub fn scaled_glyph(&self, c: char) -> Glyph { ... }
pub fn h_advance(&self, id: GlyphId) -> f32 { ... }
pub fn h_side_bearing(&self, id: GlyphId) -> f32 { ... }
pub fn v_advance(&self, id: GlyphId) -> f32 { ... }
pub fn v_side_bearing(&self, id: GlyphId) -> f32 { ... }
pub fn kern(&self, first: GlyphId, second: GlyphId) -> f32 { ... }
pub fn glyph_bounds(&self, glyph: &Glyph) -> Rect { ... }
pub fn glyph_count(&self) -> usize { ... }
pub fn outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph> { ... } }

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

pub fn scale(&self) -> PxScale[src]

Returns the pixel scale associated with this font.

pub fn font(&self) -> &F[src]

Returns a font reference.

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

Notable traits for CodepointIdIter<'a>

impl<'a> Iterator for CodepointIdIter<'a> type Item = (GlyphId, char);
[src]

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

Same as Font::codepoint_ids.

Loading content...

Provided methods

pub fn h_scale_factor(&self) -> f32[src]

Scale factor for unscaled font horizontal values.

pub fn v_scale_factor(&self) -> f32[src]

Scale factor for unscaled font vertical values.

pub fn scale_factor(&self) -> PxScaleFactor[src]

pub fn ascent(&self) -> f32[src]

Pixel scaled glyph ascent.

pub fn descent(&self) -> f32[src]

Pixel scaled glyph descent.

pub fn height(&self) -> f32[src]

Pixel scaled height ascent - descent.

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

pub fn line_gap(&self) -> f32[src]

Pixel scaled line gap.

pub fn glyph_id(&self, c: char) -> GlyphId[src]

Lookup a GlyphId matching a given char.

pub fn scaled_glyph(&self, c: char) -> Glyph[src]

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

pub fn h_advance(&self, id: GlyphId) -> f32[src]

Pixel scaled horizontal advance for a given glyph.

pub fn h_side_bearing(&self, id: GlyphId) -> f32[src]

Pixel scaled horizontal side bearing for a given glyph.

pub fn v_advance(&self, id: GlyphId) -> f32[src]

Pixel scaled vertical advance for a given glyph.

pub fn v_side_bearing(&self, id: GlyphId) -> f32[src]

Pixel scaled vertical side bearing for a given glyph.

pub fn kern(&self, first: GlyphId, second: GlyphId) -> f32[src]

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

pub fn glyph_bounds(&self, glyph: &Glyph) -> Rect[src]

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.

pub fn glyph_count(&self) -> usize[src]

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

pub fn outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph>[src]

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.

Loading content...

Implementations on Foreign Types

impl<F: Font, SF: ScaleFont<F>, '_> ScaleFont<F> for &'_ SF[src]

Loading content...

Implementors

impl<F: Font> ScaleFont<F> for PxScaleFont<F>[src]

Loading content...