public static void DrawBullet(Graphics g, Color color, Bullet.style bulletStyle, SizeF stringfSize, PointF textPosition) { RectangleF rectF = new RectangleF(textPosition, stringfSize); PointF[] bullet = new PointF[7]; bullet[0] = new PointF(rectF.X, rectF.Y); bullet[1] = new PointF(rectF.X + rectF.Width, rectF.Y); bullet[2] = new PointF(rectF.X + rectF.Width + (rectF.Height / 2), rectF.Y + (rectF.Height / 2)); bullet[3] = new PointF(rectF.X + rectF.Width, rectF.Y + rectF.Height); bullet[4] = new PointF(rectF.X, rectF.Y + rectF.Height); bullet[5] = new PointF(rectF.X - (rectF.Height / 2), rectF.Y + (rectF.Height / 2)); bullet[6] = new PointF(rectF.X, rectF.Y); if ((bulletStyle == Bullet.style.Left) || (bulletStyle == Bullet.style.None)) { bullet[2] = bullet[1]; } if ((bulletStyle == Bullet.style.Right) || (bulletStyle == Bullet.style.None)) { bullet[5] = bullet[4]; } //g.FillPolygon(new SolidBrush(Color.White), bullet); g.DrawLines(new Pen(color), bullet); }
/// <summary> /// Get color from tag (<color=red> return Color.Red) /// </summary> static public bool GetBulletStyle(string sText, out Bullet.style bulletStyle) { bulletStyle = Bullet.style.None; string sToDraw = sText; if (sToDraw.Contains("<bullet=") && sToDraw.Contains("</bullet>")) { Regex regex = new Regex("<bullet=(.*?)>"); var v = regex.Match(sText); string sValue = v.Groups[1].ToString(); if (sValue == Bullet.style.None.ToString()) { bulletStyle = Bullet.style.None; } if (sValue == Bullet.style.Left.ToString()) { bulletStyle = Bullet.style.Left; } if (sValue == Bullet.style.Right.ToString()) { bulletStyle = Bullet.style.Right; } if (sValue == Bullet.style.Both.ToString()) { bulletStyle = Bullet.style.Both; } return(true); } return(false); }
private void PanelPreview_Paint(object sender, PaintEventArgs e) { string sResult = ""; if (IsComplexExpression(Expression)) { Expression = TB_Advanced.Text; sResult = Compute(Expression); sResult = Python.Script.Evaluate(sResult); } else { Expression = TB_Simple.Text; sResult = Compute(Expression); } if (string.IsNullOrEmpty(sResult)) { return; } var g = e.Graphics; var p = sender as Panel; var format = new StringFormat { Alignment = StringAlignment.Near }; Font textFont = new System.Drawing.Font("Arial", 10); RectangleF currentView = new RectangleF(PanelPreview.DisplayRectangle.X + 10, PanelPreview.DisplayRectangle.Y + 10, PanelPreview.DisplayRectangle.Width, PanelPreview.DisplayRectangle.Height); RectangleF labelBounds = TextExpression.GetComputedLabelBounds(g, sResult, textFont, format, currentView, 1.0F); RectangleF fTitleClip = new RectangleF(); string[] sSplitted = sResult.Split('\n'); PointF pos = new PointF(labelBounds.X, labelBounds.Y); foreach (string sSplit in sSplitted) { using (var gp2 = new GraphicsPath()) { FontStyle fontStyle = TextExpression.GetFontFromTag(sSplit); FontFamily fontFamily = textFont.FontFamily; FontFamily customFontFamily = null; if (TextExpression.GetFontFamilyFromTag(sSplit, out customFontFamily)) { fontFamily = customFontFamily; } Font newFont = new Font(fontFamily, TextExpression.GetSizeFromTag(sSplit, textFont.SizeInPoints)); Color textColor = Color.Black; Color tempColor = Color.Black; if (TextExpression.GetColorFromTag(sSplit, out tempColor)) { textColor = tempColor; } Bullet.style bulletStyle = Bullet.style.None; bool bDrawBullet = TextExpression.GetBulletStyle(sSplit, out bulletStyle); string sTextWithoutTag = TextExpression.GetTextWithoutTag(sSplit); SizeF stringfSize = g.MeasureString(sTextWithoutTag, newFont); if (!TextExpression.IsMorse(sSplit)) { PointF textPosition = new PointF(pos.X, pos.Y); if (TextExpression.IsTitle(sSplit)) { textPosition = new PointF((labelBounds.X + labelBounds.Width / 2) - (stringfSize.Width / 2), labelBounds.Y); fTitleClip = new RectangleF(textPosition, stringfSize); //gp2.AddString(sTextWithoutTag, newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, textPosition, format); e.Graphics.DrawString(sTextWithoutTag, newFont, new SolidBrush(textColor), textPosition, format); labelBounds = new RectangleF(labelBounds.X, labelBounds.Y + (stringfSize.Height / 2), labelBounds.Width, labelBounds.Height - (stringfSize.Height / 2)); } else { //gp2.AddString(sTextWithoutTag, newFont.FontFamily, (int)fontStyle, newFont.Size * g.DpiY / 72F, textPosition, format); if (bulletStyle == Bullet.style.Left || bulletStyle == Bullet.style.Both) { textPosition.X += (stringfSize.Height / 2); } e.Graphics.DrawString(sTextWithoutTag, newFont, new SolidBrush(textColor), textPosition, format); } // Draw a limit above the text if needed TextExpression.DrawUpperScore(g, sSplit, textPosition, textColor, newFont, 1.0F); TextExpression.DrawUnderScore(g, sSplit, textPosition, textColor, newFont, 1.0F); if (bDrawBullet) { TextExpression.DrawBullet(g, textColor, bulletStyle, stringfSize, textPosition); } pos.Y += stringfSize.Height; } else { TextExpression.DrawMorseText(g, gp2, ref pos, sSplit, newFont, fontStyle, StringAlignment.Near, labelBounds); } // Draw a label //g.FillPath(new SolidBrush(textColor), gp2); gp2.Dispose(); } } e.Graphics.DrawRectangle(new Pen(Color.Black), (int)labelBounds.X, (int)labelBounds.Y, (int)labelBounds.Width, (int)labelBounds.Height); }