示例#1
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            //   ushort _nData =  range.tb.TextSource[range.FromLine][range.Start.iChar].nCustomData;
            ushort _nData     = CwRange.fGetStyleData(range);
            char   _nBackData = (char)((_nData & 0x00F0) >> 4);

            //draw background
            Brush backgroundBrush = CwFCTB.fGetBrush(_nBackData);

            if (backgroundBrush != Brushes.Black) // TODO or same as background color
            {
                Rectangle rect = new Rectangle(position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth + 1, range.tb.CharHeight);
                if (rect.Width == 0)
                {
                    return;
                }


                gr.FillRectangle(backgroundBrush, rect);
            }
        }
示例#2
0
        public override void Draw(Graphics gr, Point position, Range range)
        {
            ushort _nData     = CwRange.fGetStyleData(range);
            char   _nForeData = (char)((_nData & 0x000F));



            //draw background
            // if (BackgroundBrush != null)
            //      gr.FillRectangle(BackgroundBrush, position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight);
            //draw chars
            using (var f = new Font(range.tb.Font, FontStyle))
            {
                Line  line = range.tb[range.Start.iLine];
                float dx   = range.tb.CharWidth;
                float y    = position.Y + range.tb.LineInterval / 2;
                float x    = position.X - range.tb.CharWidth / 3;


                Brush ForeBrush = CwFCTB.fGetBrush(_nForeData);

                if (ForeBrush == null)
                {
                    ForeBrush = new SolidBrush(range.tb.ForeColor);
                }


                //  ForeBrush = Brushes.Blue;

                if (range.tb.ImeAllowed)
                {
                    //IME mode
                    for (int i = range.Start.iChar; i < range.End.iChar; i++)
                    {
                        SizeF size = FastColoredTextBox.GetCharSize(f, line[i].c);

                        var   gs = gr.Save();
                        float k  = size.Width > range.tb.CharWidth + 1 ? range.tb.CharWidth / size.Width : 1;
                        gr.TranslateTransform(x, y + (1 - k) * range.tb.CharHeight / 2);
                        gr.ScaleTransform(k, (float)Math.Sqrt(k));
                        gr.DrawString(line[i].c.ToString(), f, ForeBrush, 0, 0, stringFormat);
                        gr.Restore(gs);
                        x += dx;
                    }
                }
                else
                {
                    //         gr.DrawString(   range.Text, f, ForeBrush, x, y, stringFormat);


                    TextRenderer.DrawText(gr, range.Text, f, new Point((int)x, (int)y), CwFCTB.fGetColor(_nForeData), Color.Transparent);


                    /*
                     * //classic mode
                     * for (int i = range.Start.iChar; i < range.End.iChar; i++) {
                     *  //draw char
                     *  gr.DrawString(line[i].c.ToString(), f, ForeBrush, x, y, stringFormat);
                     *  x += dx;
                     * }
                     */
                }
            }
        }