Trait ab_glyph::ScaleFont[][src]

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

Notable traits for CodepointIdIter<'a>

impl<'a> Iterator for CodepointIdIter<'a> type Item = (GlyphId, char);
; 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> { ... } }

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[src]

Returns the pixel scale associated with this font.

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

Returns a font reference.

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

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

Scale factor for unscaled font horizontal values.

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

Scale factor for unscaled font vertical values.

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

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

Pixel scaled glyph ascent.

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

Pixel scaled glyph descent.

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

Pixel scaled height ascent - descent.

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

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

Pixel scaled line gap.

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

Lookup a GlyphId matching a given char.

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

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

Pixel scaled horizontal advance for a given glyph.

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

Pixel scaled horizontal side bearing for a given glyph.

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

Pixel scaled vertical advance for a given glyph.

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

Pixel scaled vertical side bearing for a given glyph.

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

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

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.

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

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