protected string GetText(Tree tree) { string s = TreeTextProvider.Text(tree); s = Utils.EscapeWhitespace(s, true); return(s); }
protected void GenerateBox(TextWriter writer, Tree parent) { // draw the box in the background var box = BoundsOfNode(parent); writer.Write(Rect("" + box.X, "" + box.Y, "" + box.Width, "" + box.Height, "fill:orange; stroke:rgb(0,0,0);", "rx=\"1\"")); // draw the text on top of the box (possibly multiple lines) string line = TreeTextProvider.Text(parent).Replace("<", "<").Replace(">", ">"); int fontBoxSize = 10; int x = (int)box.X + 2; int y = (int)box.Y + fontBoxSize - 1; string style = string.Format("font-family:sans-serif;font-size:{0}px;", fontBoxSize); writer.Write(Text("" + x, "" + y, style, line)); }
protected void PaintBox(Graphics g, Tree tree) { var box = BoundsOfNode(tree); // draw the box in the background bool ruleFailedAndMatchedNothing = false; if (tree is ParserRuleContext ctx) { ruleFailedAndMatchedNothing = ctx.exception != null && ctx.Stop != null && ctx.Stop.TokenIndex < ctx.Start.TokenIndex; } if (IsHighlighted(tree) || tree is IErrorNode || ruleFailedAndMatchedNothing) { var color = boxColor; if (IsHighlighted(tree)) { color = highlightedBoxColor; } if (tree is IErrorNode || ruleFailedAndMatchedNothing) { color = LIGHT_RED; } g.FillRectangle(color, box.Center.X, box.BottomLeft.Y, box.Width - 1, box.Height - 1); } //g.DrawRectangle(borderColor, box.X, box.Y, box.Width - 1, box.Height - 1); // draw the text on top of the box (possibly multiple lines) string s = TreeTextProvider.Text(tree); string[] lines = s.Split('\n'); float x = box.X + arcSize / 2 + nodeWidthPadding; float y = box.BottomLeft.Y + font.Ascent + font.Leading + 1 + nodeHeightPadding; for (int i = 0; i < lines.Length; i++) { Text(g, lines[i], new PointF(x, y)); y += font.LineHeight; } }