예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        private RtfTree _ConvertPict(RtfTree tree)
        {
            RtfNodeCollection shppict_nodes = tree.RootNode.SelectNodes("shppict");

            foreach (RtfTreeNode n in shppict_nodes)
            {
                tree.RootNode.FirstChild.RemoveChildDeep(n.ParentNode);
            }

            RtfNodeCollection pict_nodes = tree.RootNode.SelectNodes("pict");

            foreach (RtfTreeNode n in pict_nodes)
            {
                ImageNode imageNode = new ImageNode(n.ParentNode);

                pictObj pictObj = new pictObj();

                ImageConverter ic     = new ImageConverter();
                Image          img    = (Image)ic.ConvertFrom(imageNode.GetByteData());
                ImageFormat    format = getImageFormat(img);
                //string imgBase64Code = Convert.ToBase64String(imageNode.GetByteData());
                string imgBase64Code = ImageToBase64(img, format);

                pictObj.format  = format;
                pictObj.content = imgBase64Code;
                pictObj.attr("width", imageNode.Width);
                pictObj.attr("height", imageNode.Height);

                tree.RootNode.FirstChild.ReplaceChildDeep(n.ParentNode.ParentNode, getReplaceNode());

                rtf_replace.Add(pictObj);

                tree.RootNode.FirstChild.RemoveChildDeep(n.ParentNode.ParentNode);
            }
            return(tree);
        }