private EquationObj Wmf2Equation(ImageNode imageNode) { EquationObj equationObj = new EquationObj(); ConvertEquation ce = new ConvertEquation(); EquationInput ei = new EquationInputFileWMF(imageNode.GetByteData()); string strEquation = ce.ConvertToText(ei); Regex regex = new Regex(@"<([^>]+)>(.*?)</\1>"); var v = regex.Match(strEquation); string latexString = v.Groups[2].ToString(); if (latexString.Length > 0) { equationObj.attr("latex", latexString); } string gifBase64Code = ""; Image gifbit = ce.ConvertToGif(ei); if (gifbit != null) { gifBase64Code = ImageToBase64(gifbit, ImageFormat.Gif); equationObj.content = gifBase64Code; equationObj.attr("width", gifbit.Width); equationObj.attr("height", gifbit.Height); } return(equationObj); }
private RtfTree _ConvertMMath(RtfTree tree) { RtfNodeCollection nodes = tree.RootNode.SelectNodes("mmath"); //RtfNodeCollection nodes = tree.RootNode.ChildNodes; foreach (RtfTreeNode n in nodes) { Console.WriteLine(n.ParentNode.Rtf); RtfTreeNode auxNode = null; if ((auxNode = n.ParentNode.SelectSingleNode("nonshppict")) != null) { ImageNode imageNode = new ImageNode(auxNode.ParentNode.SelectSingleNode("pict").ParentNode); ConvertEquation ce = new ConvertEquation(); EquationInput ei = new EquationInputFileEPS(imageNode.GetByteData()); EquationOutput eo = new EquationOutputFileGIF(GetOutputFile("gif")); ce.Convert(ei, eo); //string strEquation = ce.ConvertToText(ei); //EquationObj equationObj = Wmf2Equation(imageNode); //tree.RootNode.FirstChild.ReplaceChildDeep(n.ParentNode, getReplaceNode()); //rtf_replace.Add(equationObj); } else { MessageBox.Show("'\result' node contains no images!"); } tree.RootNode.FirstChild.RemoveChildDeep(n.ParentNode); } return(tree); }