////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Draw.
        /// </summary>
        /// <param name="foreColor"> The foreground Color.</param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void Draw(Color foreColor)
        {
            var text = _scanner.Token.Text;

            FontSize = tc.MeasureText(text, 0, _scanner.Token.Length);
            tc.DrawText(text, 0, _scanner.Token.Length, startPoint, foreColor);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///  Method: Show Buffer.
        /// </summary>
        /// <param name="dev">        The dev.</param>
        /// <param name="scanner">    The buffer.</param>
        /// <param name="clientSize"> The client Size.</param>
        /// <param name="rowStart">   The top.</param>
        /// <param name="colStart">   The horizontal Percent.</param>
        /// <param name="zoom">       The zoom.</param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public void ShowBuffer(Graphics dev, IScanner scanner, Size clientSize, int rowStart, int colStart, float zoom, Selection selection)
        {
            if (scanner == null || scanner.LineCount == 0)
            {
                return;
            }

            _scanner = scanner;

            if (Math.Abs(_zoom - zoom) > .05)
            {
                _zoom = zoom;
                CreateFonts(EmSize);
            }
            SelectionBackground = BackgroundColor.Lighten(.4);

            tc.SetBackgroundMode(true);

            var inSelect  = false;
            var chkSelect = selection.Length > 0;

            tc.StartDrawing(dev, BackgroundColor, 4, fonts[0]);

            FontSize   = tc.MeasureText("M");
            FontWidth  = FontSize.Width;
            FontHeight = FontSize.Height;
            var rows     = clientSize.Height / FontHeight;
            var cols     = clientSize.Width / FontWidth;
            var leftSkip = colStart;

            // skip lines above view.
            _scanner.MoveToLine(rowStart);

            LeftMargin.X = DrawLineNumbers(scanner.LineNumber, rows, clientSize.Height);
            startPoint.X = LeftMargin.X - leftSkip * FontWidth;
            startPoint.Y = LeftMargin.Y;

            // restrict drawing to just the text part.
            tc.SelectClipRegion(LeftMargin.X - 1, LeftMargin.Y - 1, clientSize.Width, clientSize.Height);

            // todo fix end check here.
            while (!scanner.AtEnd)
            {
                var pos        = scanner.Position;
                var lineOffset = pos - scanner.StartPositionOfLine;

                // handle selection marking
                if (chkSelect)
                {
                    if (!inSelect)
                    {
                        if (pos >= selection.Start)
                        {
                            //  _selStart = new Point(startPoint.X, startPoint.Y);
                            inSelect     = true;
                            tc.BackColor = SelectionBackground;
                            // set background mode correctly for select box.
                            tc.SetBackgroundMode(false);
                        }
                    }
                    else if (pos >= selection.End)
                    {
                        chkSelect = false;
                        tc.SetBackgroundMode(true);
                    }
                }


                var type = scanner.NextToken();

                // handle special cases of Eol and not visible
                if (type == TokenType.Eol)
                {
                    startPoint.X  = LeftMargin.X - leftSkip * FontWidth;
                    startPoint.Y += FontHeight;
                    if (--rows <= 0)
                    {
                        break;
                    }

                    continue;
                }

                // check if visible, skip if not.
                if ((lineOffset + scanner.Token.Length) < leftSkip || lineOffset > cols)
                {
                    continue;
                }


                switch (type)
                {
                case TokenType.WhiteSpace:
                    if (inSelect)
                    {
                        goto default;
                    }

                    startPoint.X += scanner.Token.Length * FontWidth;
                    continue;

                case TokenType.End:     // EOD
                    break;

                //case TokenType.Eol:
                //    startPoint.X = LeftMargin.X;
                //    startPoint.Y += FontHeight;
                //    //int width = lineOffset;
                //    //if (width > RowColSize.Width) RowColSize.Width = width;
                //    --Rows;
                //    continue;


                default:
                    var foreColor = SetFont(type);
                    Draw(foreColor);
                    startPoint.X += FontSize.Width;
                    continue;
                }

                //Rectangle rect = new Rectangle(startPoint, size);
            }
            tc.EndDrawing(dev);

            RowColSize = new Size(_scanner.MaxLineLength, _scanner.LineCount);
        }