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§
sourcefn codepoint_ids(&self) -> CodepointIdIter<'_> ⓘ
fn codepoint_ids(&self) -> CodepointIdIter<'_> ⓘ
Returns an iterator of all distinct (GlyphId, char)
pairs. Not ordered.
Same as Font::codepoint_ids
.
Provided Methods§
sourcefn h_scale_factor(&self) -> f32
fn h_scale_factor(&self) -> f32
Scale factor for unscaled font horizontal values.
sourcefn v_scale_factor(&self) -> f32
fn v_scale_factor(&self) -> f32
Scale factor for unscaled font vertical values.
fn scale_factor(&self) -> PxScaleFactor
sourcefn ascent(&self) -> f32
fn ascent(&self) -> f32
Pixel scaled glyph ascent. See glyph layout concepts.
sourcefn descent(&self) -> f32
fn descent(&self) -> f32
Pixel scaled glyph descent. See glyph layout concepts.
sourcefn height(&self) -> f32
fn height(&self) -> f32
Pixel scaled height ascent - descent
. See glyph layout concepts.
By definition of PxScale
, this is self.scale().y
.
sourcefn line_gap(&self) -> f32
fn line_gap(&self) -> f32
Pixel scaled line gap. See glyph layout concepts.
sourcefn scaled_glyph(&self, c: char) -> Glyph
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));
sourcefn h_advance(&self, id: GlyphId) -> f32
fn h_advance(&self, id: GlyphId) -> f32
Pixel scaled horizontal advance for a given glyph. See glyph layout concepts.
sourcefn h_side_bearing(&self, id: GlyphId) -> f32
fn h_side_bearing(&self, id: GlyphId) -> f32
Pixel scaled horizontal side bearing for a given glyph. See glyph layout concepts.
sourcefn v_side_bearing(&self, id: GlyphId) -> f32
fn v_side_bearing(&self, id: GlyphId) -> f32
Pixel scaled vertical side bearing for a given glyph.
sourcefn kern(&self, first: GlyphId, second: GlyphId) -> f32
fn kern(&self, first: GlyphId, second: GlyphId) -> f32
Returns additional pixel scaled kerning to apply for a particular pair of glyphs.
sourcefn glyph_bounds(&self, glyph: &Glyph) -> Rect
fn glyph_bounds(&self, glyph: &Glyph) -> Rect
Returns the layout bounds of this glyph.
Horizontally: Glyph position +/- h_advance/h_side_bearing. Vertically: Glyph position +/- ascent/descent.
These are not the same as OutlinedGlyph::px_bounds
. If you are drawing pixels
you should use px_bounds
and not this method as outlines are not bound by layout
values.
Note this method does not make use of the associated scale, as Glyph
already includes one of it’s own.
sourcefn glyph_count(&self) -> usize
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()
sourcefn outline_glyph(&self, glyph: Glyph) -> Option<OutlinedGlyph>
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.