pub fn line_dimensions(&self, text: &str, text_size: f32) -> LineDimensions {
        let mut prev_glyph: Option<GlyphId> = None;
        let mut dimensions = LineDimensions::default();

        let scale = Scale::uniform(text_size);

        for c in text.chars() {
            let glyph = if let Some(glyph) = self.font.glyph(c) {
                glyph
            } else {
                continue;
            };

            // Apply kerning
            if let Some(prev) = prev_glyph.take() {
                dimensions.width += self.font.pair_kerning(scale, prev, glyph.id());
            }
            prev_glyph = Some(glyph.id());

            let glyph = glyph.scaled(scale);
            dimensions.width += glyph.h_metrics().advance_width;

            if let Some(bounding) = glyph.exact_bounding_box() {
                dimensions.descent = f32::max(dimensions.descent, bounding.max.y);
                dimensions.ascent = f32::min(dimensions.ascent, bounding.min.y);
            }
        }

        dimensions
    }
/// Calculates the dimensions of a single line of text. Any newlines in the given string
/// are ignored.
Calculates the dimensions of a single line of text. Any newlines in the given string
are ignored.
Calculates the dimensions of a single line of text . Any newlines in the given string are ignored .
pub fn line_dimensions(&self, text: &str, text_size: f32) -> LineDimensions {
        let mut prev_glyph: Option<GlyphId> = None;
        let mut dimensions = LineDimensions::default();
        let scale = Scale::uniform(text_size);
        for c in text.chars() {
            let glyph = if let Some(glyph) = self.font.glyph(c) {
                glyph
            } else {
                continue;
            };
            // Apply kerning
            if let Some(prev) = prev_glyph.take() {
                dimensions.width += self.font.pair_kerning(scale, prev, glyph.id());
            }
            prev_glyph = Some(glyph.id());
            let glyph = glyph.scaled(scale);
            dimensions.width += glyph.h_metrics().advance_width;
            if let Some(bounding) = glyph.exact_bounding_box() {
                dimensions.descent = f32::max(dimensions.descent, bounding.max.y);
                dimensions.ascent = f32::min(dimensions.ascent, bounding.min.y);
            }
        }
        dimensions
    }
pub fn line_dimensions ( & self , text : & str , text_size : f32 ) -> LineDimensions { let mut prev_glyph : Option < GlyphId > = None ; let mut dimensions = LineDimensions :: default ( ) ; let scale = Scale :: uniform ( text_size ) ; for c in text . chars ( ) { let glyph = if let Some ( glyph ) = self . font . glyph ( c ) { glyph } else { continue ; } ; // Apply kerning if let Some ( prev ) = prev_glyph . take ( ) { dimensions . width += self . font . pair_kerning ( scale , prev , glyph . id ( ) ) ; } prev_glyph = Some ( glyph . id ( ) ) ; let glyph = glyph . scaled ( scale ) ; dimensions . width += glyph . h_metrics ( ) . advance_width ; if let Some ( bounding ) = glyph . exact_bounding_box ( ) { dimensions . descent = f32 :: max ( dimensions . descent , bounding . max . y ) ; dimensions . ascent = f32 :: min ( dimensions . ascent , bounding . min . y ) ; } } dimensions }
Calculates the dimensions of a single line of text.
Calculates the dimensions of a single line of text .
&self
text
&str
text_size
f32
&self
text
&str
text_size
f32