protected void DrawTextForNode(Graphics oGraphics, Node oNode, FontForRectangle oFontForRectangle, int iTextHeight, Brush oTextBrush, Brush oBackgroundBrush, StringFormat oNonLeafStringFormat, StringFormat oLeafStringFormat) { Debug.Assert(oGraphics != null); Debug.Assert(oNode != null); Debug.Assert(oFontForRectangle != null); Debug.Assert(iTextHeight >= 0); Debug.Assert(oTextBrush != null); Debug.Assert(oNonLeafStringFormat != null); Debug.Assert(oLeafStringFormat != null); AssertValid(); bool flag = oNode.Nodes.Count == 0; Rectangle rectangleToDraw = oNode.RectangleToDraw; int penWidthPx = oNode.PenWidthPx; rectangleToDraw.Inflate(-penWidthPx, -penWidthPx); Rectangle rectangle = (!flag) ? Rectangle.FromLTRB(rectangleToDraw.Left, rectangleToDraw.Top, rectangleToDraw.Right, rectangleToDraw.Top + iTextHeight) : rectangleToDraw; int width = rectangle.Width; int height = rectangle.Height; if (width > 0 && height > 0 && height <= rectangleToDraw.Height) { if (oBackgroundBrush != null) { oGraphics.FillRectangle(oBackgroundBrush, rectangle); } oGraphics.DrawString(oNode.Text, oFontForRectangle.Font, oTextBrush, rectangle, flag ? oLeafStringFormat : oNonLeafStringFormat); } }
public override void DrawTextForSelectedNode(Graphics oGraphics, Node oSelectedNode) { Debug.Assert(oGraphics != null); Debug.Assert(oSelectedNode != null); AssertValid(); FontForRectangle fontForRectangle = null; SolidBrush solidBrush = null; SolidBrush solidBrush2 = null; TextRenderingHint textRenderingHint = TextRenderingHint.SystemDefault; try { fontForRectangle = new FontForRectangle(m_sFontFamily, m_fFontSizePt, oGraphics); textRenderingHint = SetTextRenderingHint(oGraphics, fontForRectangle.Font); solidBrush = new SolidBrush(m_oSelectedFontColor); solidBrush2 = new SolidBrush(m_oSelectedBackColor); StringFormat oNonLeafStringFormat = CreateStringFormat(bLeafNode: false); StringFormat oLeafStringFormat = CreateStringFormat(bLeafNode: true); int textHeight = GetTextHeight(oGraphics, fontForRectangle.Font, m_iMinimumTextHeight); DrawTextForNode(oGraphics, oSelectedNode, fontForRectangle, textHeight, solidBrush, solidBrush2, oNonLeafStringFormat, oLeafStringFormat); } finally { solidBrush?.Dispose(); solidBrush2?.Dispose(); fontForRectangle?.Dispose(); oGraphics.TextRenderingHint = textRenderingHint; } }
public override void DrawTextForAllNodes(Graphics oGraphics, Rectangle oTreemapRectangle, Nodes oNodes) { Debug.Assert(oGraphics != null); Debug.Assert(oNodes != null); this.AssertValid(); FontForRectangle fontForRectangle = null; SolidBrush solidBrush = null; TextRenderingHint textRenderingHint = TextRenderingHint.SystemDefault; try { fontForRectangle = new FontForRectangle(this.m_sFontFamily, this.m_fFontSizePt, oGraphics); textRenderingHint = base.SetTextRenderingHint(oGraphics, fontForRectangle.Font); solidBrush = new SolidBrush(this.m_oTextColor); StringFormat oNonLeafStringFormat = this.CreateStringFormat(false); StringFormat oLeafStringFormat = this.CreateStringFormat(true); int textHeight = TopTextDrawer.GetTextHeight(oGraphics, fontForRectangle.Font, this.m_iMinimumTextHeight); this.DrawTextForNodes(oNodes, oGraphics, fontForRectangle, textHeight, solidBrush, null, oNonLeafStringFormat, oLeafStringFormat, 0); } finally { if (solidBrush != null) { solidBrush.Dispose(); } if (fontForRectangle != null) { fontForRectangle.Dispose(); } oGraphics.TextRenderingHint = textRenderingHint; } }
protected void Dispose(bool bDisposing) { if (!this.m_bDisposed && bDisposing) { if (this.m_oFontForRectangles != null) { IEnumerator enumerator = this.m_oFontForRectangles.GetEnumerator(); try { while (enumerator.MoveNext()) { FontForRectangle fontForRectangle = (FontForRectangle)enumerator.Current; fontForRectangle.Dispose(); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } this.m_oFontForRectangles = null; } this.m_bDisposed = true; }
public bool NodeToFont(Node oNode, int iNodeLevel, Graphics oGraphics, out Font oFont, out string sTextToDraw) { Debug.Assert(oNode != null); Debug.Assert(iNodeLevel >= 0); Debug.Assert(oGraphics != null); this.AssertValid(); bool result; if (iNodeLevel < this.m_oFontForRectangles.Count) { FontForRectangle fontForRectangle = (FontForRectangle)this.m_oFontForRectangles[iNodeLevel]; string text = oNode.Text; if (fontForRectangle.CanFitInRectangle(text, oNode.Rectangle, oGraphics)) { oFont = fontForRectangle.Font; sTextToDraw = text; result = true; return(result); } } oFont = null; sTextToDraw = null; result = false; return(result); }
/// <summary> /// Initializes a new instance of the MaximizingFontMapper class. /// </summary> /// /// <param name="sFamily"> /// Font family. /// </param> /// /// <param name="fMinSizePt"> /// Minimum font size, in points. /// </param> /// /// <param name="fMaxSizePt"> /// Maximum font size, in points. /// </param> /// /// <param name="fIncrementPt"> /// Increment between fonts. /// </param> /// /// <param name="oGraphics"> /// Object the caller will use to draw the node's text. /// </param> protected internal MaximizingFontMapper(string sFamily, float fMinSizePt, float fMaxSizePt, float fIncrementPt, Graphics oGraphics) { StringUtil.AssertNotEmpty(sFamily); Debug.Assert(oGraphics != null); ValidateSizeRange(fMinSizePt, fMaxSizePt, fIncrementPt, "MaximizingFontMapper.Initialize()"); m_oFontForRectangles = new ArrayList(); for (float num = fMinSizePt; num <= fMaxSizePt; num += fIncrementPt) { FontForRectangle value = new FontForRectangle(sFamily, num, oGraphics); m_oFontForRectangles.Insert(0, value); } m_bDisposed = false; AssertValid(); }
public static int GetTextHeight(Graphics oGraphics, string sFontFamily, float fFontSizePt, int iMinimumTextHeight) { Debug.Assert(oGraphics != null); StringUtil.AssertNotEmpty(sFontFamily); Debug.Assert(fFontSizePt > 0f); Debug.Assert(iMinimumTextHeight >= 0); FontForRectangle fontForRectangle = null; try { fontForRectangle = new FontForRectangle(sFontFamily, fFontSizePt, oGraphics); return(GetTextHeight(oGraphics, fontForRectangle.Font, iMinimumTextHeight)); } finally { fontForRectangle?.Dispose(); } }
/// <summary> /// Initializes a new instance of the PerLevelFontMapper class. /// </summary> /// /// <param name="sFamily"> /// Font family. /// </param> /// /// <param name="oTreemapRectangle"> /// Treemap's outer rectangle. /// </param> /// /// <param name="fTreemapRectangleDivisor"> /// The font size for level 0 is the treemap rectangle height divided by /// fTreemapRectangleDivisor. /// </param> /// /// <param name="fPerLevelDivisor"> /// The font size for level N is the font size for level N-1 divided by /// fPerLevelDivisor. /// </param> /// /// <param name="fMinimumFontSize"> /// Minimum font size. /// </param> /// /// <param name="oGraphics"> /// Object the caller will use to draw the node's text. /// </param> protected internal PerLevelFontMapper(string sFamily, Rectangle oTreemapRectangle, float fTreemapRectangleDivisor, float fPerLevelDivisor, float fMinimumFontSize, Graphics oGraphics) { StringUtil.AssertNotEmpty(sFamily); Debug.Assert(fTreemapRectangleDivisor > 0f); Debug.Assert(fPerLevelDivisor > 0f); Debug.Assert(fMinimumFontSize > 0f); Debug.Assert(oGraphics != null); float num = (float)oTreemapRectangle.Height / fTreemapRectangleDivisor; m_oFontForRectangles = new ArrayList(); while (num > fMinimumFontSize) { FontForRectangle value = new FontForRectangle(sFamily, num, oGraphics); m_oFontForRectangles.Add(value); num /= fPerLevelDivisor; } m_bDisposed = false; AssertValid(); }
protected void DrawTextForNodes(Nodes oNodes, Graphics oGraphics, FontForRectangle oFontForRectangle, int iTextHeight, Brush oTextBrush, Brush oBackgroundBrush, StringFormat oNonLeafStringFormat, StringFormat oLeafStringFormat, int iNodeLevel) { Debug.Assert(oNodes != null); Debug.Assert(oGraphics != null); Debug.Assert(oFontForRectangle != null); Debug.Assert(iTextHeight >= 0); Debug.Assert(oTextBrush != null); Debug.Assert(oNonLeafStringFormat != null); Debug.Assert(oLeafStringFormat != null); Debug.Assert(iNodeLevel >= 0); foreach (Node oNode in oNodes) { if (!oNode.Rectangle.IsEmpty) { if (TextShouldBeDrawnForNode(oNode, iNodeLevel)) { DrawTextForNode(oGraphics, oNode, oFontForRectangle, iTextHeight, oTextBrush, oBackgroundBrush, oNonLeafStringFormat, oLeafStringFormat); } DrawTextForNodes(oNode.Nodes, oGraphics, oFontForRectangle, iTextHeight, oTextBrush, oBackgroundBrush, oNonLeafStringFormat, oLeafStringFormat, iNodeLevel + 1); } } }
public bool NodeToFont(Node oNode, int iNodeLevel, Graphics oGraphics, out Font oFont, out string sTextToDraw) { Debug.Assert(oNode != null); Debug.Assert(iNodeLevel >= 0); Debug.Assert(oGraphics != null); this.AssertValid(); string text = oNode.Text; RectangleF rectangle = oNode.Rectangle; IEnumerator enumerator = this.m_oFontForRectangles.GetEnumerator(); bool result; try { while (enumerator.MoveNext()) { FontForRectangle fontForRectangle = (FontForRectangle)enumerator.Current; if (fontForRectangle.CanFitInRectangle(text, rectangle, oGraphics)) { oFont = fontForRectangle.Font; sTextToDraw = text; result = true; return(result); } } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } oFont = null; sTextToDraw = null; result = false; return(result); }