private void printWord(List <RichTextToken> word) { foreach (var token in word) { var location = new PointF(_x, _y); var width = getTokenWidth(_renderContext.Text, token); var overflow = _x + width >= _renderContext.Rect.Right; RectangleF targetRect; if (overflow) { targetRect = new RectangleF(location, new SizeF(_renderContext.Rect.Right - _x, _lineHeight)); } else { targetRect = new RectangleF(location, new SizeF(width, _lineHeight)); } var printBatch = new RenderBatch(token.IsHighlighted); if (token.IsHighlighted) { printHighlight(targetRect, printBatch, token.IsContext); } string tokenText = _renderContext.Text.Substring(token.Index, token.Length); if (token.IconName == null) { if (overflow) { while (tokenText.Length > 0 && getLineSize(tokenText).Width > targetRect.Width) { tokenText = tokenText.Substring(0, tokenText.Length - 1); } } if (tokenText.Length > 0) { printBatch.Add( targetRect, (rect, hb, he) => { _renderContext.TextSelection.PrintedTokens.Add((token, rect)); var foreColor = _renderContext.ForeColor; if (printSelection(rect, token)) { foreColor = _renderContext.SelectionForeColor; } var textRect = rect; textRect.Inflate(1, 0); textRect.Offset(1, 0); _renderContext.Graphics.DrawText(tokenText, _renderContext.Font, textRect.Round(), foreColor); printCaret(rect, token); }); } } else { if (token.IconNeedsShadow) { printBatch.Add(targetRect, (rect, hb, he) => { _renderContext.TextSelection.PrintedTokens.Add((token, rect)); var icon = _iconRecognizer.GetIcon(token.IconName, _lineHeight.Round() - 1); var iconRect = new RectangleF(rect.Location.Round(), icon.Size); printSelection(rect, token); var shadowOffset = _iconShadowOffset.MultiplyBy(_lineHeight / 16f); var shadowRect = iconRect; shadowRect.Offset(shadowOffset); _renderContext.Graphics.FillEllipse(_shadowBrush, shadowRect); _renderContext.Graphics.DrawImage(icon, iconRect); printCaret(rect, token); }); } else { printBatch.Add(targetRect, (rect, hb, he) => { _renderContext.TextSelection.PrintedTokens.Add((token, rect)); var icon = _iconRecognizer.GetIcon(token.IconName, _lineHeight.Round()); var iconRect = new RectangleF(rect.Location.Round(), icon.Size); printSelection(rect, token); _renderContext.Graphics.DrawImage(icon, iconRect); printCaret(rect, token); }); } } _lineQueue.Add(printBatch); _x += targetRect.Width; if (overflow) { break; } } }
public void Add(RenderBatch renderAction) { _list.Add(renderAction); }