Example #1
0
 /// <summary>
 /// Write
 /// </summary>
 /// <param name="writer"></param>
 public void Write(Writer writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(Consts.Colortbl);
     writer.WriteRaw(";");
     foreach (var item in _arrayList)
     {
         var c = (Color)item;
         writer.WriteKeyword("red" + c.R);
         writer.WriteKeyword("green" + c.G);
         writer.WriteKeyword("blue" + c.B);
         writer.WriteRaw(";");
     }
     writer.WriteEndGroup();
 }
Example #2
0
 /// <summary>
 /// Write raw text
 /// </summary>
 /// <param name="text"></param>
 public void WriteRaw(string text)
 {
     if (CollectionInfo == false)
     {
         if (text != null)
         {
             Writer.WriteRaw(text);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Write end of paragraph
        /// </summary>
        /// <param name="info">format</param>
        // ReSharper disable once MemberCanBePrivate.Global
        public void WriteStartParagraph(DocumentFormatInfo info)
        {
            if (CollectionInfo)
            {
                //myFontTable.Add("Wingdings");
            }
            else
            {
                if (_firstParagraph)
                {
                    _firstParagraph = false;
                    Writer.WriteRaw(Environment.NewLine);
                    //myWriter.WriteKeyword("par");
                }
                else
                {
                    Writer.WriteKeyword("par");
                }
                if (info.ListId >= 0)
                {
                    Writer.WriteKeyword("pard");
                    Writer.WriteKeyword("ls" + info.ListId);

                    if (_lastParagraphInfo != null)
                    {
                        if (_lastParagraphInfo.ListId >= 0)
                        {
                            Writer.WriteKeyword("pard");
                        }
                    }
                }

                switch (info.Align)
                {
                case RtfAlignment.Left:
                    Writer.WriteKeyword("ql");
                    break;

                case RtfAlignment.Center:
                    Writer.WriteKeyword("qc");
                    break;

                case RtfAlignment.Right:
                    Writer.WriteKeyword("qr");
                    break;

                case RtfAlignment.Justify:
                    Writer.WriteKeyword("qj");
                    break;
                }

                if (info.ParagraphFirstLineIndent != 0)
                {
                    Writer.WriteKeyword("fi" + Convert.ToInt32(
                                            info.ParagraphFirstLineIndent * 400 / info.StandTabWidth));
                }
                else
                {
                    Writer.WriteKeyword("fi0");
                }

                if (info.LeftIndent != 0)
                {
                    Writer.WriteKeyword("li" + Convert.ToInt32(
                                            info.LeftIndent * 400 / info.StandTabWidth));
                }
                else
                {
                    Writer.WriteKeyword("li0");
                }
                Writer.WriteKeyword("plain");
            }
            _lastParagraphInfo = info;
        }
Example #4
0
        /// <summary>
        /// Write the start of the document
        /// </summary>
        public void WriteStartDocument()
        {
            _lastParagraphInfo = null;
            _firstParagraph    = true;
            if (CollectionInfo)
            {
                Info.Clear();
                FontTable.Clear();
                ColorTable.Clear();
                FontTable.Add(SystemFonts.DefaultFont.Name);
            }
            else
            {
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Rtf);
                Writer.WriteKeyword("ansi");
                Writer.WriteKeyword("ansicpg" + Writer.Encoding.CodePage);

                // Write document information
                if (Info.Count > 0)
                {
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("info");
                    foreach (string key in Info.Keys)
                    {
                        Writer.WriteStartGroup();

                        var value = Info[key];
                        if (value is string)
                        {
                            Writer.WriteKeyword(key);
                            Writer.WriteText((string)value);
                        }
                        else if (value is int)
                        {
                            Writer.WriteKeyword(key + value);
                        }
                        else if (value is DateTime)
                        {
                            var dateTime = (DateTime)value;
                            Writer.WriteKeyword(key);
                            Writer.WriteKeyword("yr" + dateTime.Year);
                            Writer.WriteKeyword("mo" + dateTime.Month);
                            Writer.WriteKeyword("dy" + dateTime.Day);
                            Writer.WriteKeyword("hr" + dateTime.Hour);
                            Writer.WriteKeyword("min" + dateTime.Minute);
                            Writer.WriteKeyword("sec" + dateTime.Second);
                        }
                        else
                        {
                            Writer.WriteKeyword(key);
                        }

                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                // Write font table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Fonttbl);
                for (var count = 0; count < FontTable.Count; count++)
                {
                    //string f = myFontTable[ count ] ;
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("f" + count);
                    var f = FontTable[count];
                    Writer.WriteText(f.Name);
                    if (f.Charset != 1)
                    {
                        Writer.WriteKeyword("fcharset" + f.Charset);
                    }
                    Writer.WriteEndGroup();
                }
                Writer.WriteEndGroup();

                // Write color table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(Consts.Colortbl);
                Writer.WriteRaw(";");

                for (var count = 0; count < ColorTable.Count; count++)
                {
                    var colorTable = ColorTable[count];
                    Writer.WriteKeyword("red" + colorTable.R);
                    Writer.WriteKeyword("green" + colorTable.G);
                    Writer.WriteKeyword("blue" + colorTable.B);
                    Writer.WriteRaw(";");
                }
                Writer.WriteEndGroup();

                // Write list table
                if (ListTable != null && ListTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }

                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listtable", true);

                    foreach (var list in ListTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("list");
                        Writer.WriteKeyword("listtemplateid" + list.ListTemplateId);

                        if (list.ListHybrid)
                        {
                            Writer.WriteKeyword("listhybrid");
                        }

                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }

                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listlevel");
                        Writer.WriteKeyword("levelfollow" + list.LevelFollow);
                        Writer.WriteKeyword("leveljc" + list.LevelJc);
                        Writer.WriteKeyword("levelstartat" + list.LevelStartAt);
                        Writer.WriteKeyword("levelnfc" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("levelnfcn" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("leveljc" + list.LevelJc);

                        if (string.IsNullOrEmpty(list.LevelText) == false)
                        {
                            Writer.WriteStartGroup();
                            Writer.WriteKeyword("leveltext");
                            Writer.WriteKeyword("'0" + list.LevelText.Length);
                            if (list.LevelNfc == RtfLevelNumberType.Bullet)
                            {
                                Writer.WriteUnicodeText(list.LevelText);
                            }
                            else
                            {
                                Writer.WriteText(list.LevelText, false);
                            }

                            Writer.WriteEndGroup();
                            if (list.LevelNfc == RtfLevelNumberType.Bullet)
                            {
                                var f = FontTable["Wingdings"];
                                if (f != null)
                                {
                                    Writer.WriteKeyword("f" + f.Index);
                                }
                            }
                            else
                            {
                                Writer.WriteStartGroup();
                                Writer.WriteKeyword("levelnumbers");
                                Writer.WriteKeyword("'01");
                                Writer.WriteEndGroup();
                            }
                        }
                        Writer.WriteEndGroup();

                        Writer.WriteKeyword("listid" + list.ListId);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                // Write list overried table
                if (ListOverrideTable != null && ListOverrideTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }

                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listoverridetable");
                    foreach (var listOverride in ListOverrideTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listoverride");
                        Writer.WriteKeyword("listid" + listOverride.ListId);
                        Writer.WriteKeyword("listoverridecount" + listOverride.ListOverrideCount);
                        Writer.WriteKeyword("ls" + listOverride.Id);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                if (DebugMode)
                {
                    Writer.WriteRaw(Environment.NewLine);
                }

                Writer.WriteKeyword("viewkind1");
            }
        }
Example #5
0
 /// <summary>
 /// Write
 /// </summary>
 /// <param name="writer"></param>
 public void Write(Writer writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(Consts.Colortbl);
     writer.WriteRaw(";");
     foreach (var item in _arrayList)
     {
         var c = (Color) item;
         writer.WriteKeyword("red" + c.R);
         writer.WriteKeyword("green" + c.G);
         writer.WriteKeyword("blue" + c.B);
         writer.WriteRaw(";");
     }
     writer.WriteEndGroup();
 }