Пример #1
0
 /// <summary>
 /// Actualiza la tabla de fuentes con una nueva fuente si es necesario.
 /// </summary>
 /// <param name="format"></param>
 private void UpdateFontTable(RtfTextFormat format)
 {
     if (fontTable.IndexOf(format.font) == -1)
     {
         fontTable.AddFont(format.font);
     }
 }
Пример #2
0
 /// <summary>
 /// Actualiza la tabla de colores con un nuevo color si es necesario.
 /// </summary>
 /// <param name="format"></param>
 private void UpdateColorTable(RtfTextFormat format)
 {
     if (colorTable.IndexOf(format.color) == -1)
     {
         colorTable.AddColor(format.color);
     }
 }
        } // PushCurrentTextFormat

        public void PopCurrentTextFormat()
        {
            if (_textFormatStack.Count == 0)
            {
                throw new RtfStructureException(Strings.InvalidTextContextState);
            }
            _currentTextFormat = (RtfTextFormat)_textFormatStack.Pop();
        } // PopCurrentTextFormat
Пример #4
0
            /// <summary>
            /// Inserta un fragmento de texto en el documento con un formato de texto determinado.
            /// </summary>
            /// <param name="text">Texto a insertar.</param>
            /// <param name="format">Formato del texto a insertar.</param>
            public void AddText(string text, RtfTextFormat format)
            {
                UpdateFontTable(format);
                UpdateColorTable(format);

                InsertFormat(format);

                InsertText(text);
            }
Пример #5
0
            public void Clear()
            {
                currentFormat = null;

                tree      = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }
        } // PopCurrentTextFormat

        public void Reset()
        {
            State         = RtfInterpreterState.Init;
            RtfVersion    = RtfSpec.RtfVersion1;
            DefaultFontId = "f0";
            WritableFontTable.Clear();
            WritableColorTable.Clear();
            Generator = null;
            _uniqueTextFormats.Clear();
            _textFormatStack.Clear();
            _currentTextFormat = null;
            WritableDocumentInfo.Reset();
            WritableUserProperties.Clear();
        } // Reset
Пример #7
0
            /// <summary>
            /// Constructor de la clase RtfDocument.
            /// </summary>
            /// <param name="path">Ruta del fichero a generar.</param>
            /// <param name="enc">Codificación del documento a generar.</param>
            public RtfDocument(string path, Encoding enc)
            {
                this.path     = path;
                this.encoding = enc;

                fontTable = new RtfFontTable();
                fontTable.AddFont("Arial");  //Default font

                colorTable = new RtfColorTable();
                colorTable.AddColor(Color.Black);  //Default color

                currentFormat = null;

                tree      = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }
Пример #8
0
        public void convert(string wordDocumentPath)
        {
            XmlDocument xmlOrigin = new XmlDocument();
            xmlOrigin.Load(path);

            XmlNodeList tasks = xmlOrigin.GetElementsByTagName("task");
            RtfTextFormat format = new RtfTextFormat();
            format.size = 20;
            format.bold = true;
            format.underline = true;

            foreach (XmlElement elem in tasks)
            {
                doc.AddText(elem.GetAttribute("id"), format);
                doc.AddText(elem.GetAttribute("name"), format);
                doc.AddNewLine();
            }

            doc.Close();
        }
Пример #9
0
            /// <summary>
            /// Inserta las claves RTF necesarias para representar el formato de texto pasado como parámetro.
            /// </summary>
            /// <param name="format">Formato de texto a representar.</param>
            private void InsertFormat(RtfTextFormat format)
            {
                if (currentFormat != null)
                {
                    //Font Color
                    if (format.color.ToArgb() != currentFormat.color.ToArgb())
                    {
                        currentFormat.color = format.color;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, colorTable.IndexOf(format.color)));
                    }

                    //Font Name
                    if (format.size != currentFormat.size)
                    {
                        currentFormat.size = format.size;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fs", true, format.size * 2));
                    }

                    //Font Size
                    if (format.font != currentFormat.font)
                    {
                        currentFormat.font = format.font;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, fontTable.IndexOf(format.font)));
                    }

                    //Bold
                    if (format.bold != currentFormat.bold)
                    {
                        currentFormat.bold = format.bold;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "b", format.bold ? false : true, 0));
                    }

                    //Italic
                    if (format.italic != currentFormat.italic)
                    {
                        currentFormat.italic = format.italic;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "i", format.italic ? false : true, 0));
                    }

                    //Underline
                    if (format.underline != currentFormat.underline)
                    {
                        currentFormat.underline = format.underline;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "ul", format.underline ? false : true, 0));
                    }
                }
                else //currentFormat == null
                {
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, colorTable.IndexOf(format.color)));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fs", true, format.size * 2));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, fontTable.IndexOf(format.font)));

                    if (format.bold)
                    {
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "b", false, 0));
                    }

                    if (format.italic)
                    {
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "i", false, 0));
                    }

                    if (format.underline)
                    {
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "ul", false, 0));
                    }

                    currentFormat           = new RtfTextFormat();
                    currentFormat.color     = format.color;
                    currentFormat.size      = format.size;
                    currentFormat.font      = format.font;
                    currentFormat.bold      = format.bold;
                    currentFormat.italic    = format.italic;
                    currentFormat.underline = format.underline;
                }
            }
Пример #10
0
            /// <summary>
            /// Inserta las claves RTF necesarias para representar el formato de texto pasado como parámetro.
            /// </summary>
            /// <param name="format">Formato de texto a representar.</param>
            private void InsertFormat(RtfTextFormat format)
            {
                if (currentFormat != null)
                {
                    //Font Color
                    if (format.color.ToArgb() != currentFormat.color.ToArgb())
                    {
                        currentFormat.color = format.color;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, colorTable.IndexOf(format.color)));
                    }

                    //Font Name
                    if (format.size != currentFormat.size)
                    {
                        currentFormat.size = format.size;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fs", true, format.size * 2));
                    }

                    //Font Size
                    if (format.font != currentFormat.font)
                    {
                        currentFormat.font = format.font;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, fontTable.IndexOf(format.font)));
                    }

                    //Bold
                    if (format.bold != currentFormat.bold)
                    {
                        currentFormat.bold = format.bold;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "b", format.bold ? false : true, 0));
                    }

                    //Italic
                    if (format.italic != currentFormat.italic)
                    {
                        currentFormat.italic = format.italic;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "i", format.italic ? false : true, 0));
                    }

                    //Underline
                    if (format.underline != currentFormat.underline)
                    {
                        currentFormat.underline = format.underline;

                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "ul", format.underline ? false : true, 0));
                    }
                }
                else //currentFormat == null
                {
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, colorTable.IndexOf(format.color)));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fs", true, format.size * 2));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, fontTable.IndexOf(format.font)));

                    if(format.bold)
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "b", false, 0));

                    if (format.italic)
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "i", false, 0));

                    if (format.underline)
                        mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "ul", false, 0));

                    currentFormat = new RtfTextFormat();
                    currentFormat.color = format.color;
                    currentFormat.size = format.size;
                    currentFormat.font = format.font;
                    currentFormat.bold = format.bold;
                    currentFormat.italic = format.italic;
                    currentFormat.underline = format.underline;
                }
            }
Пример #11
0
 /// <summary>
 /// Actualiza la tabla de colores con un nuevo color si es necesario.
 /// </summary>
 /// <param name="format"></param>
 private void UpdateColorTable(RtfTextFormat format)
 {
     if (colorTable.IndexOf(format.color) == -1)
     {
         colorTable.AddColor(format.color);
     }
 }
Пример #12
0
 /// <summary>
 /// Actualiza la tabla de fuentes con una nueva fuente si es necesario.
 /// </summary>
 /// <param name="format"></param>
 private void UpdateFontTable(RtfTextFormat format)
 {
     if (fontTable.IndexOf(format.font) == -1)
     {
         fontTable.AddFont(format.font);
     }
 }
Пример #13
0
            /// <summary>
            /// Inserta un fragmento de texto en el documento con un formato de texto determinado.
            /// </summary>
            /// <param name="text">Texto a insertar.</param>
            /// <param name="format">Formato del texto a insertar.</param>
            public void AddText(string text, RtfTextFormat format)
            {
                UpdateFontTable(format);
                UpdateColorTable(format);

                InsertFormat(format);

                InsertText(text);
            }
Пример #14
0
            public void Clear()
            {
                currentFormat = null;

                tree = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }
Пример #15
0
            /// <summary>
            /// Constructor de la clase RtfDocument.
            /// </summary>
            /// <param name="path">Ruta del fichero a generar.</param>
            /// <param name="enc">Codificación del documento a generar.</param>
            public RtfDocument(string path, Encoding enc)
            {
                this.path = path;
                this.encoding = enc;

                fontTable = new RtfFontTable();
                fontTable.AddFont("Arial");  //Default font

                colorTable = new RtfColorTable();
                colorTable.AddColor(Color.Black);  //Default color

                currentFormat = null;

                tree = new RtfTree();
                mainGroup = new RtfTreeNode(RtfNodeType.Group);

                InitializeTree();
            }