public void RenderLabel(DrawingContext dc, string label) { FormattedText ft = new FormattedText(label, System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS, FlowDirection.LeftToRight, new Typeface("Arial"), 10, Brushes.White); Point labelLocation = new Point(_boundingRect.Left-25, (_boundingRect.Bottom + _boundingRect.Top)/2 - 10); Geometry geom = ft.BuildHighlightGeometry(labelLocation); Pen backgroundPen = new Pen(Brushes.Black,1); dc.DrawGeometry(Brushes.Black, backgroundPen, geom); dc.DrawText(ft, labelLocation); }
internal void RenderLines(DrawingContext dc) { for (int i=0; i<_lineResults.Length; i++) { FixedLineResult lineResult = _lineResults[i]; Pen pen = new Pen(Brushes.Red, 1); Rect layoutBox = lineResult.LayoutBox; dc.DrawRectangle(null, pen , layoutBox); CultureInfo EnglishCulture = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; FormattedText ft = new FormattedText(i.ToString(), EnglishCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 10, Brushes.White); Point labelLocation = new Point(layoutBox.Left-25, (layoutBox.Bottom + layoutBox.Top)/2 - 10); Geometry geom = ft.BuildHighlightGeometry(labelLocation); Pen backgroundPen = new Pen(Brushes.Black,1); dc.DrawGeometry(Brushes.Black, backgroundPen, geom); dc.DrawText(ft, labelLocation); } }
// rendering protected override void OnRender(DrawingContext drawingContext) { // draw background drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, ActualWidth, ActualHeight))); drawingContext.DrawRectangle(BackgroundBrush, new Pen(), new Rect(0, 0, ActualWidth, ActualHeight)); // draw text if (Text == string.Empty) { return; } var formattedText = new FormattedText( Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(FontFamily.Source), FontSize, ForegroundBrush); var leftMargin = 4.0 + BorderThickness.Left + LineNumberMarginWidth; var topMargin = 2.0 + BorderThickness.Top; // Background highlight if (HighlightText != null && HighlightText.Any()) { foreach (string text in HighlightText) { var index = 0; var lastIndex = Text.LastIndexOf(text, StringComparison.OrdinalIgnoreCase); while (index <= lastIndex) { index = Text.IndexOf(text, index, StringComparison.OrdinalIgnoreCase); Geometry geom = formattedText.BuildHighlightGeometry(new Point(leftMargin, topMargin - VerticalOffset), index, text.Length); if (geom != null) { drawingContext.DrawGeometry(HighlightBrush, null, geom); } index += 1; } } } HighlightSyntax(formattedText); // left from first char boundary var leftBorder = GetRectFromCharacterIndex(0).Left; if (!Double.IsInfinity(leftBorder)) { _leftTextBorder = leftBorder; } drawingContext.DrawText(formattedText, new Point(_leftTextBorder - HorizontalOffset, topMargin - VerticalOffset)); // draw lines if (GetLastVisibleLineIndex() != -1) { LastLineNumberFormat = GetLineNumbers(); } if (LastLineNumberFormat != null) { LastLineNumberFormat.SetForegroundBrush(LineNumberBrush); drawingContext.DrawText(LastLineNumberFormat, new Point(3, topMargin)); } }
/// <summary> /// Render all input data as hex-formatted text lines /// </summary> /// <param name="dc"></param> protected override void OnRender(DrawingContext dc) { Stopwatch watch = new Stopwatch(); watch.Start(); // Draw background object objBackgroundBrush = ReadLocalValue(BackgroundProperty); if (!object.ReferenceEquals(objBackgroundBrush, DependencyProperty.UnsetValue)) { dc.DrawRectangle(objBackgroundBrush as Brush, null, new Rect(new Point(0, 0), RenderSize)); } if (Data == null) return;// nothing to render // total data line count _lineCount = m_byteCount / 16; if (m_byteCount % 16 > 0) _lineCount++; // loop by byte collection IEnumerator<byte> en = Data.GetEnumerator(); double y = Padding.Top; Typeface tf = new Typeface(FontFamily, FontStyles.Normal, FontWeight, FontStretches.Normal); float percentage = 0; for (int i = 0; i < _lineCount; ++i) { var point = new Point(Padding.Left, (int) Math.Ceiling(y)); var txt = new FormattedText(NextHexLine(i, en), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, tf, FontSize, Foreground); if (i == 0) { var tmp = txt.BuildHighlightGeometry(point, 14, 47); _leftBound = tmp.Bounds.Left; _rightBound = tmp.Bounds.Right; _boundWidth = _rightBound - _leftBound; } var b = Map.Highlight(i * 16, (i + 1) * 16); percentage += b.Count(x => x > 0); int? gon = null; var start = 0; var end = 0; for (var j = 0; j < 16; j++) { if (gon != null && (b[j] != gon || j == 15)) { var c = gon.Value; gon = null; end = b[j] == 0 ? j - 1 : 15; end = 16 + (end * 3); var g = txt.BuildHighlightGeometry(point, start, end - start); dc.DrawGeometry(c == 1 ? Brushes.Aquamarine : Brushes.DarkSalmon, null, g); } if (gon == null && b[j] > 0) { gon = b[j]; start = 14 + (j*3); } } dc.DrawText(txt, point); y += txt.Height; } percentage = percentage * 100 / m_byteCount; Percentage = percentage; watch.Stop(); Result = string.Format("Bytes: {0}, Rows: {1}, Load time: {3} ({2}%)", m_byteCount, _lineCount, percentage, watch.Elapsed); }