public RoslynEditor() : base() { formatting ["default"] = new TextFormatting(Colors.Jet, Colors.Transparent); formatting ["TypeSyntax"] = new TextFormatting(Colors.DarkCyan, Colors.Transparent); formatting ["DocumentationCommentTrivia"] = new TextFormatting(Colors.GreenYellow, Colors.Transparent); formatting ["DisabledTextTrivia"] = new TextFormatting(Colors.Grey, Colors.Transparent); formatting ["Trivia"] = new TextFormatting(Colors.Green, Colors.Transparent); formatting ["Punctuation"] = new TextFormatting(Colors.Black, Colors.Transparent, false); formatting ["Name"] = new TextFormatting(Colors.Jet, Colors.Transparent); formatting ["LiteralExpression"] = new TextFormatting(Colors.FireBrick, Colors.Transparent, false, true); formatting ["PredefinedType"] = new TextFormatting(Colors.DarkCyan, Colors.Transparent, false); formatting ["PrimaryFunction"] = new TextFormatting(Colors.SteelBlue, Colors.Transparent, true); formatting ["ContextualKeyword"] = new TextFormatting(Colors.DarkBlue, Colors.Transparent, true); formatting ["keyword"] = new TextFormatting(Colors.Blue, Colors.Transparent); formatting ["GlobalMemberDeclaration"] = new TextFormatting(Colors.Red, Colors.Transparent); formatting ["InstanceExpression"] = new TextFormatting(Colors.Jet, Colors.Transparent); formatting ["InstanceExpression"] = new TextFormatting(Colors.Jet, Colors.Transparent); formatting ["NamespaceMemberDeclaration"] = new TextFormatting(Colors.Jet, Colors.Transparent); formatting ["PreprocessorDirective"] = new TextFormatting(Colors.DeepPink, Colors.Transparent, true); formatting ["TypeDeclaration"] = new TextFormatting(Colors.Lavender, Colors.Transparent); /*formatting ["constant"] = new TextFormatting (Color.Blue, Color.Transparent, true); * formatting ["primitive"] = new TextFormatting (Color.DarkCyan, Color.Transparent); * formatting ["operator"] = new TextFormatting (Color.DarkRed, Color.Transparent, true); * formatting ["modifier"] = new TextFormatting (Color.RoyalBlue, Color.Transparent); * formatting ["typekind"] = new TextFormatting (Color.OliveDrab, Color.Transparent); * formatting ["async"] = new TextFormatting (Color.YellowGreen, Color.Transparent); * formatting ["linq"] = new TextFormatting (Color.Yellow, Color.Transparent); * formatting ["preproc"] = new TextFormatting (Color.DarkOrange, Color.Transparent, true); * formatting ["comment"] = new TextFormatting (Color.Green, Color.Transparent, false, true); * * formatting ["PredefinedType"] = new TextFormatting (Color.Red, Color.Transparent, true); * formatting ["identifier"] = new TextFormatting (Color.Jet, Color.Transparent, true); * formatting ["litteral"] = new TextFormatting (Color.Crimson, Color.Transparent, false, true);*/ /*formatting.Add ((int)XMLParser.TokenType.AttributeName, new TextFormatting (Color.DarkSlateGrey, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.ElementName, new TextFormatting (Color.DarkBlue, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.ElementStart, new TextFormatting (Color.Black, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.ElementEnd, new TextFormatting (Color.Black, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.ElementClosing, new TextFormatting (Color.Black, Color.Transparent)); * * formatting.Add ((int)XMLParser.TokenType.AttributeValueOpening, new TextFormatting (Color.Crimson, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.AttributeValueClosing, new TextFormatting (Color.Crimson, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.AttributeValue, new TextFormatting (Color.FireBrick, Color.Transparent, false, true)); * formatting.Add ((int)XMLParser.TokenType.XMLDecl, new TextFormatting (Color.ForestGreen, Color.Transparent)); * formatting.Add ((int)XMLParser.TokenType.Content, new TextFormatting (Color.DimGrey, Color.Transparent, false, true)); * * formatting.Add ((int)BufferParser.TokenType.BlockComment, new TextFormatting (Color.Grey, Color.Transparent, false, true)); * formatting.Add ((int)BufferParser.TokenType.LineComment, new TextFormatting (Color.Grey, Color.Transparent, false, true)); * formatting.Add ((int)BufferParser.TokenType.OperatorOrPunctuation, new TextFormatting (Color.Black, Color.Transparent)); * formatting.Add ((int)8300, new TextFormatting (Color.Teal, Color.Transparent));*/ }
void drawParsedCodeLine(Context gr, double x, double y, int i, int lineIndex) { int lPtr = 0; CodeLine cl = PrintedLines[i]; for (int t = 0; t < cl.Tokens.Count; t++) { string lstr = cl.Tokens [t].PrintableContent; if (lPtr < ScrollX) { if (lPtr - ScrollX + lstr.Length <= 0) { lPtr += lstr.Length; continue; } lstr = lstr.Substring(ScrollX - lPtr); lPtr += ScrollX - lPtr; } Color bg = this.Background; Color fg = this.Foreground; Color selbg = this.SelectionBackground; Color selfg = this.SelectionForeground; FontSlant fts = FontSlant.Normal; FontWeight ftw = FontWeight.Normal; if (formatting.ContainsKey((int)cl.Tokens [t].Type)) { TextFormatting tf = formatting [(int)cl.Tokens [t].Type]; bg = tf.Background; fg = tf.Foreground; if (tf.Bold) { ftw = FontWeight.Bold; } if (tf.Italic) { fts = FontSlant.Italic; } } gr.SelectFontFace(Font.Name, fts, ftw); gr.SetSourceColor(fg); gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lstr); gr.Fill(); if (buffer.SelectionInProgress && lineIndex >= buffer.SelectionStart.Y && lineIndex <= buffer.SelectionEnd.Y && !(lineIndex == buffer.SelectionStart.Y && lPtr + lstr.Length <= selStartCol) && !(lineIndex == buffer.SelectionEnd.Y && selEndCol <= lPtr)) { double rLineX = x, rLineY = y, rLineW = lstr.Length * fe.MaxXAdvance; double startAdjust = 0.0; if ((lineIndex == buffer.SelectionStart.Y) && (selStartCol < lPtr + lstr.Length) && (selStartCol > lPtr)) { startAdjust = (selStartCol - lPtr) * fe.MaxXAdvance; } rLineX += startAdjust; if ((lineIndex == buffer.SelectionEnd.Y) && (selEndCol < lPtr + lstr.Length)) { rLineW = (selEndCol - lPtr) * fe.MaxXAdvance; } rLineW -= startAdjust; gr.Save(); gr.Operator = Operator.Source; gr.Rectangle(rLineX, rLineY, rLineW, fe.Height); gr.SetSourceColor(selbg); gr.FillPreserve(); gr.Clip(); gr.Operator = Operator.Over; gr.SetSourceColor(selfg); gr.MoveTo(x, y + fe.Ascent); gr.ShowText(lstr); gr.Fill(); gr.Restore(); } x += (int)lstr.Length * fe.MaxXAdvance; lPtr += lstr.Length; } }
void printToken(string lstr, SyntaxKind kind, bool trivia = false) { checkPrintMargin(); TextFormatting tf = editor.formatting ["default"]; if (SyntaxFacts.IsTypeSyntax(kind)) { tf = editor.formatting ["TypeSyntax"]; } else if (SyntaxFacts.IsPreprocessorDirective(kind)) { tf = editor.formatting ["PreprocessorDirective"]; } else if (SyntaxFacts.IsDocumentationCommentTrivia(kind)) { tf = editor.formatting ["DocumentationCommentTrivia"]; } else if (kind == SyntaxKind.DisabledTextTrivia) { tf = editor.formatting ["DisabledTextTrivia"]; } else if (SyntaxFacts.IsTrivia(kind)) { tf = editor.formatting ["Trivia"]; } else if (SyntaxFacts.IsPunctuation(kind)) { tf = editor.formatting ["Punctuation"]; } else if (SyntaxFacts.IsName(kind)) { tf = editor.formatting ["Name"]; } else if (SyntaxFacts.IsLiteralExpression(kind)) { tf = editor.formatting ["LiteralExpression"]; } else if (SyntaxFacts.IsPredefinedType(kind)) { tf = editor.formatting ["PredefinedType"]; } else if (SyntaxFacts.IsPrimaryFunction(kind)) { tf = editor.formatting ["PrimaryFunction"]; } else if (SyntaxFacts.IsContextualKeyword(kind)) { tf = editor.formatting ["ContextualKeyword"]; } else if (SyntaxFacts.IsKeywordKind(kind)) { tf = editor.formatting ["keyword"]; } else if (SyntaxFacts.IsGlobalMemberDeclaration(kind)) { tf = editor.formatting ["GlobalMemberDeclaration"]; } else if (SyntaxFacts.IsInstanceExpression(kind)) { tf = editor.formatting ["InstanceExpression"]; } else if (SyntaxFacts.IsNamespaceMemberDeclaration(kind)) { tf = editor.formatting ["NamespaceMemberDeclaration"]; } else if (SyntaxFacts.IsTypeDeclaration(kind)) { tf = editor.formatting ["TypeDeclaration"]; } FontSlant fts = FontSlant.Normal; FontWeight ftw = FontWeight.Normal; if (tf.Bold) { ftw = FontWeight.Bold; } if (tf.Italic) { fts = FontSlant.Italic; } ctx.SelectFontFace(editor.Font.Name, fts, ftw); ctx.SetSourceColor(tf.Foreground); Console.WriteLine(tf.Foreground); int diffX = currentCol - editor.ScrollX; string str = lstr; if (diffX < 0) { if (diffX + lstr.Length > 0) { str = lstr.Substring(-diffX); } else { currentCol += lstr.Length; return; } } else { diffX = 0; } ctx.MoveTo(bounds.X + editor.leftMargin + (currentCol - editor.ScrollX - diffX) * fe.MaxXAdvance, y + fe.Ascent); ctx.ShowText(str); currentCol += lstr.Length; }