public static string GetRtfText(string rawtext, Graphics gr, Color backcolor, int fontsize) { MathML.Rendering.WinGraphicsRenderer _mmlRendering = new MathML.Rendering.WinGraphicsRenderer(); _mmlRendering.BackColor = backcolor; _mmlRendering.FontSize = fontsize; StringBuilder stb = new StringBuilder(); ComposeText(stb, rawtext, _mmlRendering, gr); stb.Append(texttrailer); return stb.ToString(); }
public static string GetRtfText(string rawtext, Graphics gr, Color backcolor, int fontsize) { MathML.Rendering.WinGraphicsRenderer _mmlRendering = new MathML.Rendering.WinGraphicsRenderer(); _mmlRendering.BackColor = backcolor; _mmlRendering.FontSize = fontsize; StringBuilder stb = new StringBuilder(); ComposeText(stb, rawtext, _mmlRendering, gr); stb.Append(texttrailer); return(stb.ToString()); }
static void ComposeText(StringBuilder stb, string rawtext, MathML.Rendering.WinGraphicsRenderer _mmlRendering, Graphics gr) { if (stb.Length == 0) { stb.Append(textheader); } int currpos = 0; for (; ;) { int startidx = rawtext.IndexOf("<math>", currpos); if (startidx < 0) { break; } int endidx = rawtext.IndexOf("</math>", startidx); if (endidx < 0) { break; } endidx += "</math>".Length; // all text from currpos to startidx-1 can be copyied to the stringbuilder stb.Append(rawtext, currpos, startidx - currpos); // all text from startidx to endidx-1 must be loaded into the control and rendered System.IO.StringReader rd = new StringReader(rawtext.Substring(startidx, endidx - startidx)); MathML.MathMLDocument doc = new MathML.MathMLDocument(); doc.Load(rd); rd.Close(); _mmlRendering.SetMathElement((MathML.MathMLMathElement)doc.DocumentElement); System.Drawing.Image mf = _mmlRendering.GetImage(typeof(Bitmap), gr); GraphicsUnit unit = GraphicsUnit.Point; RectangleF rect = mf.GetBounds(ref unit); string imagetext = GetRtfImage(mf); stb.Append(imageheader); stb.Append(@"\picwgoal" + Math.Ceiling(15 * rect.Width).ToString()); stb.Append(@"\pichgoal" + Math.Ceiling(15 * rect.Height).ToString()); stb.Append(" "); stb.Append(imagetext); stb.Append(imagetrailer); currpos = endidx; } stb.Append(rawtext, currpos, rawtext.Length - currpos); }