protected override Size MeasureOverride(Size availableSize) { if (m_layout != null) { Typeface typeface = TextElementUtility.GetTypeface(this); m_emSize = Math.Max(TextElement.GetFontSize(this), 10.0 * 4 / 3); FormattedText text = CreateFormattedText("8888", typeface); m_layout = m_layout.WithLineHeight(text.Height); } return(availableSize); }
private void Render(DrawingContext drawingContext) { drawingContext.DrawRectangle(Brushes.White, null, new Rect(new Point(), RenderSize)); if (m_blame == null || m_emSize == 0) { return; } Typeface typeface = TextElementUtility.GetTypeface(this); BlameLayout layout = m_layout.WithRenderSize(RenderSize); foreach (Rect newLineRectangle in layout.NewLines) { drawingContext.DrawRectangle(m_newLineBrush, null, newLineRectangle); } foreach (DisplayBlock block in layout.Blocks) { Rect blockRectangle = block.CommitPosition; drawingContext.DrawRectangle(m_personBrush[block.AuthorIndex], null, block.AuthorPosition); drawingContext.DrawRectangle(GetOrCreateCommitBrush(block), null, blockRectangle); drawingContext.DrawLine(new Pen(Brushes.LightGray, 1), new Point(0, blockRectangle.Bottom + 0.5), new Point(RenderSize.Width, blockRectangle.Bottom + 0.5)); FormattedText authorText = CreateSmallFormattedText(block.AuthorName, typeface, block.AuthorWidth); drawingContext.DrawText(authorText, new Point(block.AuthorX, block.TextY)); FormattedText dateText = CreateSmallFormattedText(block.Date, typeface, block.DateWidth); dateText.TextAlignment = TextAlignment.Right; drawingContext.DrawText(dateText, new Point(block.DateX, block.TextY)); if (block.ShowsSummary) { Rect summaryPosition = block.SummaryPosition; FormattedText commitText = CreateSmallFormattedText(block.Summary, typeface, summaryPosition.Width); commitText.MaxLineCount = commitText.Height == 0 ? 1 : Math.Max(1, (int)(summaryPosition.Height / commitText.Height)); commitText.Trimming = TextTrimming.WordEllipsis; drawingContext.DrawText(commitText, summaryPosition.TopLeft); } } Column lineNumberColumn = layout.LineNumberColumn; double yOffset = 0; double lineNumberWidth = lineNumberColumn.Width; foreach (DisplayLine line in layout.Lines) { FormattedText lineNumberText = CreateFormattedText(line.LineNumber.ToString(CultureInfo.InvariantCulture), typeface); lineNumberText.TextAlignment = TextAlignment.Right; lineNumberText.SetForegroundBrush(m_lineNumberBrush); lineNumberWidth = Math.Max(lineNumberWidth, lineNumberText.Width); lineNumberText.MaxTextWidth = lineNumberWidth; drawingContext.DrawText(lineNumberText, new Point(lineNumberColumn.Left, yOffset)); yOffset += layout.LineHeight; } layout = layout.WithLineNumberWidth(lineNumberWidth); Column codeColumn = layout.CodeColumn; Geometry clipGeometry = new RectangleGeometry(new Rect(codeColumn.Left, 0, RenderSize.Width - codeColumn.Left, RenderSize.Height)); drawingContext.PushClip(clipGeometry); yOffset = 0; foreach (DisplayLine line in layout.Lines) { double xOffset = layout.CodeColumn.Left - HorizontalOffset; foreach (LinePart part in line.Parts) { FormattedText text = CreateFormattedText(string.Join("", part.Text.Replace("\t", " ")), typeface); if (!line.IsNew && part.Status == LinePartStatus.New) { drawingContext.DrawRectangle(m_changedTextBrush, null, new Rect(xOffset, yOffset, text.WidthIncludingTrailingWhitespace, layout.LineHeight)); } drawingContext.DrawText(text, new Point(xOffset, yOffset)); xOffset += text.WidthIncludingTrailingWhitespace; } layout = layout.WithCodeWidth(xOffset - codeColumn.Left + HorizontalOffset); yOffset += layout.LineHeight; } drawingContext.Pop(); double commitRightX = layout.CommitColumn.Right; drawingContext.DrawLine(new Pen(Brushes.DarkGray, 1), new Point(commitRightX, 0), new Point(commitRightX, Math.Min(yOffset, RenderSize.Height))); double lineNumberRightX = layout.CodeMarginColumn.Right; drawingContext.DrawLine(new Pen(Brushes.DarkGray, 1), new Point(lineNumberRightX, 0), new Point(lineNumberRightX, Math.Min(yOffset, RenderSize.Height))); SetHorizontalScrollInfo(layout.Width, RenderSize.Width, null); if (layout != m_layout) { m_layout = layout; RedrawSoon(); } }