public bool PrintSpace(RichTextToken space) { if (_y + _lineHeight * HeightPart < _renderContext.Rect.Bottom) { if (_x + _spaceWidth >= _renderContext.Rect.Right) { return(newLine()); } var targetRect = new RectangleF(_x, _y, _spaceWidth, _lineHeight); var printBatch = new RenderBatch(space.IsHighlighted); if (space.IsHighlighted) { printHighlight(targetRect, printBatch, space.IsContext); } printBatch.Add(targetRect, (rect, hb, he) => { _renderContext.TextSelection.PrintedTokens.Add((space, rect)); printSelection(rect, space); printCaret(rect, space); }); _lineQueue.Add(printBatch); _x += _spaceWidth; return(true); } return(false); }
private void printHighlight(RectangleF targetRect, RenderBatch batch, bool isContext) { batch.Add(targetRect, (rectF, hb, he) => { var rect = rectF.Round(); var fillRect = (RectangleF)rect; fillRect.Offset(-0.5f, -0.5f); var brush = isContext ? _highlightContextBrush : _highlightBrush; _renderContext.Graphics.FillRectangle(brush, fillRect); int left = rect.Left - 1; int top = rect.Top - 1; int bottom = rect.Bottom; int right = rect.Right; if (hb) { _renderContext.Graphics.DrawLine(_pen, left, top, left, bottom); } if (he) { _renderContext.Graphics.DrawLine(_pen, right, top, right, bottom); } _renderContext.Graphics.DrawLine(_pen, left, top, right, top); _renderContext.Graphics.DrawLine(_pen, left, bottom, right, bottom); }); }
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; } } }