fn process_text(&mut self, font: &Font, draw2d: &Draw2D) {

        let mut lines = self.text.lines();

        let mut screen_width = 0_usize;
        let mut screen_height = 0_usize;

        while let Some(line) = lines.next() {

            let mut chars = line.chars();
            let mut line_width = 0;
            while let Some(c) = chars.next() {
                if self.metrics.contains_key(&c) == false {
                    let m= font.rasterize(c, self.font_size);
                    self.metrics.insert(c, m);
                }

                if let Some((metrics, _bitmap)) = self.metrics.get(&c) {
                    line_width += metrics.advance_width.ceil() as usize;
                }
            }

            if line_width > screen_width {
                screen_width = line_width;
            }

            screen_height += self.advance_height;
        }

        //println!("{} x {}", screen_width, screen_height);

        let left_size = 100;
        screen_width += left_size;
        screen_height += left_size;
        self.needs_update = false;

        self.text_buffer = vec![0; screen_width * screen_height * 4];
        self.text_buffer_size = (screen_width, screen_height);

        // Draw it

        let mut scanner = Scanner::new(self.text.as_str());

        let mut x = left_size;
        let mut y = 0;

        let stride = screen_width;

        let mut line_number = 1;

        let mut finished = false;
        let mut color : [u8;4] = self.theme.text;
        let mut number_printed_for_line = 0_usize;

        while finished == false {

            let token = scanner.scan_token();
            let mut printit = false;

            //println!("{:?} : {}", token.kind, token.lexeme);

            match token.kind {

                TokenType::LineFeed => {

                    draw2d.draw_text_rect(&mut self.text_buffer[..], &(0, y, 60, self.advance_height), stride, font, self.font_size, format!("{}", line_number).as_str(), &self.theme.line_numbers, &self.theme.background, crate::draw2d::TextAlignment::Right);
                    number_printed_for_line = line_number;

                    x = left_size;
                    y += self.advance_height;
                    line_number += 1;
                },
                TokenType::Space => { x += self.advance_width },
                TokenType::Eof => {

                    if number_printed_for_line != line_number {
                        draw2d.draw_text_rect(&mut self.text_buffer[..], &(0, y, 60, self.advance_height), stride, font, self.font_size, format!("{}", line_number).as_str(), &self.theme.line_numbers, &self.theme.background, crate::draw2d::TextAlignment::Right);
                    }

                    finished = true },

                TokenType::Identifier if self.text_mode == false => { color = self.theme.identifier; printit = true; },
                TokenType::SingeLineComment if self.text_mode == false => { color = self.theme.comments; printit = true; },
                TokenType::Number if self.text_mode == false => { color = self.theme.number; printit = true; },
                TokenType::String if self.text_mode == false => { color = self.theme.string; printit = true; },
                TokenType::Let if self.text_mode == false => { color = self.theme.keywords; printit = true; },
                TokenType::Quotation if self.text_mode == false => { color = self.theme.string; printit = true; },

                TokenType::LeftBrace | TokenType::RightBrace | TokenType::LeftParen | TokenType::RightParen | TokenType::Dollar => { color = self.theme.brackets; printit = true; },

                _ => {
                    color = self.theme.text;
                    printit = true;
                }
            }

            // Print the current lexeme
            if printit {
                let mut chars = token.lexeme.chars();
                while let Some(c) = chars.next() {

                    if let Some((metrics, bitmap)) = self.metrics.get(&c) {
                        let text_buffer_frame = &mut self.text_buffer[..];

                        for cy in 0..metrics.height {
                            for cx in 0..metrics.width {

                                let fy = (self.font_size as isize - metrics.height as isize - metrics.ymin as isize) as usize;

                                let i = (x + cx + metrics.xmin as usize) * 4 + (y + cy + fy) * stride * 4;
                                let m = bitmap[cx + cy * metrics.width];

                                text_buffer_frame[i..i + 4].copy_from_slice(&draw2d.mix_color(&self.theme.background, &color, m as f64 / 255.0));
                            }
                        }

                        x += self.advance_width;//metrics.advance_width as usize;
                    }
                }
            }
        }
    }
/// Takes the current text and renders it to the text_buffer bitmap
Takes the current text and renders it to the text_buffer bitmap
Takes the current text and renders it to the text_buffer bitmap
fn process_text(&mut self, font: &Font, draw2d: &Draw2D) {
        let mut lines = self.text.lines();
        let mut screen_width = 0_usize;
        let mut screen_height = 0_usize;
        while let Some(line) = lines.next() {
            let mut chars = line.chars();
            let mut line_width = 0;
            while let Some(c) = chars.next() {
                if self.metrics.contains_key(&c) == false {
                    let m= font.rasterize(c, self.font_size);
                    self.metrics.insert(c, m);
                }
                if let Some((metrics, _bitmap)) = self.metrics.get(&c) {
                    line_width += metrics.advance_width.ceil() as usize;
                }
            }
            if line_width > screen_width {
                screen_width = line_width;
            }
            screen_height += self.advance_height;
        }
        //println!("{} x {}", screen_width, screen_height);
        let left_size = 100;
        screen_width += left_size;
        screen_height += left_size;
        self.needs_update = false;
        self.text_buffer = vec![0; screen_width * screen_height * 4];
        self.text_buffer_size = (screen_width, screen_height);
        // Draw it
        let mut scanner = Scanner::new(self.text.as_str());
        let mut x = left_size;
        let mut y = 0;
        let stride = screen_width;
        let mut line_number = 1;
        let mut finished = false;
        let mut color : [u8;4] = self.theme.text;
        let mut number_printed_for_line = 0_usize;
        while finished == false {
            let token = scanner.scan_token();
            let mut printit = false;
            //println!("{:?} : {}", token.kind, token.lexeme);
            match token.kind {
                TokenType::LineFeed => {
                    draw2d.draw_text_rect(&mut self.text_buffer[..], &(0, y, 60, self.advance_height), stride, font, self.font_size, format!("{}", line_number).as_str(), &self.theme.line_numbers, &self.theme.background, crate::draw2d::TextAlignment::Right);
                    number_printed_for_line = line_number;
                    x = left_size;
                    y += self.advance_height;
                    line_number += 1;
                },
                TokenType::Space => { x += self.advance_width },
                TokenType::Eof => {
                    if number_printed_for_line != line_number {
                        draw2d.draw_text_rect(&mut self.text_buffer[..], &(0, y, 60, self.advance_height), stride, font, self.font_size, format!("{}", line_number).as_str(), &self.theme.line_numbers, &self.theme.background, crate::draw2d::TextAlignment::Right);
                    }
                    finished = true },
                TokenType::Identifier if self.text_mode == false => { color = self.theme.identifier; printit = true; },
                TokenType::SingeLineComment if self.text_mode == false => { color = self.theme.comments; printit = true; },
                TokenType::Number if self.text_mode == false => { color = self.theme.number; printit = true; },
                TokenType::String if self.text_mode == false => { color = self.theme.string; printit = true; },
                TokenType::Let if self.text_mode == false => { color = self.theme.keywords; printit = true; },
                TokenType::Quotation if self.text_mode == false => { color = self.theme.string; printit = true; },
                TokenType::LeftBrace | TokenType::RightBrace | TokenType::LeftParen | TokenType::RightParen | TokenType::Dollar => { color = self.theme.brackets; printit = true; },
                _ => {
                    color = self.theme.text;
                    printit = true;
                }
            }
            // Print the current lexeme
            if printit {
                let mut chars = token.lexeme.chars();
                while let Some(c) = chars.next() {
                    if let Some((metrics, bitmap)) = self.metrics.get(&c) {
                        let text_buffer_frame = &mut self.text_buffer[..];
                        for cy in 0..metrics.height {
                            for cx in 0..metrics.width {
                                let fy = (self.font_size as isize - metrics.height as isize - metrics.ymin as isize) as usize;
                                let i = (x + cx + metrics.xmin as usize) * 4 + (y + cy + fy) * stride * 4;
                                let m = bitmap[cx + cy * metrics.width];
                                text_buffer_frame[i..i + 4].copy_from_slice(&draw2d.mix_color(&self.theme.background, &color, m as f64 / 255.0));
                            }
                        }
                        x += self.advance_width;//metrics.advance_width as usize;
                    }
                }
            }
        }
    }
fn process_text ( & mut self , font : & Font , draw2d : & Draw2D ) { let mut lines = self . text . lines ( ) ; let mut screen_width = 0_usize ; let mut screen_height = 0_usize ; while let Some ( line ) = lines . next ( ) { let mut chars = line . chars ( ) ; let mut line_width = 0 ; while let Some ( c ) = chars . next ( ) { if self . metrics . contains_key ( & c ) == false { let m = font . rasterize ( c , self . font_size ) ; self . metrics . insert ( c , m ) ; } if let Some ( ( metrics , _bitmap ) ) = self . metrics . get ( & c ) { line_width += metrics . advance_width . ceil ( ) as usize ; } } if line_width > screen_width { screen_width = line_width ; } screen_height += self . advance_height ; } //println!("{} x {}", screen_width, screen_height); let left_size = 100 ; screen_width += left_size ; screen_height += left_size ; self . needs_update = false ; self . text_buffer = vec ! [ 0 screen_width screen_height 4 ] ; self . text_buffer_size = ( screen_width , screen_height ) ; // Draw it let mut scanner = Scanner :: new ( self . text . as_str ( ) ) ; let mut x = left_size ; let mut y = 0 ; let stride = screen_width ; let mut line_number = 1 ; let mut finished = false ; let mut color : [ u8 ; 4 ] = self . theme . text ; let mut number_printed_for_line = 0_usize ; while finished == false { let token = scanner . scan_token ( ) ; let mut printit = false ; //println!("{:?} : {}", token.kind, token.lexeme); match token . kind { TokenType :: LineFeed => { draw2d . draw_text_rect ( & mut self . text_buffer [ .. ] , & ( 0 , y , 60 , self . advance_height ) , stride , font , self . font_size , format ! ( " " line_number ) . as_str ( ) , & self . theme . line_numbers , & self . theme . background , crate :: draw2d :: TextAlignment :: Right ) ; number_printed_for_line = line_number ; x = left_size ; y += self . advance_height ; line_number += 1 ; } , TokenType :: Space => { x += self . advance_width } , TokenType :: Eof => { if number_printed_for_line != line_number { draw2d . draw_text_rect ( & mut self . text_buffer [ .. ] , & ( 0 , y , 60 , self . advance_height ) , stride , font , self . font_size , format ! ( " " line_number ) . as_str ( ) , & self . theme . line_numbers , & self . theme . background , crate :: draw2d :: TextAlignment :: Right ) ; } finished = true } , TokenType :: Identifier if self . text_mode == false => { color = self . theme . identifier ; printit = true ; } , TokenType :: SingeLineComment if self . text_mode == false => { color = self . theme . comments ; printit = true ; } , TokenType :: Number if self . text_mode == false => { color = self . theme . number ; printit = true ; } , TokenType :: String if self . text_mode == false => { color = self . theme . string ; printit = true ; } , TokenType :: Let if self . text_mode == false => { color = self . theme . keywords ; printit = true ; } , TokenType :: Quotation if self . text_mode == false => { color = self . theme . string ; printit = true ; } , TokenType :: LeftBrace | TokenType :: RightBrace | TokenType :: LeftParen | TokenType :: RightParen | TokenType :: Dollar => { color = self . theme . brackets ; printit = true ; } , _ => { color = self . theme . text ; printit = true ; } } // Print the current lexeme if printit { let mut chars = token . lexeme . chars ( ) ; while let Some ( c ) = chars . next ( ) { if let Some ( ( metrics , bitmap ) ) = self . metrics . get ( & c ) { let text_buffer_frame = & mut self . text_buffer [ .. ] ; for cy in 0 .. metrics . height { for cx in 0 .. metrics . width { let fy = ( self . font_size as isize - metrics . height as isize - metrics . ymin as isize ) as usize ; let i = ( x + cx + metrics . xmin as usize ) * 4 + ( y + cy + fy ) * stride * 4 ; let m = bitmap [ cx + cy * metrics . width ] ; text_buffer_frame [ i .. i + 4 ] . copy_from_slice ( & draw2d . mix_color ( & self . theme . background , & color , m as f64 / 255.0 ) ) ; } } x += self . advance_width ; //metrics.advance_width as usize; } } } } }
Takes the current text and renders it to the text_buffer bitmap
Takes the current text and renders it to the text_buffer bitmap
&mut self
font
&Font
draw2d
&Draw2D
&mut self
font
&Font
draw2d
&Draw2D