pub fn tabular_numbers<'a>(
        &'a self,
        cursor: &'a mut Cursor,
    ) -> impl Iterator<Item = PositionedGlyph> + 'a {
        let mut digits = [0; 10];
        let mut digit_width = 0.0;
        for (digit, glyph) in digits.iter_mut().enumerate() {
            let GlyphId(the_glyph) = self
                .font
                .font
                .face
                .glyph_index(char::from(digit as u8 + b'0'))
                .unwrap_or_default();

            *glyph = the_glyph as _;

            let width = self.font.glyph_x_advance(the_glyph as _);
            if width > digit_width {
                digit_width = width;
            }
        }

        // FIXME: There's kerning between e.g. ".1" now, which is maybe not quite
        // what we want. We may need to either stabilize `:` and `.` now or turn
        // off kerning for tabular numbers.

        let scale = self.font.scale;

        Iterator::zip(
            self.buffer.glyph_infos().iter(),
            self.buffer.glyph_positions().iter(),
        )
        .rev()
        .map(move |(i, p)| {
            let x = if digits.contains(&i.glyph_id) {
                cursor.x -= digit_width;
                let wider_by = digit_width - (p.x_advance as f32 * scale);
                cursor.x + p.x_offset as f32 * scale + 0.5 * wider_by
            } else {
                cursor.x -= p.x_advance as f32 * scale;
                cursor.x + p.x_offset as f32 * scale
            };

            cursor.y -= p.y_advance as f32 * scale;
            PositionedGlyph {
                id: i.glyph_id,
                x,
                y: cursor.y + p.y_offset as f32 * scale,
            }
        })
    }
// This is a right aligned layout where all the digits have the same width.
This is a right aligned layout where all the digits have the same width.
This is a right aligned layout where all the digits have the same width .
pub fn tabular_numbers<'a>(
        &'a self,
        cursor: &'a mut Cursor,
    ) -> impl Iterator<Item = PositionedGlyph> + 'a {
        let mut digits = [0; 10];
        let mut digit_width = 0.0;
        for (digit, glyph) in digits.iter_mut().enumerate() {
            let GlyphId(the_glyph) = self
                .font
                .font
                .face
                .glyph_index(char::from(digit as u8 + b'0'))
                .unwrap_or_default();
            *glyph = the_glyph as _;
            let width = self.font.glyph_x_advance(the_glyph as _);
            if width > digit_width {
                digit_width = width;
            }
        }
        // FIXME: There's kerning between e.g. ".1" now, which is maybe not quite
        // what we want. We may need to either stabilize `:` and `.` now or turn
        // off kerning for tabular numbers.
        let scale = self.font.scale;
        Iterator::zip(
            self.buffer.glyph_infos().iter(),
            self.buffer.glyph_positions().iter(),
        )
        .rev()
        .map(move |(i, p)| {
            let x = if digits.contains(&i.glyph_id) {
                cursor.x -= digit_width;
                let wider_by = digit_width - (p.x_advance as f32 * scale);
                cursor.x + p.x_offset as f32 * scale + 0.5 * wider_by
            } else {
                cursor.x -= p.x_advance as f32 * scale;
                cursor.x + p.x_offset as f32 * scale
            };
            cursor.y -= p.y_advance as f32 * scale;
            PositionedGlyph {
                id: i.glyph_id,
                x,
                y: cursor.y + p.y_offset as f32 * scale,
            }
        })
    }
pub fn tabular_numbers < ' a > ( & ' a self , cursor : & ' a mut Cursor , ) -> impl Iterator < Item = PositionedGlyph > + ' a { let mut digits = [ 0 ; 10 ] ; let mut digit_width = 0.0 ; for ( digit , glyph ) in digits . iter_mut ( ) . enumerate ( ) { let GlyphId ( the_glyph ) = self . font . font . face . glyph_index ( char :: from ( digit as u8 + b'0' ) ) . unwrap_or_default ( ) ; * glyph = the_glyph as _ ; let width = self . font . glyph_x_advance ( the_glyph as _ ) ; if width > digit_width { digit_width = width ; } } // FIXME: There's kerning between e.g. ".1" now, which is maybe not quite // what we want. We may need to either stabilize `:` and `.` now or turn // off kerning for tabular numbers. let scale = self . font . scale ; Iterator :: zip ( self . buffer . glyph_infos ( ) . iter ( ) , self . buffer . glyph_positions ( ) . iter ( ) , ) . rev ( ) . map ( move | ( i , p ) | { let x = if digits . contains ( & i . glyph_id ) { cursor . x -= digit_width ; let wider_by = digit_width - ( p . x_advance as f32 * scale ) ; cursor . x + p . x_offset as f32 * scale + 0.5 * wider_by } else { cursor . x -= p . x_advance as f32 * scale ; cursor . x + p . x_offset as f32 * scale } ; cursor . y -= p . y_advance as f32 * scale ; PositionedGlyph { id : i . glyph_id , x , y : cursor . y + p . y_offset as f32 * scale , } } ) }
This is a right aligned layout where all the digits have the same width.
This is a right aligned layout where all the digits have the same width .
&'a self
cursor
&'a mut Cursor
&'a self
cursor
&'a mut Cursor