예제 #1
0
        public void ResultNode()
        {
            RtfTree tree = new RtfTree();

            tree.LoadRtfFile("..\\..\\testdocs\\testdoc3.rtf");

            RtfTreeNode node = tree.MainGroup.SelectSingleNode("object").ParentNode;

            ObjectNode objNode = new ObjectNode(node);

            RtfTreeNode resNode = objNode.ResultNode;

            Assert.That(resNode, Is.SameAs(tree.MainGroup.SelectSingleGroup("object").SelectSingleChildGroup("result")));

            RtfTreeNode pictNode = resNode.SelectSingleNode("pict").ParentNode;
            ImageNode   imgNode  = new ImageNode(pictNode);

            Assert.That(imgNode.Height, Is.EqualTo(2247));
            Assert.That(imgNode.Width, Is.EqualTo(9320));

            Assert.That(imgNode.DesiredHeight, Is.EqualTo(1274));
            Assert.That(imgNode.DesiredWidth, Is.EqualTo(5284));

            Assert.That(imgNode.ScaleX, Is.EqualTo(100));
            Assert.That(imgNode.ScaleY, Is.EqualTo(100));

            Assert.That(imgNode.ImageFormat, Is.EqualTo(ImageFormat.Emf));
        }
예제 #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            //Se establecen las propiedades del cuadro de diálogo "Abrir"
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter           = "Archivos RTF (*.rtf)|*.rtf|Todos los archivos (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            //Se muestra el cuadro de diálogo Abrir y se espera a que se seleccione un fichero RTF.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Se crea un árbol RTF
                RtfTree arbol = new RtfTree();

                //Se carga el documento seleccionado (Este método parsea el documento y crea la estructura de árbol interna)
                arbol.LoadRtfFile(openFileDialog1.FileName);

                //Busca el primer nodo de tipo objeto.
                RtfTreeNode node = arbol.RootNode.SelectSingleNode("object");

                //Se crea un nodo RTF especializado en imágenes
                ObjectNode objectNode = new ObjectNode(node.ParentNode);

                //Se escriben al cuadro de texto superior algunos datos del objeto
                txtArbol.Text += "Object type: " + objectNode.ObjectType + "\r\n";
                txtArbol.Text += "Object class: " + objectNode.ObjectClass + "\r\n";

                //Se extrae la imagen insertada como representación del objeto

                //Se obtiene el nodo "\result" del objeto (representación externa del objeto en el documento RTF)
                RtfTreeNode resultNode = objectNode.ResultNode;

                RtfTreeNode auxNode = null;

                //Si existe un nodo imagen en el grupo "\result" la extraemos a un fichero y mostramos algunas características en
                //el cuadro de texto superior de la ventana.
                if ((auxNode = resultNode.SelectSingleNode("pict")) != null)
                {
                    //Creamos el nodo especializado de tipo Imagen
                    ImageNode imageNode = new ImageNode(auxNode.ParentNode);

                    //Mostramos algunas características de la imagen
                    txtArbol.Text += "Image width: " + imageNode.Width / 20 + "\r\n";
                    txtArbol.Text += "Image heigh: " + imageNode.Height / 20 + "\r\n";
                    txtArbol.Text += "Image format: " + imageNode.ImageFormat + "\r\n";

                    //Se guarda la imagen a fichero
                    MessageBox.Show("Se va a crear el fichero: image-example3." + getExtension(imageNode.ImageFormat));
                    imageNode.SaveImage("image-example3." + getExtension(imageNode.ImageFormat));
                }
                else
                {
                    MessageBox.Show("El grupo '\result' del objeto no contiene imágenes!");
                }
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
            /// <summary>
            /// Devuelve la información contenida en el grupo "\info" del documento RTF.
            /// </summary>
            /// <returns>Objeto InfoGroup con la información del grupo "\info" del documento RTF.</returns>
            public InfoGroup GetInfoGroup()
            {
                InfoGroup info = null;

                RtfTreeNode infoNode = RootNode.SelectSingleNode("info");

                //Si existe el nodo "\info" exraemos toda la información.
                if (infoNode != null)
                {
                    RtfTreeNode auxnode = null;

                    info = new InfoGroup();

                    //Title
                    if ((auxnode = rootNode.SelectSingleNode("title")) != null)
                    {
                        info.Title = auxnode.NextSibling.NodeKey;
                    }

                    //Subject
                    if ((auxnode = rootNode.SelectSingleNode("subject")) != null)
                    {
                        info.Subject = auxnode.NextSibling.NodeKey;
                    }

                    //Author
                    if ((auxnode = rootNode.SelectSingleNode("author")) != null)
                    {
                        info.Author = auxnode.NextSibling.NodeKey;
                    }

                    //Manager
                    if ((auxnode = rootNode.SelectSingleNode("manager")) != null)
                    {
                        info.Manager = auxnode.NextSibling.NodeKey;
                    }

                    //Company
                    if ((auxnode = rootNode.SelectSingleNode("company")) != null)
                    {
                        info.Company = auxnode.NextSibling.NodeKey;
                    }

                    //Operator
                    if ((auxnode = rootNode.SelectSingleNode("operator")) != null)
                    {
                        info.Operator = auxnode.NextSibling.NodeKey;
                    }

                    //Category
                    if ((auxnode = rootNode.SelectSingleNode("category")) != null)
                    {
                        info.Category = auxnode.NextSibling.NodeKey;
                    }

                    //Keywords
                    if ((auxnode = rootNode.SelectSingleNode("keywords")) != null)
                    {
                        info.Keywords = auxnode.NextSibling.NodeKey;
                    }

                    //Comments
                    if ((auxnode = rootNode.SelectSingleNode("comment")) != null)
                    {
                        info.Comment = auxnode.NextSibling.NodeKey;
                    }

                    //Document comments
                    if ((auxnode = rootNode.SelectSingleNode("doccomm")) != null)
                    {
                        info.DocComment = auxnode.NextSibling.NodeKey;
                    }

                    //Hlinkbase (The base address that is used for the path of all relative hyperlinks inserted in the document)
                    if ((auxnode = rootNode.SelectSingleNode("hlinkbase")) != null)
                    {
                        info.HlinkBase = auxnode.NextSibling.NodeKey;
                    }

                    //Version
                    if ((auxnode = rootNode.SelectSingleNode("version")) != null)
                    {
                        info.Version = auxnode.Parameter;
                    }

                    //Internal Version
                    if ((auxnode = rootNode.SelectSingleNode("vern")) != null)
                    {
                        info.InternalVersion = auxnode.Parameter;
                    }

                    //Editing Time
                    if ((auxnode = rootNode.SelectSingleNode("edmins")) != null)
                    {
                        info.EditingTime = auxnode.Parameter;
                    }

                    //Number of Pages
                    if ((auxnode = rootNode.SelectSingleNode("nofpages")) != null)
                    {
                        info.NumberOfPages = auxnode.Parameter;
                    }

                    //Number of Chars
                    if ((auxnode = rootNode.SelectSingleNode("nofchars")) != null)
                    {
                        info.NumberOfChars = auxnode.Parameter;
                    }

                    //Number of Words
                    if ((auxnode = rootNode.SelectSingleNode("nofwords")) != null)
                    {
                        info.NumberOfWords = auxnode.Parameter;
                    }

                    //Id
                    if ((auxnode = rootNode.SelectSingleNode("id")) != null)
                    {
                        info.Id = auxnode.Parameter;
                    }

                    //Creation DateTime
                    if ((auxnode = rootNode.SelectSingleNode("creatim")) != null)
                    {
                        info.CreationTime = parseDateTime(auxnode.ParentNode);
                    }

                    //Revision DateTime
                    if ((auxnode = rootNode.SelectSingleNode("revtim")) != null)
                    {
                        info.RevisionTime = parseDateTime(auxnode.ParentNode);
                    }

                    //Last Print Time
                    if ((auxnode = rootNode.SelectSingleNode("printim")) != null)
                    {
                        info.LastPrintTime = parseDateTime(auxnode.ParentNode);
                    }

                    //Backup Time
                    if ((auxnode = rootNode.SelectSingleNode("buptim")) != null)
                    {
                        info.BackupTime = parseDateTime(auxnode.ParentNode);
                    }
                }

                return(info);
            }