public void Draw(Renderer renderer) { DebugUtil.DebugCode(() => { renderer.SetColor(Color.Red); renderer.FillRect(new Rect2D(_location, new Size2D(8, 2))); renderer.FillRect(new Rect2D(_location, new Size2D(2, 8))); }); renderer.SetColor(_color); renderer.SetFont(_font); renderer.DrawString(_buffer.WrittenSpan, _location); }
/// <summary> /// /// </summary> public TextPresenter(ICanvasContext canvasContext, string settingsJson) { _doc = new TextDocument(settingsJson); _view = new TextView(canvasContext, _doc, settingsJson); DebugUtil.DebugCode(() => { canvasContext.Created += _ => { InsertText(string.Format("あ{0}い{1}う え\tお{2}", StringUtil.Cr, StringUtil.Lf, StringUtil.CrLf)); InsertText(string.Format("か{0}き{1}く け\tこ{2}", StringUtil.Cr, StringUtil.CrLf, StringUtil.Lf)); InsertText(string.Format("さ{0}し{1}す せ\tそ{2}", StringUtil.Lf, StringUtil.Cr, StringUtil.CrLf)); InsertText(string.Format("た{0}ち{1}つ て\tと{2}", StringUtil.Lf, StringUtil.CrLf, StringUtil.Cr)); InsertText(string.Format("な{0}に{1}ぬ ね\tの{2}", StringUtil.CrLf, StringUtil.Cr, StringUtil.Lf)); InsertText(string.Format("は{0}ひ{1}ふ へ\tほ{2}", StringUtil.CrLf, StringUtil.Lf, StringUtil.Cr)); }; }); }
/// <summary> /// /// </summary> private IEnumerable <ICharMetric> EnumerateCharMetricsByLine(int lineIndex, bool isTabProcess, bool isAddMetaChar) { var chars = _textView.Doc.Lines[lineIndex].Text.AsEnumerable(); if (isAddMetaChar) { if (lineIndex < _textView.Doc.Lines.LastIndex()) { chars = chars.Append(CharUtil.Space); } DebugUtil.DebugCode(() => { if (lineIndex < _textView.Doc.Lines.LastIndex()) { chars = chars.SkipLast(1).Append('↓'); } else { chars = chars.Concat("[EOF]"); } }); } var lineHeight = _textView.GetLineHeight(); var columnCounter = new ColumnCounter(_textView._settings.tabWidth); var originalIndex = 0; var index = 0; var lineLength = _textView.Doc.Lines[lineIndex].Length; var x = 0.0; var chItem = new CharMetric(); foreach (var ch in chars) { columnCounter.Add(ch); var sourceChar = ch; var color = Color.Black; var backgroundColor = Color.Transparent; #warning test //if (!CharUtil.CanDraw(ch) && ch != CharUtil.Tab) //{ // // バイナリファイルを開いた場合でも、それとなく表示できるようにしておく // ch = '?'; //} if (sourceChar == CharUtil.Tab && isTabProcess) { sourceChar = CharUtil.Space; for (var i = 0; i < columnCounter.LastCharCount; i++) { DebugUtil.DebugCode(() => { sourceChar = i == 0 ? '>' : '.'; color = Color.DarkCyan; backgroundColor = Color.FromRgb(0x00aaaa); }); var width = _textView.AsciiFont.MeasureChar(sourceChar).Width; yield return(chItem.Init( lineIndex, lineHeight, sourceChar, x, index, originalIndex, 1, color, backgroundColor, _textView.AsciiFont, width, _textView._settings.lineHeightAdjust / 2.0)); x += width; index++; } } else { DebugUtil.DebugCode(() => { if (sourceChar == CharUtil.FullWidthSpace) { sourceChar = '□'; color = Color.DarkCyan; } if (originalIndex >= lineLength) { color = Color.DarkCyan; } }); var tempChar = (sourceChar == CharUtil.Tab) ? CharUtil.Space : sourceChar; var font = CharUtil.IsAscii(tempChar) ? _textView.AsciiFont : _textView.JpFont; var width = font.MeasureChar(tempChar).Width *columnCounter.LastCharCount; yield return(chItem.Init( lineIndex, lineHeight, sourceChar, x, index, originalIndex, columnCounter.LastColumnCount, color, backgroundColor, font, width, _textView._settings.lineHeightAdjust / 2.0)); x += width; index++; } originalIndex++; } }