/// rasterize a given set of characters at the specified atlas index (ix, iy), record related metrics in the atlas, returns the first free atlas index.
/// (note: if atlas managing multiple fonts, bits should include some unique id to disambiguate font kern values lookup).

rasterize a given set of characters at the specified atlas index (ix, iy), record related metrics in the atlas, returns the first free atlas index.
(note: if atlas managing multiple fonts, bits should include some unique id to disambiguate font kern values lookup).
rasterize a given set of characters at the specified atlas index ( ix iy ) record related metrics in the atlas returns the first free atlas index . ( note : if atlas managing multiple fonts bits should include some unique id to disambiguate font kern values lookup ) .
pub fn rasterize<F: abFont>(font: F, atlas: &mut FontAtlas, chars: &[char], bits: u64, cursor: &mut Vec2) {
                    let grid_num_cols = atlas.grid.num_slots.x;
                    let grid_num_rows = atlas.grid.num_slots.y;
                    let grid_px_offset = atlas.grid.px_offset;
                    let grid_px_step = atlas.grid.px_slot_size + atlas.grid.px_gap;
                    let bpp = atlas.texture.bpp();
                    let stride = (grid_px_offset.x + grid_num_cols * grid_px_step.x) as usize * bpp;
                    let texture_data = &mut atlas.texture_data;
                    let hack = 4.0;  // TODO: remove this hack (some glyph overflow the given scale != max glyph px height)
                    let font_px_scale = atlas.grid.px_slot_size.y - hack;
                    let font_scaled = font.as_scaled(font_px_scale);
                    let ver_ascent = font_scaled.ascent().ceil();
                    atlas.map_font_meta.insert(bits, FontMetadata {
                        px_scale: font_px_scale,
                        px_ascent: ver_ascent + hack,
                    });
                    atlas.map_char_info.reserve(chars.len());
                    let mut kern_chars = atlas.map_char_info
                        .keys()
                        .cloned()
                        .filter_map(|(chr, bits1)| if bits1 == bits { Some(chr) } else { None })
                        .collect::<Vec<_>>();
                    kern_chars.extend(chars);
                    for chr in chars.iter().cloned() {
                        // fetch glyph
                        let glyph_id = font.glyph_id(chr);
                        let glyph = glyph_id.with_scale_and_position(font_px_scale, ab_glyph::point(0.0, 0.0));
                        // locate and rasterize
                        let cur_pixel = grid_px_offset + *cursor * grid_px_step;
                        debug_assert!(cursor.x < grid_num_cols && cursor.y < grid_num_rows,
                            "Atlas texture_data too small ({:?}) to fit all the requested chars (n: {}); cursor ({:?}), cur_pixel ({:?})!",
                            atlas.grid, chars.len(), cursor, cur_pixel
                        );
                        let (px_region, re_bits) = {
                            if let Some(out) = font.outline_glyph(glyph) {
                                let bounds = out.px_bounds();
                                let ver_align = (ver_ascent + bounds.min.y).ceil().max(0.0);
                                let off_index = (cur_pixel.y + ver_align) as usize * stride + cur_pixel.x as usize;
                                out.draw(|x, y, c| {
                                    let index = off_index + y as usize * stride + x as usize;
                                    let value = (c * 255.0) as u8;
                                    for channel_index in 0 .. bpp { 
                                        texture_data[index + channel_index * bpp] = value;
                                    }
                                });
                                // next atlas index
                                if cursor.x + 1.0 < grid_num_cols {
                                    cursor.x += 1.0;
                                } else {
                                    cursor.x = 0.0;
                                    cursor.y += 1.0;
                                }
                                (Rect::from_ltrb(cur_pixel.x, cur_pixel.y, cur_pixel.x + bounds.width().ceil() + 1.0, cur_pixel.y + ver_align + bounds.height().ceil() + 1.0), bits)
                            } else {
                                (Rect::ZERO, Default::default())
                            }
                        };
                        // store metadata
                        atlas.map_char_info.insert((chr, re_bits), CharDrawInfo {
                            px_region,
                            px_advance: font_scaled.h_advance(glyph_id).ceil() as _,
                        });
                        for other_chr in kern_chars.iter().cloned() {
                            let glyph_id1 = font.glyph_id(other_chr);
                            let kern01 = font_scaled.kern(glyph_id, glyph_id1);
                            let kern10 = font_scaled.kern(glyph_id1, glyph_id);
                            if kern01 != 0.0 { atlas.map_char_kern.insert((chr, other_chr, re_bits), kern01); }
                            if kern10 != 0.0 { atlas.map_char_kern.insert((other_chr, chr, re_bits), kern10); }
                        }
                    }
                }
pub fn rasterize < F : abFont > ( font : F , atlas : & mut FontAtlas , chars : & [ char ] , bits : u64 , cursor : & mut Vec2 ) { let grid_num_cols = atlas . grid . num_slots . x ; let grid_num_rows = atlas . grid . num_slots . y ; let grid_px_offset = atlas . grid . px_offset ; let grid_px_step = atlas . grid . px_slot_size + atlas . grid . px_gap ; let bpp = atlas . texture . bpp ( ) ; let stride = ( grid_px_offset . x + grid_num_cols * grid_px_step . x ) as usize * bpp ; let texture_data = & mut atlas . texture_data ; let hack = 4.0 ; // TODO: remove this hack (some glyph overflow the given scale != max glyph px height)
 let font_px_scale = atlas . grid . px_slot_size . y - hack ; let font_scaled = font . as_scaled ( font_px_scale ) ; let ver_ascent = font_scaled . ascent ( ) . ceil ( ) ; atlas . map_font_meta . insert ( bits , FontMetadata { px_scale : font_px_scale , px_ascent : ver_ascent + hack , } ) ; atlas . map_char_info . reserve ( chars . len ( ) ) ; let mut kern_chars = atlas . map_char_info . keys ( ) . cloned ( ) . filter_map ( | ( chr , bits1 ) | if bits1 == bits { Some ( chr ) } else { None } ) . collect :: < Vec < _ > > ( ) ; kern_chars . extend ( chars ) ; for chr in chars . iter ( ) . cloned ( ) { // fetch glyph
 let glyph_id = font . glyph_id ( chr ) ; let glyph = glyph_id . with_scale_and_position ( font_px_scale , ab_glyph :: point ( 0.0 , 0.0 ) ) ; // locate and rasterize
 let cur_pixel = grid_px_offset + * cursor * grid_px_step ; debug_assert ! ( cursor x grid_num_cols cursor y grid_num_rows " " atlas grid chars len ( ) cursor cur_pixel ) ; let ( px_region , re_bits ) = { if let Some ( out ) = font . outline_glyph ( glyph ) { let bounds = out . px_bounds ( ) ; let ver_align = ( ver_ascent + bounds . min . y ) . ceil ( ) . max ( 0.0 ) ; let off_index = ( cur_pixel . y + ver_align ) as usize * stride + cur_pixel . x as usize ; out . draw ( | x , y , c | { let index = off_index + y as usize * stride + x as usize ; let value = ( c * 255.0 ) as u8 ; for channel_index in 0 .. bpp { texture_data [ index + channel_index * bpp ] = value ; } } ) ; // next atlas index
 if cursor . x + 1.0 < grid_num_cols { cursor . x += 1.0 ; } else { cursor . x = 0.0 ; cursor . y += 1.0 ; } ( Rect :: from_ltrb ( cur_pixel . x , cur_pixel . y , cur_pixel . x + bounds . width ( ) . ceil ( ) + 1.0 , cur_pixel . y + ver_align + bounds . height ( ) . ceil ( ) + 1.0 ) , bits ) } else { ( Rect :: ZERO , Default :: default ( ) ) } } ; // store metadata
 atlas . map_char_info . insert ( ( chr , re_bits ) , CharDrawInfo { px_region , px_advance : font_scaled . h_advance ( glyph_id ) . ceil ( ) as _ , } ) ; for other_chr in kern_chars . iter ( ) . cloned ( ) { let glyph_id1 = font . glyph_id ( other_chr ) ; let kern01 = font_scaled . kern ( glyph_id , glyph_id1 ) ; let kern10 = font_scaled . kern ( glyph_id1 , glyph_id ) ; if kern01 != 0.0 { atlas . map_char_kern . insert ( ( chr , other_chr , re_bits ) , kern01 ) ; } if kern10 != 0.0 { atlas . map_char_kern . insert ( ( other_chr , chr , re_bits ) , kern10 ) ; } } } }
rasterize a given set of characters at the specified atlas index (ix, iy), record related metrics in the atlas, returns the first free atlas index.
rasterize a given set of characters at the specified atlas index ( ix iy ) record related metrics in the atlas returns the first free atlas index .
font
F
atlas
&mut FontAtlas
chars
&[char]
bits
u64
cursor
&mut Vec2