public void DrawToGraphics(FormattedCode code, CodeRenderingContext args, Rectangle viewport) { UiExceptionHelper.CheckNotNull(code, "code"); UiExceptionHelper.CheckNotNull(args, "args"); ClassifiedTokenCollection line; PaintLineLocation[] lines; ClassifiedToken token; float fontHeight; string text; float tk_width; int i; float x; fontHeight = LineIndexToYCoordinate(1, args.Graphics, args.Font); lines = ViewportLines(code, viewport, fontHeight); foreach (PaintLineLocation paintLine in lines) { // All lines that differ from CurrentLine are displayed // in using different styles of Brush to make a distinction // between code, keyword, comments. if (paintLine.LineIndex != args.CurrentLine) { line = code[paintLine.LineIndex]; x = 0; text = line.Text; for (i = 0; i < line.Count; ++i) { token = line[i]; args.Graphics.DrawString(token.Text, args.Font, args.GetBrush(token.Tag), paintLine.Location.X + x, paintLine.Location.Y); tk_width = measureStringWidth(args.Graphics, args.Font, text, token.IndexStart, token.Text.Length); x += tk_width; } continue; } // The current line is emphasized by using a // specific couples of Background & Foreground colors args.Graphics.FillRectangle( args.CurrentLineBackBrush, 0, paintLine.Location.Y, viewport.Width, fontHeight); args.Graphics.DrawString( paintLine.Text, args.Font, args.CurrentLineForeBrush, paintLine.Location.X, paintLine.Location.Y); } return; }
public void SetUp() { _renderer = new DefaultCodeRenderer(); ICodeFormatter formatter = new PlainTextCodeFormatter(); _empty = formatter.Format(""); _text3x7 = formatter.Format( "111\r\n" + "222\r\n" + "333\r\n" + "444\r\n" + "555\r\n" + "666\r\n" + "777\r\n"); _loremIpsum = formatter.Format( "Lorem ipsum dolor sit\r\n" + "amet, consectetur adipiscing elit.\r\n" + "Maecenas a nisi. In imperdiet, orci in\r\n" + "porta facilisis,\r\n" + "odio purus iaculis est, non varius urna turpis in mi.\r\n" + // longest line "Nullam dictum. Ut iaculis dignissim nulla.\r\n" + "Nullam condimentum porttitor leo.\r\n" + "Integer a odio et\r\n" + "velit suscipit pulvinar."); Image img = new Bitmap(100, 100); _args = new CodeRenderingContext(); _args.Graphics = Graphics.FromImage(img); _args.Font = new Font("Courier New", 12); return; }
void CheckPens(CodeRenderingContext context) { Assert.NotNull(_context.BackgroundPen); Assert.NotNull(_context.CurrentLineBackPen); Assert.NotNull(_context.CurrentLineForePen); Assert.NotNull(_context.KeywordPen); Assert.NotNull(_context.CommentPen); Assert.NotNull(_context.CodePen); Assert.NotNull(_context.StringPen); Assert.That(_context.GetPen(ClassificationTag.Code), Is.SameAs(_context.CodePen)); Assert.That(_context.GetPen(ClassificationTag.Comment), Is.SameAs(_context.CommentPen)); Assert.That(_context.GetPen(ClassificationTag.Keyword), Is.SameAs(_context.KeywordPen)); Assert.That(_context.GetPen(ClassificationTag.String), Is.SameAs(_context.StringPen)); return; }
void CheckBrushes(CodeRenderingContext context) { Assert.NotNull(_context.BackgroundBrush); Assert.NotNull(_context.CurrentLineBackBrush); Assert.NotNull(_context.CurrentLineForeBrush); Assert.NotNull(_context.KeywordBrush); Assert.NotNull(_context.CommentBrush); Assert.NotNull(_context.CodeBrush); Assert.NotNull(_context.StringBrush); Assert.That(_context.GetBrush(ClassificationTag.Code), Is.SameAs(_context.CodeBrush)); Assert.That(_context.GetBrush(ClassificationTag.Comment), Is.SameAs(_context.CommentBrush)); Assert.That(_context.GetBrush(ClassificationTag.Keyword), Is.SameAs(_context.KeywordBrush)); Assert.That(_context.GetBrush(ClassificationTag.String), Is.SameAs(_context.StringBrush)); return; }
public void SetUp() { TestingCodeBox box = new TestingCodeBox(); _context = box.RenderingContext; }
private void createGraphics() { Graphics gCurrent = CreateGraphics(); Image img = new Bitmap(10, 10, gCurrent); Graphics gImg = Graphics.FromImage(img); gCurrent.Dispose(); _workingContext = new CodeRenderingContext(); _workingContext.Graphics = gImg; _workingContext.Font = Font; _workingContext.CurrentLine = -1; _workingContext.BackgroundColor = Color.White; _workingContext.CurrentLineBackColor = Color.Red; _workingContext.CurrentLineForeColor = Color.White; _workingContext.CodeColor = Color.Black; _workingContext.CommentColor = Color.Green; _workingContext.KeywordColor = Color.Blue; _workingContext.StringColor = Color.Red; return; }
public void DrawToGraphics(FormattedCode code, CodeRenderingContext args, Rectangle viewport) { UiExceptionHelper.CheckNotNull(code, "code"); UiExceptionHelper.CheckNotNull(args, "args"); ClassifiedTokenCollection line; PaintLineLocation[] lines; ClassifiedToken token; float fontHeight; string text; float tk_width; int i; float x; fontHeight = LineIndexToYCoordinate(1, args.Graphics, args.Font); lines = ViewportLines(code, viewport, fontHeight); foreach (PaintLineLocation paintLine in lines) { // All lines that differ from CurrentLine are displayed // in using different styles of Brush to make a distinction // between code, keyword, comments. if (paintLine.LineIndex != args.CurrentLine) { line = code[paintLine.LineIndex]; x = 0; text = line.Text; for (i = 0; i < line.Count; ++i) { token = line[i]; args.Graphics.DrawString(token.Text, args.Font, args.GetBrush(token.Tag), paintLine.Location.X + x, paintLine.Location.Y); tk_width = measureStringWidth(args.Graphics, args.Font, text, token.IndexStart, token.Text.Length); x += tk_width; } continue; } // The current line is emphasized by using a // specific couples of Background & Foreground colors args.Graphics.FillRectangle( args.CurrentLineBackBrush, 0, paintLine.Location.Y, viewport.Width, fontHeight); args.Graphics.DrawString( paintLine.Text, args.Font, args.CurrentLineForeBrush, paintLine.Location.X, paintLine.Location.Y); } return; }
public void DrawToGraphics(FormattedCode code, CodeRenderingContext args, Rectangle viewport) { CURRENTLINE_INDEX = args.CurrentLine; }