Esempio n. 1
0
            /// <summary>
            /// Actualiza los valores de las propiedades de formato de texto y párrafo.
            /// </summary>
            /// <param name="format">Formato de texto a insertar.</param>
            public void UpdateCharFormat(RtfCharFormat format)
            {
                if (currentFormat != null)
                {
                    SetFormatColor(format.Color);
                    SetFormatSize(format.Size);
                    SetFormatFont(format.Font);

                    SetFormatBold(format.Bold);
                    SetFormatItalic(format.Italic);
                    SetFormatUnderline(format.Underline);
                }
                else //currentFormat == null
                {
                    int indColor = colorTable.IndexOf(format.Color);

                    if (indColor == -1)
                    {
                        colorTable.AddColor(format.Color);
                        indColor = colorTable.IndexOf(format.Color);
                    }

                    int indFont = fontTable.IndexOf(format.Font);

                    if (indFont == -1)
                    {
                        fontTable.AddFont(format.Font);
                        indFont = fontTable.IndexOf(format.Font);
                    }

                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "cf", true, indColor));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fs", true, format.Size * 2));
                    mainGroup.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, indFont));

                    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 RtfCharFormat();
                    currentFormat.Color     = format.Color;
                    currentFormat.Size      = format.Size;
                    currentFormat.Font      = format.Font;
                    currentFormat.Bold      = format.Bold;
                    currentFormat.Italic    = format.Italic;
                    currentFormat.Underline = format.Underline;
                }
            }
Esempio n. 2
0
        public void FontTableTest()
        {
            RtfFontTable fontTable = tree.GetFontTable();

            Assert.That(fontTable.Count, Is.EqualTo(3));
            Assert.That(fontTable[0], Is.EqualTo("Times New Roman"));
            Assert.That(fontTable[1], Is.EqualTo("Arial"));
            Assert.That(fontTable[2], Is.EqualTo("Arial"));

            Assert.That(fontTable.IndexOf("Times New Roman"), Is.EqualTo(0));
            Assert.That(fontTable.IndexOf("Arial"), Is.EqualTo(1));
            Assert.That(fontTable.IndexOf("nofont"), Is.EqualTo(-1));
        }
Esempio n. 3
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);
     }
 }
Esempio n. 4
0
            /// <summary>
            /// Obtiene el código de la fuente pasada como parámetro, insertándola en la tabla de fuentes si es necesario.
            /// </summary>
            /// <param name="fontDestTbl">Tabla de fuentes resultante.</param>
            /// <param name="sFontName">Fuente buscada.</param>
            /// <returns></returns>
            private int getFontID(ref RtfFontTable fontDestTbl, string sFontName)
            {
                int iExistingFontID;

                if ((iExistingFontID = fontDestTbl.IndexOf(sFontName)) == -1)
                {
                    fontDestTbl.AddFont(sFontName);
                    iExistingFontID = fontDestTbl.IndexOf(sFontName);

                    RtfTreeNode fontTableGroupNode = baseRtfDoc.MainGroup.SelectSingleGroup("fonttbl");

                    RtfTreeNode ftFont = new RtfTreeNode(RtfNodeType.Group);
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, iExistingFontID));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fnil", false, 0));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Text, sFontName + ";", false, 0));

                    fontTableGroupNode.AppendChild(ftFont);
                }

                return(iExistingFontID);
            }
Esempio n. 5
0
            /// <summary>
            /// Obtiene el código de la fuente pasada como parámetro, insertándola en la tabla de fuentes si es necesario.
            /// </summary>
            /// <param name="fontDestTbl">Tabla de fuentes resultante.</param>
            /// <param name="sFontName">Fuente buscada.</param>
            /// <returns></returns>
            private int getFontID(ref RtfFontTable fontDestTbl, string sFontName)
            {
                int iExistingFontID = -1;

                if ((iExistingFontID = fontDestTbl.IndexOf(sFontName)) == -1)
                {
                    fontDestTbl.AddFont(sFontName);
                    iExistingFontID = fontDestTbl.IndexOf(sFontName);

                    RtfNodeCollection nodeListToInsert = baseRtfDoc.RootNode.SelectNodes("fonttbl");

                    RtfTreeNode ftFont = new RtfTreeNode(RtfNodeType.Group);
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, iExistingFontID));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fnil", false, 0));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Text, sFontName + ";", false, 0));

                    nodeListToInsert[0].ParentNode.AppendChild(ftFont);
                }

                return(iExistingFontID);
            }
Esempio n. 6
0
            /// <summary>
            /// Obtiene el código de la fuente pasada como parámetro, insertándola en la tabla de fuentes si es necesario.
            /// </summary>
            /// <param name="fontDestTbl">Tabla de fuentes resultante.</param>
            /// <param name="sFontName">Fuente buscada.</param>
            /// <returns></returns>
            private int getFontID(ref RtfFontTable fontDestTbl, string sFontName)
            {
                int iExistingFontID = -1;

                if ((iExistingFontID = fontDestTbl.IndexOf(sFontName)) == -1)
                {
                    fontDestTbl.AddFont(sFontName);
                    iExistingFontID = fontDestTbl.IndexOf(sFontName);

                    RtfNodeCollection nodeListToInsert = baseRtfDoc.RootNode.SelectNodes("fonttbl");

                    RtfTreeNode ftFont = new RtfTreeNode(RtfNodeType.Group);
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "f", true, iExistingFontID));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Keyword, "fnil", false, 0));
                    ftFont.AppendChild(new RtfTreeNode(RtfNodeType.Text, sFontName + ";", false, 0));

                    nodeListToInsert[0].ParentNode.AppendChild(ftFont);
                }

                return iExistingFontID;
            }