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 _ConvertObject(RtfTree tree) { RtfNodeCollection nodes = tree.RootNode.SelectNodes("object"); //RtfNodeCollection nodes = tree.RootNode.ChildNodes; foreach (RtfTreeNode n in nodes) { ObjectNode objectNode = new ObjectNode(n.ParentNode); if (objectNode.ObjectType == "objemb" && objectNode.ObjectClass == "Equation.DSMT4") { RtfTreeNode resultNode = objectNode.ResultNode; RtfTreeNode auxNode = null; if ((auxNode = resultNode.SelectSingleNode("pict")) != null) { ImageNode imageNode = new ImageNode(auxNode.ParentNode); 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); }